ABSTRACT

This class connects to the nethz LDAP of ETHZ and checks if a given username and password combination is valid.

Method error_msg will return a error message if validation failed; otherwise undef and several methods will return attributes of that user: all_attributes and attribute will return attributes as got from the home organisation (utf8 encoded), all other attribut retrieval methods return values converted to iso-8859-1 code.


SYNOPSIS

 use NethzLDAP;
 $username = '...'; $password = '...';
 my $nethz_info = NethzLDAP->check_validation(-username=>$username,
                                              -password=>$password);
 if ($nethz_info->error_msg) {
     die $nethz_info->error_msg . "/n";
 }
 my $name = $nethz_info->givenName . ' ' . $nethz_info->sn; # iso-8859-1
 my $iso_addr = $nethz_info->postalAddress;              # iso-8859-1
 my $utf_addr = $nethz_info->attribute('postalAddress'); # utf8
 my $all_attributes = $nethz_info->all_attributes;
 foreach my $attr_name ( sort keys %$all_attributes ) {
     print "Attribute: $attr_name\n";
     foreach my $value ( @{$all_attributes{$attr_name}} ) {
         print "    $value\n"; # utf8
     }
 }


METHODS

$info = NethzLDAP->check_validation(-username=>$un, -password=>$pw)
$info = NethzLDAP->check_validation(-username=>$un, -no_password=>1)
$info = NethzLDAP->check_validation(-username=>$un, -password=>$pw, -super_pw=>$pw2)
Object Constructor: returns an object of class NethzLDAP. Connects to the LDAP and gets the info for the specified username. If Argument -password=> ... is specified, the password is checked. If Argument -no_password=>1 is specified, only the LDAP info is accessed. If none of the two is specified, the method dies. The argument -super_pw=>$pw2 can be used to specify a super password: if the -password=>$pw does not validate with the LDAP, $pw will be compared with $pw2. This is for debug only and should never be used in a production environment.

$string = $info->error_msg
If NethzLDAP->check_validation($username, $password) got a valid $username / $password combination, method error_msg returns undef, otherwise a iso-8859-1 string with an error message.

$string = $info->error_field
Returns 'username' or 'password' if error_msg reports an error. A login script may set the focus on the appropiate input field. If error_msg returns undef, error_field will return undef as well.

$href = $info->all_attributes
Returns a reference to a hash with all attributes of a checked user, or undef, if NethzLDAP->check_validation($username, $password) was not able to validate the specified user. The return value is a reference to a hash, keys are the attritute names as got from the LDAP and values are references to arrays of values as got from the LDAP (i.e. utf8 encoded).

$value = $info->attribute( $name )
@values = $info->attribute( $name )
Returns a specified attribute (or undef if <check_validation> did not validate a user or there was no attribute with $name). In scalar context, the first value is returned, in list context, an array with all values is returned. Values are as got from LDAP (utf8 encoded).

$string = $info->givenName
Returns the givenName (firstname) of a validated user, converted to iso-8859-1 code. undef if not supplied by LDAP. Only the first value will be returned, when the LDAP supplies more tan one value.

$string = $info->mail
Returns the mail (email address) of a validated user, converted to iso-8859-1 code. undef if not supplied by LDAP. Only the first value will be returned, when the LDAP supplies more tan one value.

$string = $info->nPID
Returns the nPID (nethz DB identification) of a validated user, this is a number. undef if not supplied by LDAP. Only the first value will be returned, when the LDAP supplies more tan one value.

$href = $info->ou
Returns a reference to a hash (or undef if not a validated user). Keys are ou attribute values (names of 'Ngroups' to which the user belongs) converted to iso-8859-1 code, values are true (1). undef if the ou attribute was not supplied by LDAP.

$string = $info->postalAddress
Returns the postalAddress of a validated user, converted to iso-8859-1 code. undef if not supplied by LDAP. Only the first value will be returned, when the LDAP supplies more tan one value.

$string = $info->sn
Returns the sn (surname, lastname, familyname) of a validated user, converted to iso-8859-1 code. undef if not supplied by LDAP. Only the first value will be returned, when the LDAP supplies more tan one value.


COPYRIGHT

Copyright 2004-2013 Thedi gerber@id.ethz.ch