<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.eprints.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Florent.lartet%40univ-tlse2.fr</id>
	<title>EPrints Documentation - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.eprints.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Florent.lartet%40univ-tlse2.fr"/>
	<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/Special:Contributions/Florent.lartet@univ-tlse2.fr"/>
	<updated>2026-09-11T09:23:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.8</generator>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Talk:CAS&amp;diff=11475</id>
		<title>Talk:CAS</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Talk:CAS&amp;diff=11475"/>
		<updated>2015-10-30T14:08:07Z</updated>

		<summary type="html">&lt;p&gt;Florent.lartet@univ-tlse2.fr: Created page with 'I don't get the relation between LDAP configuration and the archives/**/user_login.pl file. Without any feedback on it, I will transform the end of this page simply explaining wh…'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I don't get the relation between LDAP configuration and the archives/**/user_login.pl file. Without any feedback on it, I will transform the end of this page simply explaining what you can find inside this file.&lt;br /&gt;
Anyone ?&lt;/div&gt;</summary>
		<author><name>Florent.lartet@univ-tlse2.fr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=CAS&amp;diff=11474</id>
		<title>CAS</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=CAS&amp;diff=11474"/>
		<updated>2015-10-30T14:01:43Z</updated>

		<summary type="html">&lt;p&gt;Florent.lartet@univ-tlse2.fr: /* Eprints::Session edit */ wrong function, wrong query, wrong package&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page explains how to use a CAS server to authenticate user in eprints.&lt;br /&gt;
