Hi there. thank you for responding. Here is the script itself.

$c->{check_user_password} = sub { my( $session, $username, $password ) = @_; # LDAP authentication for "user", "editor" and "admin" types (roles +) use Net::LDAP; # IO::Socket::SSL also required # LDAP tunables my $ldap_host = "Tute.Usp.Ac.Fj/"; my $base = "Dc=Usp,Dc=Ac,Dc=Fj"; my $dn = "Cn=XXX,Cn=Users,$base"; my $ldap = Net::LDAP->new ( $ldap_host, version => 3 ); unless( $ldap ) { print STDERR "LDAP error: $@\n"; return 0; } # Start secure connection (not needed if using LDAPS) my $ssl = $ldap->start_tls(); if( $ssl->code() ) { print STDERR "LDAP SSL error: " . $ssl->error() . "\n"; return 0; } # Get password for the search-bind-account my $repository = $session->get_repository; my $id = $repository->get_id; my $ldappass = `cat /opt/eprints3/archives/$id/cfg/ldap.passwd`; chomp($ldappass); my $mesg = $ldap->bind( $dn, password=>$ldappass ); if( $mesg->code() ) { print STDERR "LDAP Bind error: " . $mesg->error() . "\n"; return 0; } # Distinguished name (and attribues needed later on) for this user my $result = $ldap->search ( base => "$base", scope => "sub", #filter => "(&(uid=$username)(objectclass=inetOrgPerson))", filter => "SAMAccountName=$username", #attrs => ['1.1', 'uid', 'sn', 'givenname', 'mail'], sizelimit=>1 ); my $entr = $result->pop_entry; unless( defined $entr ) { # Allow local EPrints authentication for admins (accounts not f +ound in LDAP) my $user = EPrints::DataObj::User::user_with_username( $session +, $username ); return 0 unless $user; my $user_type = $user->get_type; if( $user_type eq "admin" ) { # internal authentication for "admin" type return $session->get_database->valid_login( $username, $pas +sword ); } return 0; } my $ldap_dn = $entr->dn; # Check password my $mesg = $ldap->bind( $ldap_dn, password => $password ); if( $mesg->code() ) { return 0; } # Does account already exist? my $user = EPrints::DataObj::User::user_with_username( $session, $u +sername ); if( !defined $user ) { # New account $user = EPrints::DataObj::User::create( $session, "user" ); $user->set_value( "username", $username ); } # Set metadata my $name = {}; $name->{family} = $entr->get_value( "sn" ); $name->{given} = $entr->get_value( "givenName" ); $user->set_value( "name", $name ); $user->set_value( "username", $username ); $user->set_value( "email", $entr->get_value( "mail" ) ); $user->commit(); $ldap->unbind if $ldap; return 1; }

In reply to Re^2: LDAP Authentication by buksh_s
in thread LDAP Authentication by buksh_s

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.