Jump to content
Wiki Home
EPrints Home
Bazaar
Files
Main menu
Main menu
move to sidebar
hide
Navigation
Front Page
EPrints 3 Manual
EPrints Training Course
EPrints Glossary
Installing EPrints
How-to Configure EPrints
EPrints 3.2+ API
EPrints 3 Reference
EPrints Plugins
Wiki
All categories
Recent changes
Main Page
Help
EPrints Documentation
Search
Search
Appearance
Log in
Request account
Personal tools
Log in
Request account
Pages for logged out editors
learn more
Contributions
Talk
Editing
LDAP
(section)
Page
Discussion
British English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====LDAP Import==== Below is an example of a script to import/update users from LDAP based on them being founder under the ldap_import_filter set in ldap.pl above. Typically you would edit this files as follows: vi /opt/eprints3/archives/myarchivename/bin/update_users Before you can run this you will need to change permissions sot it can be run: chmod u+x /opt/eprints3/archives/myarchivename/bin/update_users Then to run the script use the following: /opt/eprints3/archives/myarchivename/bin/update_users myarchivename #!/usr/bin/perl -w # EPrints LDAP example user import/update script use FindBin; use lib "$FindBin::Bin/../../../perl_lib"; use EPrints; use Getopt::Long; use Net::LDAP; use Net::LDAP::Control::Paged; use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); use strict; my $verbose = 0; GetOptions( 'verbose+' => \$verbose, ); my $session = EPrints::Session->new( 1 , $ARGV[0] ); exit( 1 ) unless defined $session; # Params my $ldap_host = $session->get_repository->get_conf( "ldap_hostname" ); my $bind_dn = $session->get_repository->get_conf( "ldap_bind_username" ); my $bind_pword = $session->get_repository->get_conf( "ldap_bind_password" ); my $base = $session->get_repository->get_conf( "ldap_import_base" ); my $filter = $session->get_repository->get_conf( "ldap_import_filter" ); # Connect to server my $ldap = Net::LDAP->new( $ldap_host, version => 3 ); die "LDAP connect error: $@\n" unless defined $ldap; # Try to bind my $mesg; if( $bind_dn eq "" && $bind_pword eq "" ) { $mesg = $ldap->bind; # anonymous bind } else { $mesg = $ldap->bind( $bind_dn, password => $bind_pword ); } die "LDAP bind error: " . $mesg->error() . "\n" if $mesg->code(); my $updated_counter = 0; my $created_counter = 0; # Create paging control my $page = Net::LDAP::Control::Paged->new( size => 100 ); # Build args for the search my @args = ( base => $base, scope => "sub", filter => $filter, callback => \&process_entry, control => [ $page ], ); print "\n$created_counter user(s) created.\n $updated_counter user(s) updated.\n" if $verbose; my $cookie; while( 1 ) { # Perform search my $result = $ldap->search( @args ); # Only continue on LDAP_SUCCESS $result->code and last; # Get cookie from paged control my( $resp ) = $result->control( LDAP_CONTROL_PAGED ) or last; $cookie = $resp->cookie or last; # Set cookie in paged control $page->cookie( $cookie ); } if( $cookie ) { # We had an abnormal exit, so let the server know we do not want any more $page->cookie( $cookie ); $page->size( 0 ); $ldap->search( @args ); } $ldap->unbind; $session->terminate; # Process entry sub process_entry { my( $mesg, $entr ) = @_; return unless defined $entr and $entr->can("get_value"); my $username = $entr->get_value( "sAMAccountName" ); # This may need to be changed to uid or cn rather than sAMAccountName my $given = $entr->get_value( "givenName" ); my $family = $entr->get_value( "sn" ); my $email = $entr->get_value( "mail" ); my $dept = $entr->get_value( "department" ); # Assumes that the user account will have a given name, family name, username and email address return unless defined $username && defined $given && defined $family && defined $email; # Can we find this user already in EPrints by username my $user = EPrints::DataObj::User::user_with_username( $session, $username ); # If not maybe we can find them by email address. if( !defined $user ) { my $user = EPrints::DataObj::User::user_with_email( $session, $email ); } if( !defined $user ) { print "Creating for username: $username\n" if $verbose; $user = EPrints::DataObj::User::create( $session, "user" ); $created_counter = $created_counter +1; } else { print "Updating for username: $username with ID: ".$user->id."\n" if $verbose; $updated_counter = $updated_counter+1; } my $name = { family => $family, given => $given, }; my $usertype = "user"; $user->set_value( "usertype", $usertype ); $user->set_value( "username", $username ); $user->set_value( "name", $name ); $user->set_value( "email", $email ); $user->set_value( "dept", $dept ); $user->commit(); }
Summary:
Please note that all contributions to EPrints Documentation may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
EPrints Documentation:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)