&lt;br /&gt;
==Install a secure host==&lt;br /&gt;
&lt;br /&gt;
The first thing you'll have to do is to [[Https3|install a secure host]].&lt;br /&gt;
&lt;br /&gt;
==Apache2::AuthCAS==&lt;br /&gt;
This perl library allows you to easily communicate with a CAS sever.&lt;br /&gt;
&lt;br /&gt;
===Install the lib===&lt;br /&gt;
&lt;br /&gt;
This can be done with the command:&lt;br /&gt;
perl -MCPAN -e 'install Apache2::AuthCAS'&lt;br /&gt;
&lt;br /&gt;
More infomartion are available on http://search.cpan.org/~jhitt/Apache2-AuthCAS-0.4/lib/Apache2/AuthCAS.pm&lt;br /&gt;
&lt;br /&gt;
===Create the database to store cookies===&lt;br /&gt;
&lt;br /&gt;
You should find this schema on&lt;br /&gt;
http://search.cpan.org/src/JHITT/Apache2-AuthCAS-0.4/schemaPg.sql&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Schema for use with PostgreSQL&lt;br /&gt;
CREATE TABLE cas_sessions (&lt;br /&gt;
      id                varchar(32) not null primary key&lt;br /&gt;
    , last_accessed     int8        not null&lt;br /&gt;
    , user_id           varchar(32) not null&lt;br /&gt;
    , pgtiou            varchar(256)&lt;br /&gt;
    , pgt               varchar(256)&lt;br /&gt;
    , service_ticket    varchar(256)&lt;br /&gt;
);&lt;br /&gt;
CREATE INDEX cas_sessions_id_index ON cas_sessions(id);&lt;br /&gt;
CREATE INDEX cas_sessions_pgtiou_index ON cas_sessions(pgtiou);&lt;br /&gt;
&lt;br /&gt;
-- Schema for use with MySQL&lt;br /&gt;
CREATE TABLE cas_sessions (&lt;br /&gt;
      id                varchar(32) not null primary key&lt;br /&gt;
    , last_accessed     int(8)        not null&lt;br /&gt;
    , user_id           varchar(32) not null&lt;br /&gt;
    , pgtiou            varchar(256)&lt;br /&gt;
    , pgt               varchar(256)&lt;br /&gt;
    , service_ticket    varchar(256)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
-- MySQL will create automatically the index for the primary key&lt;br /&gt;
CREATE INDEX cas_sessions_pgtiou_index ON cas_sessions(pgtiou);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Configure your secure host===&lt;br /&gt;
You must provide some information like the CAS host. You can provide it in your virtual host, or in AuthCAS.pm.&lt;br /&gt;
Read the [http://search.cpan.org/~jhitt/Apache2-AuthCAS-0.4/lib/Apache2/AuthCAS.pm module page on CPAN] to know more about it.&lt;br /&gt;
&lt;br /&gt;
Edit $EPRINTS_ROOT/archives/$ARCHIVE_ID/var/manual-secure.conf and add the lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  PerlLoadModule Apache2::AuthCAS::Configuration&lt;br /&gt;
  PerlLoadModule Apache2::AuthCAS&lt;br /&gt;
  &amp;lt;Directory &amp;quot;/opt/eprints3/cgi/users&amp;quot;&amp;gt;&lt;br /&gt;
    AuthName &amp;quot;User Area&amp;quot;&lt;br /&gt;
    AuthType Apache2::AuthCAS&lt;br /&gt;
    AuthName &amp;quot;CAS&amp;quot;&lt;br /&gt;
    PerlAuthenHandler Apache2::AuthCAS-&amp;gt;authenticate&lt;br /&gt;
&lt;br /&gt;
    CASHost &amp;quot;HOST&amp;quot;&lt;br /&gt;
    CASPort &amp;quot;443&amp;quot;&lt;br /&gt;
    CASErrorURL &amp;quot;https://HOST/cas/error/&amp;quot;&lt;br /&gt;
    CASDbDataSource &amp;quot;dbname=DATABASE_NAME&amp;quot;&lt;br /&gt;
    CASDbDriver &amp;quot;mysql&amp;quot;&lt;br /&gt;
    CASDbUser &amp;quot;DATABASE_USERNAME&amp;quot;&lt;br /&gt;
    CASDbPass &amp;quot;DATABASE_PASSWORD&amp;quot;&lt;br /&gt;
    CASSessionCookieName &amp;quot;COOKIE_NAME&amp;quot;&lt;br /&gt;
    CASSessionTimeout &amp;quot;1800&amp;quot;&lt;br /&gt;
    CASLogLevel &amp;quot;0&amp;quot;&lt;br /&gt;
    CASRemoveTicket &amp;quot;true&amp;quot;&lt;br /&gt;
    CASPretendBasicAuth &amp;quot;true&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#   CASLoginUri &amp;quot;/cas/login&amp;quot;&lt;br /&gt;
#   CASLogoutUri &amp;quot;/cas/logout&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    PerlAuthzHandler EPrints::Apache::Auth::authz&lt;br /&gt;
    Require valid-user&lt;br /&gt;
&lt;br /&gt;
    SetHandler perl-script&lt;br /&gt;
    PerlHandler ModPerl::Registry&lt;br /&gt;
    PerlSendHeader Off&lt;br /&gt;
    Options ExecCGI FollowSymLinks&lt;br /&gt;
  &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Eprints::Repository edit==&lt;br /&gt;
Now edit the $EPRINTS_PATH/perl_lib/EPrints/Repository.pm.&lt;br /&gt;
(( previously, a modification to the CGI module declaration was suggested, it works without this modification on my instance ))&lt;br /&gt;
&lt;br /&gt;
Here is the complete current_user function with English/French comments&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub current_user&lt;br /&gt;
{&lt;br /&gt;
	my( $self ) = @_;&lt;br /&gt;
&lt;br /&gt;
	if( $self-&amp;gt;{offline} )&lt;br /&gt;
	{&lt;br /&gt;
		return undef;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if( $self-&amp;gt;{logged_out} )&lt;br /&gt;
	{	&lt;br /&gt;
		return undef;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	# info : $self-&amp;gt;log loggue dans error.log d'Apache, même pas celui lié à l'instance ...&lt;br /&gt;
	# info : $self-&amp;gt;log logs in Apache's error.log not the one defined for eprints vhost ...&lt;br /&gt;
&lt;br /&gt;
	if( !defined $self-&amp;gt;{current_user} ) {&lt;br /&gt;
		# 1ère vérification, par cookie car il s'agit du fonctionnement standard et que même CAS fixe ce cookie. Il est important de ne pas passer dans le processus CAS/LDAP à chaque appel à la méthode&lt;br /&gt;
		# 1st check, cookie check because it's eprints standard, even CAS sets this cookie. It's important not to go through the CAS/LDAP process at each method call&lt;br /&gt;
		if ($self-&amp;gt;get_archive-&amp;gt;get_conf(&amp;quot;cookie_auth&amp;quot;)) {&lt;br /&gt;
			$self-&amp;gt;{current_user} = $self-&amp;gt;_current_user_auth_cookie;&lt;br /&gt;
			&lt;br /&gt;
			# pas de cookie avec l'utilisateur, il faut passer via le process CAS s'il est activé&lt;br /&gt;
			# no user cookie, must go through the CAS process if defined&lt;br /&gt;
			if (! defined($self-&amp;gt;{current_user})) {&lt;br /&gt;
				my $username = undef;&lt;br /&gt;
				if ($self-&amp;gt;get_archive-&amp;gt;get_conf('cas_auth')) {&lt;br /&gt;
					my $cookie_name = $self-&amp;gt;get_archive-&amp;gt;get_conf('cas_cookie_name');&lt;br /&gt;
					&lt;br /&gt;
					# la query (objet CGI) n'est pas initialisé lors des 1ers passages dans cette méthode&lt;br /&gt;
					# the query (CGI object) is not set at the first calls of this method&lt;br /&gt;
					if (defined($self-&amp;gt;{query})) {&lt;br /&gt;
						my $ticket = $self-&amp;gt;{query}-&amp;gt;cookie($cookie_name);&lt;br /&gt;
						# récupération du nom d'utilisateur via la base de données mise à jour par le module CAS chargé par Apache&lt;br /&gt;
						# get the username from database updated by the CAS module from Apache mod_perl&lt;br /&gt;
						if ($ticket ne '') {&lt;br /&gt;
							my $sql=&amp;quot;SELECT user_id FROM cas_sessions WHERE id='$ticket'&amp;quot;;&lt;br /&gt;
							my $sth = $self-&amp;gt;get_database()-&amp;gt;prepare($sql);&lt;br /&gt;
							$self-&amp;gt;get_database()-&amp;gt;execute($sth,$ticket);&lt;br /&gt;
							my @info = $sth-&amp;gt;fetchrow_array();&lt;br /&gt;
							# my @list = split(&amp;quot;:&amp;quot;,$info[0]);&lt;br /&gt;
							$username = $info[0];&lt;br /&gt;
							$sth-&amp;gt;finish;&lt;br /&gt;
						}&lt;br /&gt;
					}&lt;br /&gt;
					$self-&amp;gt;{current_user} = EPrints::DataObj::User::user_with_username($self, $username);&lt;br /&gt;
				}&lt;br /&gt;
&lt;br /&gt;
				# la méthode au-dessus ne créé pas l'utilisateur si celui n'est pas déjà présent dans l'application, à faire via le LDAP&lt;br /&gt;
				# the previous method doesn't create user if he doesn't exist in the database, we'll do this with an LDAP&lt;br /&gt;
				if (defined($username) &amp;amp;&amp;amp; ! defined($self-&amp;gt;{current_user})) {&lt;br /&gt;
					# récupération de tous les paramètres de connexion et recherche dans l'annuaire LDAP&lt;br /&gt;
					# get every parameter to set the connection and search the user in the LDAP directory&lt;br /&gt;
					my $ldap_host = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_host');&lt;br /&gt;
					my $ldap_version = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_version');&lt;br /&gt;
					my $ldap_bind_user = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_bind_user');&lt;br /&gt;
					my $ldap_bind_pass = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_bind_pass');&lt;br /&gt;
					my $ldap_base = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_base');&lt;br /&gt;
					my $ldap_scope = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_scope');&lt;br /&gt;
					my $ldap_search_string = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_search_string');&lt;br /&gt;
					$ldap_search_string =~ s/!!USERNAME!!/$username/g;&lt;br /&gt;
					&lt;br /&gt;
					# récupération des valeurs par défaut que le LDAP ne renverra pas (sauf email)&lt;br /&gt;
					# get all default values, except email because we don't need it in our instance&lt;br /&gt;
					my $ldap_default_email = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_email');&lt;br /&gt;
					my $ldap_default_country = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_country');                                         &lt;br /&gt;
					my $ldap_default_org = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_org');&lt;br /&gt;
					my $ldap_conforms_supann = $self-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_conforms_supann');&lt;br /&gt;
					&lt;br /&gt;
					# connexion à l'annuaire LDAP&lt;br /&gt;
					# LDAP directory connection&lt;br /&gt;
					my $ldap = Net::LDAP-&amp;gt;new( $ldap_host ) or die &amp;quot;$@&amp;quot;;&lt;br /&gt;
					my $mesg = $ldap-&amp;gt;bind ( $ldap_bind_user, password =&amp;gt; $ldap_bind_pass, version =&amp;gt; $ldap_version);&lt;br /&gt;
&lt;br /&gt;
					# recherche de l'utilisateur&lt;br /&gt;
					# user search&lt;br /&gt;
					my $result = $ldap-&amp;gt;search(base =&amp;gt; $ldap_base, scope   =&amp;gt; $ldap_scope, filter  =&amp;gt; $ldap_search_string);&lt;br /&gt;
&lt;br /&gt;
					# les entrées sont censées être uniques, on prend la 1ère entrée&lt;br /&gt;
					# user entry is meant to be unique, we take the first&lt;br /&gt;
					my @entries = $result-&amp;gt;entries();&lt;br /&gt;
					if (defined (my $ldap_entry = $entries[0])) {&lt;br /&gt;
						# récupération du type d'utilisateur par défaut&lt;br /&gt;
						# get the default user type&lt;br /&gt;
						my $usertype = $self-&amp;gt;config(&amp;quot;default_user_type&amp;quot;);&lt;br /&gt;
						&lt;br /&gt;
						my $ds = $self-&amp;gt;dataset(&amp;quot;user&amp;quot;);&lt;br /&gt;
						my $user = $ds-&amp;gt;create_object( $self, { username =&amp;gt; $username, usertype =&amp;gt; $usertype } );&lt;br /&gt;
						$self-&amp;gt;log(Dumper($user));&lt;br /&gt;
						# the previous version was using create_user, deprecated and non-working&lt;br /&gt;
						# my $user = EPrints::User::create_user($self, $usertype);&lt;br /&gt;
&lt;br /&gt;
						my $name = {};&lt;br /&gt;
						$name-&amp;gt;{family} = $ldap_entry-&amp;gt;get_value(&amp;quot;sn&amp;quot;);&lt;br /&gt;
						$name-&amp;gt;{given} = $ldap_entry-&amp;gt;get_value(&amp;quot;givenName&amp;quot;);&lt;br /&gt;
						$user-&amp;gt;set_value(&amp;quot;name&amp;quot;, $name);&lt;br /&gt;
&lt;br /&gt;
						# Set Email&lt;br /&gt;
						my $email = defined $ldap_entry-&amp;gt;get_value(&amp;quot;mail&amp;quot;) ? $ldap_entry-&amp;gt;get_value(&amp;quot;mail&amp;quot;) : $ldap_default_email;&lt;br /&gt;
						$user-&amp;gt;set_value(&amp;quot;email&amp;quot;, $email);&lt;br /&gt;
&lt;br /&gt;
						if ($ldap_conforms_supann) {&lt;br /&gt;
							$user-&amp;gt;set_value(&amp;quot;org&amp;quot;, $ldap_entry-&amp;gt;get_value(&amp;quot;supannEtablissement&amp;quot;));&lt;br /&gt;
						}&lt;br /&gt;
						else {&lt;br /&gt;
							$user-&amp;gt;set_value(&amp;quot;org&amp;quot;, $ldap_default_org);&lt;br /&gt;
						}&lt;br /&gt;
&lt;br /&gt;
						# Set Address&lt;br /&gt;
						# my $address = $ldap_entry-&amp;gt;get_value(&amp;quot;postalAddress&amp;quot;)&lt;br /&gt;
						# . &amp;quot;\n&amp;quot;&lt;br /&gt;
						# . $ldap_entry-&amp;gt;get_value(&amp;quot;postalCode&amp;quot;)&lt;br /&gt;
						# . &amp;quot; &amp;quot;&lt;br /&gt;
						# . $ldap_entry-&amp;gt;get_value(&amp;quot;l&amp;quot;);&lt;br /&gt;
						# $user-&amp;gt;set_value(&amp;quot;address&amp;quot;, $address);&lt;br /&gt;
						$user-&amp;gt;set_value(&amp;quot;country&amp;quot;, $ldap_default_country);&lt;br /&gt;
&lt;br /&gt;
						# Set URL&lt;br /&gt;
						# $user-&amp;gt;set_value(&amp;quot;url&amp;quot;, $ldap_entry-&amp;gt;get_value(&amp;quot;labeledURI&amp;quot;));&lt;br /&gt;
						&lt;br /&gt;
						# save the information into the database and gives the user an id&lt;br /&gt;
						$user-&amp;gt;commit();&lt;br /&gt;
&lt;br /&gt;
						$self-&amp;gt;{current_user} = $user;&lt;br /&gt;
					}&lt;br /&gt;
				}&lt;br /&gt;
				# la fonction est aussi appelée avant tout procédé d'authentification, même si l'on accède à la page de login&lt;br /&gt;
				# en fait, elle est appelée très souvent, d'où le test qui suit&lt;br /&gt;
				# the method is also called before any authentication process, need to check again at this point&lt;br /&gt;
				if (defined($self-&amp;gt;{current_user})) {&lt;br /&gt;
					# création d'un ticket de login interne à l'appli et connexion de l'utilisateur (méthode trouvée dans le package Register.pm où un utilisateur est connecté après avoir été créé)&lt;br /&gt;
					# Create a login ticket and log the user in&lt;br /&gt;
					EPrints::DataObj::LoginTicket-&amp;gt;expire_all( $self );&lt;br /&gt;
					$self-&amp;gt;dataset( &amp;quot;loginticket&amp;quot; )-&amp;gt;create_dataobj({&lt;br /&gt;
						userid =&amp;gt; $self-&amp;gt;{current_user}-&amp;gt;id,&lt;br /&gt;
					})-&amp;gt;set_cookies();&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else {&lt;br /&gt;
			# custom auth&lt;br /&gt;
			if( $self-&amp;gt;get_repository-&amp;gt;can_call( 'get_current_user' ) )&lt;br /&gt;
			{&lt;br /&gt;
				$self-&amp;gt;{current_user} = $self-&amp;gt;get_repository-&amp;gt;call( 'get_current_user', $self );&lt;br /&gt;
			}&lt;br /&gt;
			# basic auth&lt;br /&gt;
			if( !defined $self-&amp;gt;{current_user} )&lt;br /&gt;
			{&lt;br /&gt;
				$self-&amp;gt;{current_user} = $self-&amp;gt;_current_user_auth_basic;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		$self-&amp;gt;{already_in_current_user} = 0;&lt;br /&gt;
	}&lt;br /&gt;
	$self-&amp;gt;{processor}-&amp;gt;{user} = $self-&amp;gt;{current_user};&lt;br /&gt;
	return $self-&amp;gt;{current_user};&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this method, I have commented some stuff around addresses because I had no need. By the way, you can use/add every useful information from your LDAP that has a place to go in the user object.&lt;br /&gt;
&lt;br /&gt;
This code assumes Apache2::AuthCAS SQL tables are stored with the rest of the Eprints server. It won't work if you use a Postgres database or even if you stored your Apache2::AuthCAS tables on an other MySQL database. If you have any good reason to use a separated database, you will have to change some lines in order to make it work.&lt;br /&gt;
&lt;br /&gt;
==Configure your archive==&lt;br /&gt;
Add the following lines into cfg/cfg.d/misc.pl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$c-&amp;gt;{cas_auth} = 1;&lt;br /&gt;
$c-&amp;gt;{cas_cookie_name} = 'COOKIE_NAME'; # The same as in manual-secure.conf&lt;br /&gt;
&lt;br /&gt;
$c-&amp;gt;{ldap_host} = 'LDAP_HOST_NAME';&lt;br /&gt;
$c-&amp;gt;{ldap_version} = 3;&lt;br /&gt;
$c-&amp;gt;{ldap_bind_user} = 'ou=admin,dc=DOMAIN,dc=com';&lt;br /&gt;
$c-&amp;gt;{ldap_bind_pass} = 'SECRET_PASS';&lt;br /&gt;
$c-&amp;gt;{ldap_base} = 'dc=DOMAIN,dc=com';&lt;br /&gt;
$c-&amp;gt;{ldap_scope} = 'sub';&lt;br /&gt;
$c-&amp;gt;{ldap_search_string} = '(uid=!!USERNAME!!)';&lt;br /&gt;
$c-&amp;gt;{ldap_default_email} = 'A VALID EMAIL';&lt;br /&gt;
$c-&amp;gt;{ldap_default_country} = 'USA';&lt;br /&gt;
$c-&amp;gt;{ldap_default_org} = 'YOUR ORGANISATION';&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test your archive==&lt;br /&gt;
&lt;br /&gt;
You should now be able to login through your CAS server.&lt;br /&gt;
&lt;br /&gt;
==LDAP Configuration==&lt;br /&gt;
&lt;br /&gt;
Once CAS is working, you may need to copy the user entry from an LDAP server.&lt;br /&gt;
EPrints3 comes with example code in archives/ARCHIVEID/cfg/cfg.d/user_login.pl. Just use it !&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;/div&gt;</summary>
		<author><name>Florent.lartet@univ-tlse2.fr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=CAS&amp;diff=11473</id>
		<title>CAS</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=CAS&amp;diff=11473"/>
		<updated>2015-10-30T13:34:37Z</updated>

		<summary type="html">&lt;p&gt;Florent.lartet@univ-tlse2.fr: /* Configure your secure host */ update version and add the Uri parameter because admins can do the mistake of putting it in host&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page explains how to use a CAS server to authenticate user in eprints.&lt;br /&gt;
&lt;br /&gt;
==Install a secure host==&lt;br /&gt;
&lt;br /&gt;
The first thing you'll have to do is to [[Https3|install a secure host]].&lt;br /&gt;
&lt;br /&gt;
==Apache2::AuthCAS==&lt;br /&gt;
This perl library allows you to easily communicate with a CAS sever.&lt;br /&gt;
&lt;br /&gt;
===Install the lib===&lt;br /&gt;
&lt;br /&gt;
This can be done with the command:&lt;br /&gt;
perl -MCPAN -e 'install Apache2::AuthCAS'&lt;br /&gt;
&lt;br /&gt;
More infomartion are available on http://search.cpan.org/~jhitt/Apache2-AuthCAS-0.4/lib/Apache2/AuthCAS.pm&lt;br /&gt;
&lt;br /&gt;
===Create the database to store cookies===&lt;br /&gt;
&lt;br /&gt;
You should find this schema on&lt;br /&gt;
http://search.cpan.org/src/JHITT/Apache2-AuthCAS-0.4/schemaPg.sql&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Schema for use with PostgreSQL&lt;br /&gt;
CREATE TABLE cas_sessions (&lt;br /&gt;
      id                varchar(32) not null primary key&lt;br /&gt;
    , last_accessed     int8        not null&lt;br /&gt;
    , user_id           varchar(32) not null&lt;br /&gt;
    , pgtiou            varchar(256)&lt;br /&gt;
    , pgt               varchar(256)&lt;br /&gt;
    , service_ticket    varchar(256)&lt;br /&gt;
);&lt;br /&gt;
CREATE INDEX cas_sessions_id_index ON cas_sessions(id);&lt;br /&gt;
CREATE INDEX cas_sessions_pgtiou_index ON cas_sessions(pgtiou);&lt;br /&gt;
&lt;br /&gt;
-- Schema for use with MySQL&lt;br /&gt;
CREATE TABLE cas_sessions (&lt;br /&gt;
      id                varchar(32) not null primary key&lt;br /&gt;
    , last_accessed     int(8)        not null&lt;br /&gt;
    , user_id           varchar(32) not null&lt;br /&gt;
    , pgtiou            varchar(256)&lt;br /&gt;
    , pgt               varchar(256)&lt;br /&gt;
    , service_ticket    varchar(256)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
-- MySQL will create automatically the index for the primary key&lt;br /&gt;
CREATE INDEX cas_sessions_pgtiou_index ON cas_sessions(pgtiou);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Configure your secure host===&lt;br /&gt;
You must provide some information like the CAS host. You can provide it in your virtual host, or in AuthCAS.pm.&lt;br /&gt;
Read the [http://search.cpan.org/~jhitt/Apache2-AuthCAS-0.4/lib/Apache2/AuthCAS.pm module page on CPAN] to know more about it.&lt;br /&gt;
&lt;br /&gt;
Edit $EPRINTS_ROOT/archives/$ARCHIVE_ID/var/manual-secure.conf and add the lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  PerlLoadModule Apache2::AuthCAS::Configuration&lt;br /&gt;
  PerlLoadModule Apache2::AuthCAS&lt;br /&gt;
  &amp;lt;Directory &amp;quot;/opt/eprints3/cgi/users&amp;quot;&amp;gt;&lt;br /&gt;
    AuthName &amp;quot;User Area&amp;quot;&lt;br /&gt;
    AuthType Apache2::AuthCAS&lt;br /&gt;
    AuthName &amp;quot;CAS&amp;quot;&lt;br /&gt;
    PerlAuthenHandler Apache2::AuthCAS-&amp;gt;authenticate&lt;br /&gt;
&lt;br /&gt;
    CASHost &amp;quot;HOST&amp;quot;&lt;br /&gt;
    CASPort &amp;quot;443&amp;quot;&lt;br /&gt;
    CASErrorURL &amp;quot;https://HOST/cas/error/&amp;quot;&lt;br /&gt;
    CASDbDataSource &amp;quot;dbname=DATABASE_NAME&amp;quot;&lt;br /&gt;
    CASDbDriver &amp;quot;mysql&amp;quot;&lt;br /&gt;
    CASDbUser &amp;quot;DATABASE_USERNAME&amp;quot;&lt;br /&gt;
    CASDbPass &amp;quot;DATABASE_PASSWORD&amp;quot;&lt;br /&gt;
    CASSessionCookieName &amp;quot;COOKIE_NAME&amp;quot;&lt;br /&gt;
    CASSessionTimeout &amp;quot;1800&amp;quot;&lt;br /&gt;
    CASLogLevel &amp;quot;0&amp;quot;&lt;br /&gt;
    CASRemoveTicket &amp;quot;true&amp;quot;&lt;br /&gt;
    CASPretendBasicAuth &amp;quot;true&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#   CASLoginUri &amp;quot;/cas/login&amp;quot;&lt;br /&gt;
#   CASLogoutUri &amp;quot;/cas/logout&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    PerlAuthzHandler EPrints::Apache::Auth::authz&lt;br /&gt;
    Require valid-user&lt;br /&gt;
&lt;br /&gt;
    SetHandler perl-script&lt;br /&gt;
    PerlHandler ModPerl::Registry&lt;br /&gt;
    PerlSendHeader Off&lt;br /&gt;
    Options ExecCGI FollowSymLinks&lt;br /&gt;
  &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Eprints::Session edit==&lt;br /&gt;
Now edit the $EPRINTS_PATH/perl_lib/EPrints/Session.pm.&lt;br /&gt;
First change the line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use CGI qw(-compile);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use CGI qw(:standard -nph -compile);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Which enables you to use the raw_cookie fuction which returns variables stored in http cookie.&lt;br /&gt;
Then go to the current_user function definition where you have to put the uid provided by AuthCAS module in $username. To do it, you just have to make a sql query which looks like that:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$sql=&amp;quot;SELECT uid FROM cas_sessions WHERE id='$user_ticket'&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where $user_ticket is the variable stored in the AuthCAS http cookie.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my $user_ticket=raw_cookie('APACHECAS');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that 'APACHECAS' is the default name for the AuthCAS cookie but you may have change it.&lt;br /&gt;
&lt;br /&gt;
Here is a code that should work if you have installed your Apache::AuthCAS sql tables in the same database where you store your eprints tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub current_user&lt;br /&gt;
{&lt;br /&gt;
  my( $self ) = @_;&lt;br /&gt;
&lt;br /&gt;
  if( $self-&amp;gt;{logged_out} )&lt;br /&gt;
  {&lt;br /&gt;
    return undef;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  if( !defined $self-&amp;gt;{current_user} )&lt;br /&gt;
  {&lt;br /&gt;
    if( $self-&amp;gt;get_archive-&amp;gt;get_conf( &amp;quot;cookie_auth&amp;quot; ) )&lt;br /&gt;
    {&lt;br /&gt;
      if ( $self-&amp;gt;get_archive-&amp;gt;get_conf( 'cas_auth' ) )&lt;br /&gt;
      {&lt;br /&gt;
        my $username;&lt;br /&gt;
        my $cookie_name = $self-&amp;gt;get_archive-&amp;gt;get_conf( 'cas_cookie_name' );&lt;br /&gt;
        if( defined $ENV{HTTP_CAS_FILTER_USER})&lt;br /&gt;
        {           $username = $ENV{HTTP_CAS_FILTER_USER};&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
          my $ticket = raw_cookie($cookie_name);&lt;br /&gt;
          if ($ticket ne '') {&lt;br /&gt;
            my $sql = &amp;quot;SELECT uid FROM cas_sessions where id='?'&amp;quot;;&lt;br /&gt;
            my $sth = $self-&amp;gt;get_database()-&amp;gt;prepare( $sql );&lt;br /&gt;
            $self-&amp;gt;get_database()-&amp;gt;execute($sth,$ticket);&lt;br /&gt;
            my @info = $sth-&amp;gt;fetchrow_array();&lt;br /&gt;
            my @list = split(&amp;quot;:&amp;quot;,$info[0]);&lt;br /&gt;
            $username = $list[0];&lt;br /&gt;
            $sth-&amp;gt;finish;&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        $self-&amp;gt;{current_user} = EPrints::DataObj::User::user_with_username( $self, $username );&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      # Create user FROM LDAP server if needed&lt;br /&gt;
      if (not defined $self-&amp;gt;{current_user})&lt;br /&gt;
      {&lt;br /&gt;
         my $session = $self;&lt;br /&gt;
&lt;br /&gt;
         my $ldap_host = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_host');&lt;br /&gt;
         my $ldap_version = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_version');&lt;br /&gt;
         my $ldap_bind_user = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_bind_user');&lt;br /&gt;
         my $ldap_bind_pass = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_bind_pass');&lt;br /&gt;
         my $ldap_base = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_base');&lt;br /&gt;
         my $ldap_scope = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_scope');&lt;br /&gt;
         my $ldap_search_string = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_search_string');&lt;br /&gt;
         $ldap_search_string =~ s/!!USERNAME!!/$username/g;&lt;br /&gt;
&lt;br /&gt;
         my $ldap_default_email = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_email');&lt;br /&gt;
         my $ldap_default_country = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_country');                                         &lt;br /&gt;
         my $ldap_default_org = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_org');&lt;br /&gt;
         my $ldap_conforms_supann = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_conforms_supann');&lt;br /&gt;
         &lt;br /&gt;
         eval &amp;quot;use Net::LDAP;&amp;quot;;&lt;br /&gt;
         die &amp;quot;Cannot load Net::LDAP: $@&amp;quot; if $@;&lt;br /&gt;
&lt;br /&gt;
         # Connect to LDAP server&lt;br /&gt;
         my $ldap = Net::LDAP-&amp;gt;new( $ldap_host ) or die &amp;quot;$@&amp;quot;;&lt;br /&gt;
         my $mesg = $ldap-&amp;gt;bind ( $ldap_bind_user,&lt;br /&gt;
               password =&amp;gt; $ldap_bind_pass,&lt;br /&gt;
               version =&amp;gt; $ldap_version,&lt;br /&gt;
         );&lt;br /&gt;
&lt;br /&gt;
         # Search the user&lt;br /&gt;
         my $result = $ldap-&amp;gt;search(&lt;br /&gt;
               base =&amp;gt; $ldap_base,&lt;br /&gt;
               scope   =&amp;gt; $ldap_scope,&lt;br /&gt;
               filter  =&amp;gt; $ldap_search_string,&lt;br /&gt;
         );&lt;br /&gt;
&lt;br /&gt;
         # Use only the first entry !&lt;br /&gt;
         my @entries = $result-&amp;gt;entries();&lt;br /&gt;
         if (defined (my $ldap_entry = $entries[0])) {&lt;br /&gt;
            # Set user type&lt;br /&gt;
            my $usertype = &amp;quot;user&amp;quot;;&lt;br /&gt;
            my $user = EPrints::User::create_user( $session, $usertype );&lt;br /&gt;
&lt;br /&gt;
            # Set user name&lt;br /&gt;
            $user-&amp;gt;set_value( &amp;quot;username&amp;quot; , $username );&lt;br /&gt;
            my $name = {};&lt;br /&gt;
            $name-&amp;gt;{family} = $ldap_entry-&amp;gt;get_value( &amp;quot;sn&amp;quot; );&lt;br /&gt;
            $name-&amp;gt;{given} = $ldap_entry-&amp;gt;get_value( &amp;quot;givenName&amp;quot; );&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;name&amp;quot;, $name );&lt;br /&gt;
&lt;br /&gt;
            # Set Email&lt;br /&gt;
            my $email = defined $ldap_entry-&amp;gt;get_value(&amp;quot;mail&amp;quot;)&lt;br /&gt;
                      ? $ldap_entry-&amp;gt;get_value(&amp;quot;mail&amp;quot;) : $ldap_default_email;&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;email&amp;quot;, $email);&lt;br /&gt;
&lt;br /&gt;
            if ( $ldap_conforms_supann )&lt;br /&gt;
            {&lt;br /&gt;
               $user-&amp;gt;set_value(&amp;quot;org&amp;quot;, $ldap_entry-&amp;gt;get_value(&amp;quot;supannEtablissement&amp;quot;));&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
               $user-&amp;gt;set_value(&amp;quot;org&amp;quot;, $ldap_default_org);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            # Set Address&lt;br /&gt;
            my $address = $ldap_entry-&amp;gt;get_value(&amp;quot;postalAddress&amp;quot;)&lt;br /&gt;
                        . &amp;quot;\n&amp;quot;&lt;br /&gt;
                        . $ldap_entry-&amp;gt;get_value(&amp;quot;postalCode&amp;quot;)&lt;br /&gt;
                        . &amp;quot; &amp;quot;&lt;br /&gt;
                        . $ldap_entry-&amp;gt;get_value(&amp;quot;l&amp;quot;);&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;address&amp;quot;, $address);&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;country&amp;quot;, $ldap_default_country);&lt;br /&gt;
&lt;br /&gt;
            # Set URL&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;url&amp;quot;, $ldap_entry-&amp;gt;get_value(&amp;quot;labeledURI&amp;quot;));&lt;br /&gt;
            $user-&amp;gt;commit();&lt;br /&gt;
&lt;br /&gt;
            $self-&amp;gt;{current_user} = $user;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
        $self-&amp;gt;{current_user} = $self-&amp;gt;_current_user_auth_cookie;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
      $self-&amp;gt;{current_user} = $self-&amp;gt;_current_user_auth_basic;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return $self-&amp;gt;{current_user};&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code assumes CASAuth SQL tables are stored with the rest of the Eprints server. It won't work if you use a Postgres database or even if you stored your CASauth tables on an other MySQL database. If you have any good reason to use a seperated database, you will have to change some lines in order to make it work.&lt;br /&gt;
&lt;br /&gt;
==Configure your archive==&lt;br /&gt;
Add the following lines into cfg/cfg.d/misc.pl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$c-&amp;gt;{cas_auth} = 1;&lt;br /&gt;
$c-&amp;gt;{cas_cookie_name} = 'COOKIE_NAME'; # The same as in manual-secure.conf&lt;br /&gt;
&lt;br /&gt;
$c-&amp;gt;{ldap_host} = 'LDAP_HOST_NAME';&lt;br /&gt;
$c-&amp;gt;{ldap_version} = 3;&lt;br /&gt;
$c-&amp;gt;{ldap_bind_user} = 'ou=admin,dc=DOMAIN,dc=com';&lt;br /&gt;
$c-&amp;gt;{ldap_bind_pass} = 'SECRET_PASS';&lt;br /&gt;
$c-&amp;gt;{ldap_base} = 'dc=DOMAIN,dc=com';&lt;br /&gt;
$c-&amp;gt;{ldap_scope} = 'sub';&lt;br /&gt;
$c-&amp;gt;{ldap_search_string} = '(uid=!!USERNAME!!)';&lt;br /&gt;
$c-&amp;gt;{ldap_default_email} = 'A VALID EMAIL';&lt;br /&gt;
$c-&amp;gt;{ldap_default_country} = 'USA';&lt;br /&gt;
$c-&amp;gt;{ldap_default_org} = 'YOUR ORGANISATION';&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test your archive==&lt;br /&gt;
&lt;br /&gt;
You should now be able to login through your CAS server.&lt;br /&gt;
&lt;br /&gt;
==LDAP Configuration==&lt;br /&gt;
&lt;br /&gt;
Once CAS is working, you may need to copy the user entry from an LDAP server.&lt;br /&gt;
EPrints3 comes with example code in archives/ARCHIVEID/cfg/cfg.d/user_login.pl. Just use it !&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;/div&gt;</summary>
		<author><name>Florent.lartet@univ-tlse2.fr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=CAS&amp;diff=11472</id>
		<title>CAS</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=CAS&amp;diff=11472"/>
		<updated>2015-10-30T13:30:07Z</updated>

		<summary type="html">&lt;p&gt;Florent.lartet@univ-tlse2.fr: /* Create the database to store cookies */ update schema and version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page explains how to use a CAS server to authenticate user in eprints.&lt;br /&gt;
&lt;br /&gt;
==Install a secure host==&lt;br /&gt;
&lt;br /&gt;
The first thing you'll have to do is to [[Https3|install a secure host]].&lt;br /&gt;
&lt;br /&gt;
==Apache2::AuthCAS==&lt;br /&gt;
This perl library allows you to easily communicate with a CAS sever.&lt;br /&gt;
&lt;br /&gt;
===Install the lib===&lt;br /&gt;
&lt;br /&gt;
This can be done with the command:&lt;br /&gt;
perl -MCPAN -e 'install Apache2::AuthCAS'&lt;br /&gt;
&lt;br /&gt;
More infomartion are available on http://search.cpan.org/~jhitt/Apache2-AuthCAS-0.4/lib/Apache2/AuthCAS.pm&lt;br /&gt;
&lt;br /&gt;
===Create the database to store cookies===&lt;br /&gt;
&lt;br /&gt;
You should find this schema on&lt;br /&gt;
http://search.cpan.org/src/JHITT/Apache2-AuthCAS-0.4/schemaPg.sql&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Schema for use with PostgreSQL&lt;br /&gt;
CREATE TABLE cas_sessions (&lt;br /&gt;
      id                varchar(32) not null primary key&lt;br /&gt;
    , last_accessed     int8        not null&lt;br /&gt;
    , user_id           varchar(32) not null&lt;br /&gt;
    , pgtiou            varchar(256)&lt;br /&gt;
    , pgt               varchar(256)&lt;br /&gt;
    , service_ticket    varchar(256)&lt;br /&gt;
);&lt;br /&gt;
CREATE INDEX cas_sessions_id_index ON cas_sessions(id);&lt;br /&gt;
CREATE INDEX cas_sessions_pgtiou_index ON cas_sessions(pgtiou);&lt;br /&gt;
&lt;br /&gt;
-- Schema for use with MySQL&lt;br /&gt;
CREATE TABLE cas_sessions (&lt;br /&gt;
      id                varchar(32) not null primary key&lt;br /&gt;
    , last_accessed     int(8)        not null&lt;br /&gt;
    , user_id           varchar(32) not null&lt;br /&gt;
    , pgtiou            varchar(256)&lt;br /&gt;
    , pgt               varchar(256)&lt;br /&gt;
    , service_ticket    varchar(256)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
-- MySQL will create automatically the index for the primary key&lt;br /&gt;
CREATE INDEX cas_sessions_pgtiou_index ON cas_sessions(pgtiou);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Configure your secure host===&lt;br /&gt;
You must provide some information like the CAS host. You can provide it in your virtual host, or in AuthCAS.pm.&lt;br /&gt;
Read the [http://search.cpan.org/~jhitt/Apache2-AuthCAS-0.1/lib/Apache2/AuthCAS.pm module page on CPAN] to know more about it.&lt;br /&gt;
&lt;br /&gt;
Edit $EPRINTS_ROOT/archives/$ARCHIVE_ID/var/manual-secure.conf and add the lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  PerlLoadModule Apache2::AuthCAS::Configuration&lt;br /&gt;
  PerlLoadModule Apache2::AuthCAS&lt;br /&gt;
  &amp;lt;Directory &amp;quot;/opt/eprints3/cgi/users&amp;quot;&amp;gt;&lt;br /&gt;
    AuthName &amp;quot;User Area&amp;quot;&lt;br /&gt;
    AuthType Apache2::AuthCAS&lt;br /&gt;
    AuthName &amp;quot;CAS&amp;quot;&lt;br /&gt;
    PerlAuthenHandler Apache2::AuthCAS-&amp;gt;authenticate&lt;br /&gt;
&lt;br /&gt;
    CASHost &amp;quot;HOST&amp;quot;&lt;br /&gt;
    CASPort &amp;quot;443&amp;quot;&lt;br /&gt;
    CASErrorURL &amp;quot;https://HOST/cas/error/&amp;quot;&lt;br /&gt;
    CASDbDataSource &amp;quot;dbname=DATABASE_NAME&amp;quot;&lt;br /&gt;
    CASDbDriver &amp;quot;mysql&amp;quot;&lt;br /&gt;
    CASDbUser &amp;quot;DATABASE_USERNAME&amp;quot;&lt;br /&gt;
    CASDbPass &amp;quot;DATABASE_PASSWORD&amp;quot;&lt;br /&gt;
    CASSessionCookieName &amp;quot;COOKIE_NAME&amp;quot;&lt;br /&gt;
    CASSessionTimeout &amp;quot;1800&amp;quot;&lt;br /&gt;
    CASLogLevel &amp;quot;0&amp;quot;&lt;br /&gt;
    CASRemoveTicket &amp;quot;true&amp;quot;&lt;br /&gt;
    CASPretendBasicAuth &amp;quot;true&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    PerlAuthzHandler EPrints::Apache::Auth::authz&lt;br /&gt;
    Require valid-user&lt;br /&gt;
&lt;br /&gt;
    SetHandler perl-script&lt;br /&gt;
    PerlHandler ModPerl::Registry&lt;br /&gt;
    PerlSendHeader Off&lt;br /&gt;
    Options ExecCGI FollowSymLinks&lt;br /&gt;
  &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Eprints::Session edit==&lt;br /&gt;
Now edit the $EPRINTS_PATH/perl_lib/EPrints/Session.pm.&lt;br /&gt;
First change the line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use CGI qw(-compile);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use CGI qw(:standard -nph -compile);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Which enables you to use the raw_cookie fuction which returns variables stored in http cookie.&lt;br /&gt;
Then go to the current_user function definition where you have to put the uid provided by AuthCAS module in $username. To do it, you just have to make a sql query which looks like that:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$sql=&amp;quot;SELECT uid FROM cas_sessions WHERE id='$user_ticket'&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where $user_ticket is the variable stored in the AuthCAS http cookie.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my $user_ticket=raw_cookie('APACHECAS');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that 'APACHECAS' is the default name for the AuthCAS cookie but you may have change it.&lt;br /&gt;
&lt;br /&gt;
Here is a code that should work if you have installed your Apache::AuthCAS sql tables in the same database where you store your eprints tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub current_user&lt;br /&gt;
{&lt;br /&gt;
  my( $self ) = @_;&lt;br /&gt;
&lt;br /&gt;
  if( $self-&amp;gt;{logged_out} )&lt;br /&gt;
  {&lt;br /&gt;
    return undef;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  if( !defined $self-&amp;gt;{current_user} )&lt;br /&gt;
  {&lt;br /&gt;
    if( $self-&amp;gt;get_archive-&amp;gt;get_conf( &amp;quot;cookie_auth&amp;quot; ) )&lt;br /&gt;
    {&lt;br /&gt;
      if ( $self-&amp;gt;get_archive-&amp;gt;get_conf( 'cas_auth' ) )&lt;br /&gt;
      {&lt;br /&gt;
        my $username;&lt;br /&gt;
        my $cookie_name = $self-&amp;gt;get_archive-&amp;gt;get_conf( 'cas_cookie_name' );&lt;br /&gt;
        if( defined $ENV{HTTP_CAS_FILTER_USER})&lt;br /&gt;
        {           $username = $ENV{HTTP_CAS_FILTER_USER};&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
          my $ticket = raw_cookie($cookie_name);&lt;br /&gt;
          if ($ticket ne '') {&lt;br /&gt;
            my $sql = &amp;quot;SELECT uid FROM cas_sessions where id='?'&amp;quot;;&lt;br /&gt;
            my $sth = $self-&amp;gt;get_database()-&amp;gt;prepare( $sql );&lt;br /&gt;
            $self-&amp;gt;get_database()-&amp;gt;execute($sth,$ticket);&lt;br /&gt;
            my @info = $sth-&amp;gt;fetchrow_array();&lt;br /&gt;
            my @list = split(&amp;quot;:&amp;quot;,$info[0]);&lt;br /&gt;
            $username = $list[0];&lt;br /&gt;
            $sth-&amp;gt;finish;&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        $self-&amp;gt;{current_user} = EPrints::DataObj::User::user_with_username( $self, $username );&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      # Create user FROM LDAP server if needed&lt;br /&gt;
      if (not defined $self-&amp;gt;{current_user})&lt;br /&gt;
      {&lt;br /&gt;
         my $session = $self;&lt;br /&gt;
&lt;br /&gt;
         my $ldap_host = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_host');&lt;br /&gt;
         my $ldap_version = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_version');&lt;br /&gt;
         my $ldap_bind_user = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_bind_user');&lt;br /&gt;
         my $ldap_bind_pass = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_bind_pass');&lt;br /&gt;
         my $ldap_base = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_base');&lt;br /&gt;
         my $ldap_scope = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_scope');&lt;br /&gt;
         my $ldap_search_string = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_search_string');&lt;br /&gt;
         $ldap_search_string =~ s/!!USERNAME!!/$username/g;&lt;br /&gt;
&lt;br /&gt;
         my $ldap_default_email = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_email');&lt;br /&gt;
         my $ldap_default_country = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_country');                                         &lt;br /&gt;
         my $ldap_default_org = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_org');&lt;br /&gt;
         my $ldap_conforms_supann = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_conforms_supann');&lt;br /&gt;
         &lt;br /&gt;
         eval &amp;quot;use Net::LDAP;&amp;quot;;&lt;br /&gt;
         die &amp;quot;Cannot load Net::LDAP: $@&amp;quot; if $@;&lt;br /&gt;
&lt;br /&gt;
         # Connect to LDAP server&lt;br /&gt;
         my $ldap = Net::LDAP-&amp;gt;new( $ldap_host ) or die &amp;quot;$@&amp;quot;;&lt;br /&gt;
         my $mesg = $ldap-&amp;gt;bind ( $ldap_bind_user,&lt;br /&gt;
               password =&amp;gt; $ldap_bind_pass,&lt;br /&gt;
               version =&amp;gt; $ldap_version,&lt;br /&gt;
         );&lt;br /&gt;
&lt;br /&gt;
         # Search the user&lt;br /&gt;
         my $result = $ldap-&amp;gt;search(&lt;br /&gt;
               base =&amp;gt; $ldap_base,&lt;br /&gt;
               scope   =&amp;gt; $ldap_scope,&lt;br /&gt;
               filter  =&amp;gt; $ldap_search_string,&lt;br /&gt;
         );&lt;br /&gt;
&lt;br /&gt;
         # Use only the first entry !&lt;br /&gt;
         my @entries = $result-&amp;gt;entries();&lt;br /&gt;
         if (defined (my $ldap_entry = $entries[0])) {&lt;br /&gt;
            # Set user type&lt;br /&gt;
            my $usertype = &amp;quot;user&amp;quot;;&lt;br /&gt;
            my $user = EPrints::User::create_user( $session, $usertype );&lt;br /&gt;
&lt;br /&gt;
            # Set user name&lt;br /&gt;
            $user-&amp;gt;set_value( &amp;quot;username&amp;quot; , $username );&lt;br /&gt;
            my $name = {};&lt;br /&gt;
            $name-&amp;gt;{family} = $ldap_entry-&amp;gt;get_value( &amp;quot;sn&amp;quot; );&lt;br /&gt;
            $name-&amp;gt;{given} = $ldap_entry-&amp;gt;get_value( &amp;quot;givenName&amp;quot; );&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;name&amp;quot;, $name );&lt;br /&gt;
&lt;br /&gt;
            # Set Email&lt;br /&gt;
            my $email = defined $ldap_entry-&amp;gt;get_value(&amp;quot;mail&amp;quot;)&lt;br /&gt;
                      ? $ldap_entry-&amp;gt;get_value(&amp;quot;mail&amp;quot;) : $ldap_default_email;&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;email&amp;quot;, $email);&lt;br /&gt;
&lt;br /&gt;
            if ( $ldap_conforms_supann )&lt;br /&gt;
            {&lt;br /&gt;
               $user-&amp;gt;set_value(&amp;quot;org&amp;quot;, $ldap_entry-&amp;gt;get_value(&amp;quot;supannEtablissement&amp;quot;));&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
               $user-&amp;gt;set_value(&amp;quot;org&amp;quot;, $ldap_default_org);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            # Set Address&lt;br /&gt;
            my $address = $ldap_entry-&amp;gt;get_value(&amp;quot;postalAddress&amp;quot;)&lt;br /&gt;
                        . &amp;quot;\n&amp;quot;&lt;br /&gt;
                        . $ldap_entry-&amp;gt;get_value(&amp;quot;postalCode&amp;quot;)&lt;br /&gt;
                        . &amp;quot; &amp;quot;&lt;br /&gt;
                        . $ldap_entry-&amp;gt;get_value(&amp;quot;l&amp;quot;);&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;address&amp;quot;, $address);&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;country&amp;quot;, $ldap_default_country);&lt;br /&gt;
&lt;br /&gt;
            # Set URL&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;url&amp;quot;, $ldap_entry-&amp;gt;get_value(&amp;quot;labeledURI&amp;quot;));&lt;br /&gt;
            $user-&amp;gt;commit();&lt;br /&gt;
&lt;br /&gt;
            $self-&amp;gt;{current_user} = $user;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
        $self-&amp;gt;{current_user} = $self-&amp;gt;_current_user_auth_cookie;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
      $self-&amp;gt;{current_user} = $self-&amp;gt;_current_user_auth_basic;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return $self-&amp;gt;{current_user};&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code assumes CASAuth SQL tables are stored with the rest of the Eprints server. It won't work if you use a Postgres database or even if you stored your CASauth tables on an other MySQL database. If you have any good reason to use a seperated database, you will have to change some lines in order to make it work.&lt;br /&gt;
&lt;br /&gt;
==Configure your archive==&lt;br /&gt;
Add the following lines into cfg/cfg.d/misc.pl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$c-&amp;gt;{cas_auth} = 1;&lt;br /&gt;
$c-&amp;gt;{cas_cookie_name} = 'COOKIE_NAME'; # The same as in manual-secure.conf&lt;br /&gt;
&lt;br /&gt;
$c-&amp;gt;{ldap_host} = 'LDAP_HOST_NAME';&lt;br /&gt;
$c-&amp;gt;{ldap_version} = 3;&lt;br /&gt;
$c-&amp;gt;{ldap_bind_user} = 'ou=admin,dc=DOMAIN,dc=com';&lt;br /&gt;
$c-&amp;gt;{ldap_bind_pass} = 'SECRET_PASS';&lt;br /&gt;
$c-&amp;gt;{ldap_base} = 'dc=DOMAIN,dc=com';&lt;br /&gt;
$c-&amp;gt;{ldap_scope} = 'sub';&lt;br /&gt;
$c-&amp;gt;{ldap_search_string} = '(uid=!!USERNAME!!)';&lt;br /&gt;
$c-&amp;gt;{ldap_default_email} = 'A VALID EMAIL';&lt;br /&gt;
$c-&amp;gt;{ldap_default_country} = 'USA';&lt;br /&gt;
$c-&amp;gt;{ldap_default_org} = 'YOUR ORGANISATION';&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test your archive==&lt;br /&gt;
&lt;br /&gt;
You should now be able to login through your CAS server.&lt;br /&gt;
&lt;br /&gt;
==LDAP Configuration==&lt;br /&gt;
&lt;br /&gt;
Once CAS is working, you may need to copy the user entry from an LDAP server.&lt;br /&gt;
EPrints3 comes with example code in archives/ARCHIVEID/cfg/cfg.d/user_login.pl. Just use it !&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;/div&gt;</summary>
		<author><name>Florent.lartet@univ-tlse2.fr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=CAS&amp;diff=11471</id>
		<title>CAS</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=CAS&amp;diff=11471"/>
		<updated>2015-10-30T13:28:24Z</updated>

		<summary type="html">&lt;p&gt;Florent.lartet@univ-tlse2.fr: /* Install the lib */ change version, 0.1 to 0.4&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page explains how to use a CAS server to authenticate user in eprints.&lt;br /&gt;
&lt;br /&gt;
==Install a secure host==&lt;br /&gt;
&lt;br /&gt;
The first thing you'll have to do is to [[Https3|install a secure host]].&lt;br /&gt;
&lt;br /&gt;
==Apache2::AuthCAS==&lt;br /&gt;
This perl library allows you to easily communicate with a CAS sever.&lt;br /&gt;
&lt;br /&gt;
===Install the lib===&lt;br /&gt;
&lt;br /&gt;
This can be done with the command:&lt;br /&gt;
perl -MCPAN -e 'install Apache2::AuthCAS'&lt;br /&gt;
&lt;br /&gt;
More infomartion are available on http://search.cpan.org/~jhitt/Apache2-AuthCAS-0.4/lib/Apache2/AuthCAS.pm&lt;br /&gt;
&lt;br /&gt;
===Create the database to store cookies===&lt;br /&gt;
&lt;br /&gt;
You should find this mysql schema on&lt;br /&gt;
http://search.cpan.org/src/JHITT/Apache2-AuthCAS-0.1/schemaPg.sql&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Schema for use with PostgreSQL&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE cas_sessions (&lt;br /&gt;
	id				varchar(32) not null primary key,&lt;br /&gt;
	last_accessed	int8 not null,&lt;br /&gt;
	user_id			varchar(32) not null,&lt;br /&gt;
	pgtiou			varchar(64),&lt;br /&gt;
	pgt 			varchar(64)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
CREATE INDEX cas_sessions_id_index ON cas_sessions(id);&lt;br /&gt;
CREATE INDEX cas_sessions_pgtiou_index ON cas_sessions(pgtiou);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Configure your secure host===&lt;br /&gt;
You must provide some information like the CAS host. You can provide it in your virtual host, or in AuthCAS.pm.&lt;br /&gt;
Read the [http://search.cpan.org/~jhitt/Apache2-AuthCAS-0.1/lib/Apache2/AuthCAS.pm module page on CPAN] to know more about it.&lt;br /&gt;
&lt;br /&gt;
Edit $EPRINTS_ROOT/archives/$ARCHIVE_ID/var/manual-secure.conf and add the lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  PerlLoadModule Apache2::AuthCAS::Configuration&lt;br /&gt;
  PerlLoadModule Apache2::AuthCAS&lt;br /&gt;
  &amp;lt;Directory &amp;quot;/opt/eprints3/cgi/users&amp;quot;&amp;gt;&lt;br /&gt;
    AuthName &amp;quot;User Area&amp;quot;&lt;br /&gt;
    AuthType Apache2::AuthCAS&lt;br /&gt;
    AuthName &amp;quot;CAS&amp;quot;&lt;br /&gt;
    PerlAuthenHandler Apache2::AuthCAS-&amp;gt;authenticate&lt;br /&gt;
&lt;br /&gt;
    CASHost &amp;quot;HOST&amp;quot;&lt;br /&gt;
    CASPort &amp;quot;443&amp;quot;&lt;br /&gt;
    CASErrorURL &amp;quot;https://HOST/cas/error/&amp;quot;&lt;br /&gt;
    CASDbDataSource &amp;quot;dbname=DATABASE_NAME&amp;quot;&lt;br /&gt;
    CASDbDriver &amp;quot;mysql&amp;quot;&lt;br /&gt;
    CASDbUser &amp;quot;DATABASE_USERNAME&amp;quot;&lt;br /&gt;
    CASDbPass &amp;quot;DATABASE_PASSWORD&amp;quot;&lt;br /&gt;
    CASSessionCookieName &amp;quot;COOKIE_NAME&amp;quot;&lt;br /&gt;
    CASSessionTimeout &amp;quot;1800&amp;quot;&lt;br /&gt;
    CASLogLevel &amp;quot;0&amp;quot;&lt;br /&gt;
    CASRemoveTicket &amp;quot;true&amp;quot;&lt;br /&gt;
    CASPretendBasicAuth &amp;quot;true&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    PerlAuthzHandler EPrints::Apache::Auth::authz&lt;br /&gt;
    Require valid-user&lt;br /&gt;
&lt;br /&gt;
    SetHandler perl-script&lt;br /&gt;
    PerlHandler ModPerl::Registry&lt;br /&gt;
    PerlSendHeader Off&lt;br /&gt;
    Options ExecCGI FollowSymLinks&lt;br /&gt;
  &amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Eprints::Session edit==&lt;br /&gt;
Now edit the $EPRINTS_PATH/perl_lib/EPrints/Session.pm.&lt;br /&gt;
First change the line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use CGI qw(-compile);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
use CGI qw(:standard -nph -compile);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Which enables you to use the raw_cookie fuction which returns variables stored in http cookie.&lt;br /&gt;
Then go to the current_user function definition where you have to put the uid provided by AuthCAS module in $username. To do it, you just have to make a sql query which looks like that:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$sql=&amp;quot;SELECT uid FROM cas_sessions WHERE id='$user_ticket'&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where $user_ticket is the variable stored in the AuthCAS http cookie.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my $user_ticket=raw_cookie('APACHECAS');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that 'APACHECAS' is the default name for the AuthCAS cookie but you may have change it.&lt;br /&gt;
&lt;br /&gt;
Here is a code that should work if you have installed your Apache::AuthCAS sql tables in the same database where you store your eprints tables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub current_user&lt;br /&gt;
{&lt;br /&gt;
  my( $self ) = @_;&lt;br /&gt;
&lt;br /&gt;
  if( $self-&amp;gt;{logged_out} )&lt;br /&gt;
  {&lt;br /&gt;
    return undef;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  if( !defined $self-&amp;gt;{current_user} )&lt;br /&gt;
  {&lt;br /&gt;
    if( $self-&amp;gt;get_archive-&amp;gt;get_conf( &amp;quot;cookie_auth&amp;quot; ) )&lt;br /&gt;
    {&lt;br /&gt;
      if ( $self-&amp;gt;get_archive-&amp;gt;get_conf( 'cas_auth' ) )&lt;br /&gt;
      {&lt;br /&gt;
        my $username;&lt;br /&gt;
        my $cookie_name = $self-&amp;gt;get_archive-&amp;gt;get_conf( 'cas_cookie_name' );&lt;br /&gt;
        if( defined $ENV{HTTP_CAS_FILTER_USER})&lt;br /&gt;
        {           $username = $ENV{HTTP_CAS_FILTER_USER};&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
          my $ticket = raw_cookie($cookie_name);&lt;br /&gt;
          if ($ticket ne '') {&lt;br /&gt;
            my $sql = &amp;quot;SELECT uid FROM cas_sessions where id='?'&amp;quot;;&lt;br /&gt;
            my $sth = $self-&amp;gt;get_database()-&amp;gt;prepare( $sql );&lt;br /&gt;
            $self-&amp;gt;get_database()-&amp;gt;execute($sth,$ticket);&lt;br /&gt;
            my @info = $sth-&amp;gt;fetchrow_array();&lt;br /&gt;
            my @list = split(&amp;quot;:&amp;quot;,$info[0]);&lt;br /&gt;
            $username = $list[0];&lt;br /&gt;
            $sth-&amp;gt;finish;&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        $self-&amp;gt;{current_user} = EPrints::DataObj::User::user_with_username( $self, $username );&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      # Create user FROM LDAP server if needed&lt;br /&gt;
      if (not defined $self-&amp;gt;{current_user})&lt;br /&gt;
      {&lt;br /&gt;
         my $session = $self;&lt;br /&gt;
&lt;br /&gt;
         my $ldap_host = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_host');&lt;br /&gt;
         my $ldap_version = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_version');&lt;br /&gt;
         my $ldap_bind_user = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_bind_user');&lt;br /&gt;
         my $ldap_bind_pass = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_bind_pass');&lt;br /&gt;
         my $ldap_base = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_base');&lt;br /&gt;
         my $ldap_scope = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_scope');&lt;br /&gt;
         my $ldap_search_string = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_search_string');&lt;br /&gt;
         $ldap_search_string =~ s/!!USERNAME!!/$username/g;&lt;br /&gt;
&lt;br /&gt;
         my $ldap_default_email = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_email');&lt;br /&gt;
         my $ldap_default_country = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_country');                                         &lt;br /&gt;
         my $ldap_default_org = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_default_org');&lt;br /&gt;
         my $ldap_conforms_supann = $session-&amp;gt;get_archive()-&amp;gt;get_conf('ldap_conforms_supann');&lt;br /&gt;
         &lt;br /&gt;
         eval &amp;quot;use Net::LDAP;&amp;quot;;&lt;br /&gt;
         die &amp;quot;Cannot load Net::LDAP: $@&amp;quot; if $@;&lt;br /&gt;
&lt;br /&gt;
         # Connect to LDAP server&lt;br /&gt;
         my $ldap = Net::LDAP-&amp;gt;new( $ldap_host ) or die &amp;quot;$@&amp;quot;;&lt;br /&gt;
         my $mesg = $ldap-&amp;gt;bind ( $ldap_bind_user,&lt;br /&gt;
               password =&amp;gt; $ldap_bind_pass,&lt;br /&gt;
               version =&amp;gt; $ldap_version,&lt;br /&gt;
         );&lt;br /&gt;
&lt;br /&gt;
         # Search the user&lt;br /&gt;
         my $result = $ldap-&amp;gt;search(&lt;br /&gt;
               base =&amp;gt; $ldap_base,&lt;br /&gt;
               scope   =&amp;gt; $ldap_scope,&lt;br /&gt;
               filter  =&amp;gt; $ldap_search_string,&lt;br /&gt;
         );&lt;br /&gt;
&lt;br /&gt;
         # Use only the first entry !&lt;br /&gt;
         my @entries = $result-&amp;gt;entries();&lt;br /&gt;
         if (defined (my $ldap_entry = $entries[0])) {&lt;br /&gt;
            # Set user type&lt;br /&gt;
            my $usertype = &amp;quot;user&amp;quot;;&lt;br /&gt;
            my $user = EPrints::User::create_user( $session, $usertype );&lt;br /&gt;
&lt;br /&gt;
            # Set user name&lt;br /&gt;
            $user-&amp;gt;set_value( &amp;quot;username&amp;quot; , $username );&lt;br /&gt;
            my $name = {};&lt;br /&gt;
            $name-&amp;gt;{family} = $ldap_entry-&amp;gt;get_value( &amp;quot;sn&amp;quot; );&lt;br /&gt;
            $name-&amp;gt;{given} = $ldap_entry-&amp;gt;get_value( &amp;quot;givenName&amp;quot; );&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;name&amp;quot;, $name );&lt;br /&gt;
&lt;br /&gt;
            # Set Email&lt;br /&gt;
            my $email = defined $ldap_entry-&amp;gt;get_value(&amp;quot;mail&amp;quot;)&lt;br /&gt;
                      ? $ldap_entry-&amp;gt;get_value(&amp;quot;mail&amp;quot;) : $ldap_default_email;&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;email&amp;quot;, $email);&lt;br /&gt;
&lt;br /&gt;
            if ( $ldap_conforms_supann )&lt;br /&gt;
            {&lt;br /&gt;
               $user-&amp;gt;set_value(&amp;quot;org&amp;quot;, $ldap_entry-&amp;gt;get_value(&amp;quot;supannEtablissement&amp;quot;));&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
               $user-&amp;gt;set_value(&amp;quot;org&amp;quot;, $ldap_default_org);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            # Set Address&lt;br /&gt;
            my $address = $ldap_entry-&amp;gt;get_value(&amp;quot;postalAddress&amp;quot;)&lt;br /&gt;
                        . &amp;quot;\n&amp;quot;&lt;br /&gt;
                        . $ldap_entry-&amp;gt;get_value(&amp;quot;postalCode&amp;quot;)&lt;br /&gt;
                        . &amp;quot; &amp;quot;&lt;br /&gt;
                        . $ldap_entry-&amp;gt;get_value(&amp;quot;l&amp;quot;);&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;address&amp;quot;, $address);&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;country&amp;quot;, $ldap_default_country);&lt;br /&gt;
&lt;br /&gt;
            # Set URL&lt;br /&gt;
            $user-&amp;gt;set_value(&amp;quot;url&amp;quot;, $ldap_entry-&amp;gt;get_value(&amp;quot;labeledURI&amp;quot;));&lt;br /&gt;
            $user-&amp;gt;commit();&lt;br /&gt;
&lt;br /&gt;
            $self-&amp;gt;{current_user} = $user;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
        $self-&amp;gt;{current_user} = $self-&amp;gt;_current_user_auth_cookie;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
      $self-&amp;gt;{current_user} = $self-&amp;gt;_current_user_auth_basic;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return $self-&amp;gt;{current_user};&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code assumes CASAuth SQL tables are stored with the rest of the Eprints server. It won't work if you use a Postgres database or even if you stored your CASauth tables on an other MySQL database. If you have any good reason to use a seperated database, you will have to change some lines in order to make it work.&lt;br /&gt;
&lt;br /&gt;
==Configure your archive==&lt;br /&gt;
Add the following lines into cfg/cfg.d/misc.pl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$c-&amp;gt;{cas_auth} = 1;&lt;br /&gt;
$c-&amp;gt;{cas_cookie_name} = 'COOKIE_NAME'; # The same as in manual-secure.conf&lt;br /&gt;
&lt;br /&gt;
$c-&amp;gt;{ldap_host} = 'LDAP_HOST_NAME';&lt;br /&gt;
$c-&amp;gt;{ldap_version} = 3;&lt;br /&gt;
$c-&amp;gt;{ldap_bind_user} = 'ou=admin,dc=DOMAIN,dc=com';&lt;br /&gt;
$c-&amp;gt;{ldap_bind_pass} = 'SECRET_PASS';&lt;br /&gt;
$c-&amp;gt;{ldap_base} = 'dc=DOMAIN,dc=com';&lt;br /&gt;
$c-&amp;gt;{ldap_scope} = 'sub';&lt;br /&gt;
$c-&amp;gt;{ldap_search_string} = '(uid=!!USERNAME!!)';&lt;br /&gt;
$c-&amp;gt;{ldap_default_email} = 'A VALID EMAIL';&lt;br /&gt;
$c-&amp;gt;{ldap_default_country} = 'USA';&lt;br /&gt;
$c-&amp;gt;{ldap_default_org} = 'YOUR ORGANISATION';&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test your archive==&lt;br /&gt;
&lt;br /&gt;
You should now be able to login through your CAS server.&lt;br /&gt;
&lt;br /&gt;
==LDAP Configuration==&lt;br /&gt;
&lt;br /&gt;
Once CAS is working, you may need to copy the user entry from an LDAP server.&lt;br /&gt;
EPrints3 comes with example code in archives/ARCHIVEID/cfg/cfg.d/user_login.pl. Just use it !&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;/div&gt;</summary>
		<author><name>Florent.lartet@univ-tlse2.fr</name></author>
		
	</entry>
</feed>