Nom du serveur |
cas-kerb.univ-rennes1.fr |
Système |
RedHat Entreprise 5 |
Ouverture de ports |
ssh (22 tcp) |
Installation système
Installer les packages Tomcat (yum install tomcat5), Apache (yum install httpd), puis Maven :
[root@cas-kerb ~]# cd /usr/local [root@cas-kerb local]# wget ftp://ftp.inria.fr/pub/Apache/maven/binaries/apache-maven-2.2.1-bin.tar.gz --2010-03-09 10:35:41-- ftp://ftp.inria.fr/pub/Apache/maven/binaries/apache-maven-2.2.1-bin.tar.gz => `apache-maven-2.2.1-bin.tar.gz' Resolving ftp.inria.fr... 192.93.2.32 Connecting to ftp.inria.fr|192.93.2.32|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD /pub/Apache/maven/binaries ... done. ==> SIZE apache-maven-2.2.1-bin.tar.gz ... 2840961 ==> PASV ... done. ==> RETR apache-maven-2.2.1-bin.tar.gz ... done. Length: 2840961 (2.7M) 100%[================================>] 2,840,961 2.01M/s in 1.3s 2010-03-09 10:35:43 (2.01 MB/s) - `apache-maven-2.2.1-bin.tar.gz' saved [2840961] [root@cas-kerb local]# tar xf apache-maven-2.2.1-bin.tar.gz [root@cas-kerb local]# ln -s apache-maven-2.2.1 maven2 [root@cas-kerb local]# cd /etc/profile.d [root@cas-kerb profile.d]# cat > maven2.sh export PATH=$PATH:/usr/local/maven2/bin [root@cas-kerb profile.d]# chmod 644 maven2.sh [root@cas-kerb profile.d]# . maven2.sh [root@cas-kerb profile.d]#
Installation de CAS
Télécharger la dernière version de CAS depuis http://www.jasig.org/cas/download et décompresser :
[root@cas-kerb ~]# cd /usr/local [root@cas-kerb local]# wget http://www.ja-sig.org/downloads/cas/cas-server-3.3.5-release.tar.gz --2010-03-09 09:25:51-- http://www.ja-sig.org/downloads/cas/cas-server-3.3.5-release.tar.gz Resolving www.ja-sig.org... 128.112.131.108 Connecting to www.ja-sig.org|128.112.131.108|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 14467126 (14M) [application/x-gzip] Saving to: `cas-server-3.3.5-release.tar.gz' 100%[========================>] 14,467,126 427K/s in 15s 2010-03-09 09:26:07 (919 KB/s) - `cas-server-3.3.5-release.tar.gz' saved [14467126/14467126] [root@cas-kerb local]# tar xf cas-server-3.3.5-release.tar.gz [root@cas-kerb local]# cd cas-server-3.3.5 [root@cas-kerb cas-server-3.3.5]#
Créer un répertoire cas-server-rennes1 dans lequel seront stockées toutes les personnalisations et y ajouter le fichier pom.xml suivant :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>org.jasig.cas</groupId> <artifactId>cas-server</artifactId> <version>3.3.5</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>fr.univrennes1.cas</groupId> <artifactId>cas-server-rennes1</artifactId> <version>3.3.5</version> <packaging>war</packaging> <name>University of Rennes 1 CAS webapp</name> <organization> <name>University of Rennes 1</name> <url>http://www.univ-rennes1.fr.fr</url> </organization> <description>The University of Rennes 1 customizations to the JA-SIG CAS server.</description> <dependencies> <dependency> <groupId>org.jasig.cas</groupId> <artifactId>cas-server-webapp</artifactId> <version>${project.version}</version> <type>war</type> </dependency> <dependency> <groupId>org.jasig.cas</groupId> <artifactId>cas-server-core</artifactId> <version>${project.version}</version> </dependency> </dependencies> <build> <finalName>cas</finalName> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>RELEASE</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> <repositories> <repository> <id>jasig-repository</id> <name>JA-SIG Maven2 Repository</name> <url>http://developer.ja-sig.org/maven2</url> </repository> </repositories> <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-changelog-plugin</artifactId> </plugin> </plugins> </reporting> </project>
Plutôt que modifier les fichiers de la distribution CAS, il est préférable de maintenir toutes modifications effectuées dans ce répertoire, ce qui facilite les mises à jour. Tous les fichiers trouvés dans ce répertoire écraseront les fichiers de la distribution, on adoptera donc exactement la même hiérarchie de fichiers que celle de la distribution.
Installation basique
Copier le fichier src/main/webapp/WEB-INF/classes/log4j.properties de cas-server-webapp dans src/main/webapp/WEB-INF/classes et indiquer le chemin des logs :
log4j.appender.logfile.File=/var/log/tomcat5/cas.log
Générer le WAR, le copier dans Tomcat et redémarrer :
[root@cas cas-server-rennes1]# mvn package install [root@cas cas-server-rennes1]# cp target/cas.war /var/lib/tomcat5/webapps/ROOT.war [root@cas cas-server-rennes1]# /etc/init.d/tomcat5 restart
Debug
Ajouter dans le fichier src/main/webapp/WEB-INF/classes/log4j.properties la ligne suivante :
log4j.logger.org.jasig.cas=DEBUG
Les logs se trouvent dans le répertoire /var/log/tomcat5.
La mise au point la plus difficile est celle de Kerberos (les logs en debug de Krb5LoginModule se trouvent dans catalina.out).
Test
Tester http://cas-kerb.univ-rennes1.fr:8080 (user = test, password = test).
Script de déploiement de CAS
Pour faciliter le déploiement du serveur CAS et le redémarrage de Tomcat, on pourra ajouter le script /usr/local/cas-server-3.3.5/deploy-restart.sh suivant :
[root@cas-kerb ~]# cd /usr/local/cas-server-3.3.5 [root@cas-kerb cas-server-3.3.5]# cat > deploy-restart.sh #!/bin/bash service tomcat5 stop pushd /usr/local/cas-server-3.3.5/cas-server-rennes1 mvn package && rm -f /var/lib/tomcat5/webapps/ROOT.war && cp target/cas.war /var/lib/tomcat5/webapps/ROOT.war popd service tomcat5 start [root@cas-kerb cas-server-3.3.5]# chmod 744 deploy-restart.sh [root@cas-kerb cas-server-3.3.5]#
Ajout d'un frontal Apache
On va dans cette partie configurer un frontal Apache sur le port 80, qui va accéder au Tomcat du serveur CAS en AJP sur le port 8009.
Il n'est pas obligatoire de mettre un frontal Apache devant Tomcat, mais cela délègue le chiffrement à Apache au lieu de Tomcat et simplifie l'administration système (cette architecture est employée de manière générale sur les plateformes d'exploitation).
Configuration de Apache
Insérer dans /etc/httpd/conf.d/proxy_ajp.conf les lignes suivantes :
ProxyPass / ajp://cas-kerb.univ-rennes1.fr:8009/ min=0 max=100 smax=50 ttl=10
Configuration de Tomcat
S'assurer que le connecteur AJP sur le port 8009 n'est pas commenté et a bien le paramètres tomcatAuthentication positionné à false :
<Connector port="8009" debug="0" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" tomcatAuthentication="false" />
Test
Après redémarrage de Apache et Tomcat, le serveur CAS doit désormais répondre sur l'URL https://cas-kerb.univ-rennes1.fr (sur le port 80 par défaut en HTTP).
Passage en HTTPS
Configuration de Apache
Installer le certificat du serveur en éditant /etc/httpd/conf.d/ssl.conf et modifier les lignes suivantes dans le virtual host _default_:443 :
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateFile /etc/pki/tls/private/cas-kerb.univ-rennes1.fr.pem #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key SSLCertificateKeyFile /etc/pki/tls/private/cas-kerb.univ-rennes1.fr.key
Test
Après redémarrage de Apache, le serveur CAS doit désormais répondre sur l'URL https://cas.ifsic.univ-rennes1.fr (sur le port 443 par défaut en HTTPS).
Ajout de l'authentification LDAP
Configuration de CAS pour LDAP
Ajouter la dépendance vers le module cas-server-support-ldap dans le fichier pom.xml :
<dependency> <groupId>org.jasig.cas</groupId> <artifactId>cas-server-support-ldap</artifactId> <version>${project.version}</version> </dependency>
Copier le fichier src/main/webapp/WEB-INF/deployerConfigContext.xml de cas-server-webapp dans src/main/webapp/WEB-INF, ajouter le bean suivant pour déclarer le contexte LDAP :
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> <property name="pooled" value="true"/> <property name="urls"> <list> <value>ldap://ldapglobal.univ-rennes1.fr/</value> </list> </property> <property name="userDn" value=""/> <property name="password" value=""/> <property name="baseEnvironmentProperties"> <map> <entry> <key> <value>java.naming.security.authentication</value> </key> <value>simple</value> </entry> </map> </property> </bean>
puis changer le handler SimpleTestUsernamePasswordAuthenticationHandler par celui-ci :
<bean class="org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticationHandler" > <property name="filter" value="uid=%u,ou=people,dc=univ-rennes1,dc=fr" /> <property name="contextSource" ref="contextSource" /> </bean>
Test
Redéployer le serveur CAS, et tester l'authentification d'un utilisateur LDAP.
Ajout de l'authentification Kerberos
La documentation de référence est http://www.ja-sig.org/wiki/display/CASUM/SPNEGO .
Configuration de Kerberos
Procéder comme vu précédemment pour générer le fichier /etc/http.keytab qui sera utilisé ultérieurement par la librairie JCIFS :
[root@cas ~]# kadmin Authenticating as principal root/admin@UNIV-RENNES1.FR with password. Password for root/admin@UNIV-RENNES1.FR: kadmin: ktadd -k /etc/http.keytab HTTP/cas.ifsic.univ-rennes1.fr Entry for principal HTTP/cas.ifsic.univ-rennes1.fr with kvno 3, encryption type AES-256 CTS mode with 96-bit SHA-1 HMAC added to keytab WRFILE:/etc/http.keytab. Entry for principal HTTP/cas.ifsic.univ-rennes1.fr with kvno 3, encryption type AES-128 CTS mode with 96-bit SHA-1 HMAC added to keytab WRFILE:/etc/http.keytab. Entry for principal HTTP/cas.ifsic.univ-rennes1.fr with kvno 3, encryption type Triple DES cbc mode with HMAC/sha1 added to keytab WRFILE:/etc/http.keytab. Entry for principal HTTP/cas.ifsic.univ-rennes1.fr with kvno 3, encryption type ArcFour with HMAC/md5 added to keytab WRFILE:/etc/http.keytab. Entry for principal HTTP/cas.ifsic.univ-rennes1.fr with kvno 3, encryption type DES with HMAC/sha1 added to keytab WRFILE:/etc/http.keytab. Entry for principal HTTP/cas.ifsic.univ-rennes1.fr with kvno 3, encryption type DES cbc mode with RSA-MD5 added to keytab WRFILE:/etc/http.keytab. kadmin: exit [root@cas ~]
Configuration de CAS
Ajouter le support du handler spnego
Editer le fichier <cas-home>/cas-server-webapp/pom.xml et ajouter la dépendance suivante (par exemple juste après la dépendance vers le module cas-server-support-ldap) :
<dependency> <groupId>${project.groupId}</groupId> <artifactId>cas-server-support-spnego</artifactId> <version>${project.version}</version> </dependency>
Modifier le login webflow
Editer le fichier <cas-home>/cas-server-webapp/src/main/webapp/WEB-INF/login-webflow.xml et ajouter l'état suivant juste avant l'état viewLoginForm :
<action-state id="startAuthenticate"> <action bean="negociateSpnego" /> <transition on="success" to="spnego" /> </action-state> <action-state id="spnego"> <action bean="spnego" /> <transition on="success" to="sendTicketGrantingTicket" /> <transition on="error" to="viewLoginForm" /> </action-state>
Dans ce même fichier, remplacer les références à viewLoginForm par remoteAuthenticate pour les trois decision-state gatewayRequestCheck et renewRequestCheck :
<decision-state id="gatewayRequestCheck"> <if test="${externalContext.requestParameterMap['gateway'] != '' && externalContext.requestParameterMap['gateway'] != null && flowScope.service != null}" then="redirect" else="startAuthenticate" /> </decision-state>
<decision-state id="renewRequestCheck"> <if test="${externalContext.requestParameterMap['renew'] != '' && externalContext.requestParameterMap['renew'] != null}" then="startAuthenticate" else="generateServiceTicket" /> </decision-state>
Déclarer le bean implémentant le nouvel état du webflow en ajoutant les lignes suivantes dans le fichier <cas-home>/cas-server-webapp/src/main/webapp/WEB-INF/cas-servlet.xml (par exemple juste avant le bean authenticationViaFormAction) :
<bean id="negociateSpnego" class="org.jasig.cas.support.spnego.web.flow.SpnegoNegociateCredentialsAction" /> <bean id="spnego" class="org.jasig.cas.support.spnego.web.flow.SpnegoCredentialsAction"> <property name="centralAuthenticationService" ref="centralAuthenticationService"/> </bean>
Modifier le schéma d'authentification
Pour modifier le schéma d'authentification, éditer le fichier <cas-home>/cas-server-webapp/src/main/webapp/WEB-INF/deployerConfigContext.xml et modifier le bean authenticationManager en ajoutant :
- PrincipalBearingCredentialsToPrincipalResolver après les resolvers existants de credentialsToPrincipalResolvers
- PrincipalBearingCredentialsAuthenticationHandler avant les handlers existants de authenticationHandlers
<bean id="authenticationManager" class="org.jasig.cas.authentication.AuthenticationManagerImpl"> <property name="credentialsToPrincipalResolvers"> <list> <!-- ... the others credentialsToPrincipalResolvers ... --> <bean class="org.jasig.cas.support.spnego.authentication.principal.SpnegoCredentialsToPrincipalResolver" /> </list> </property> <property name="authenticationHandlers"> <list> <bean class="org.jasig.cas.support.spnego.authentication.handler.support.JCIFSSpnegoAuthenticationHandler"> <property name="authentication"> <bean class="jcifs.spnego.Authentication" /> </property> <property name="principalWithDomainName" value="true" /> <property name="NTLMallowed" value="false"/> </bean> <!-- ... the others authenticationHandlers... --> </list> </property> </bean>
Le bean authenticationManager doit ainsi ressembler à :
<bean id="authenticationManager" class="org.jasig.cas.authentication.AuthenticationManagerImpl"> <property name="credentialsToPrincipalResolvers"> <list> <bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" /> <bean class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" /> <bean class="org.jasig.cas.support.spnego.authentication.principal.SpnegoCredentialsToPrincipalResolver" /> </list> </property> <property name="authenticationHandlers"> <list> <bean class="org.jasig.cas.support.spnego.authentication.handler.support.JCIFSSpnegoAuthenticationHandler"> <property name="authentication"> <bean class="jcifs.spnego.Authentication" /> </property> <property name="principalWithDomainName" value="true" /> <property name="NTLMallowed" value="false"/> </bean> <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref="httpClient" /> <bean class="org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticationHandler" > <property name="filter" value="uid=%u,ou=people,dc=univ-rennes1,dc=fr" /> <property name="contextSource" ref="contextSource" /> </bean> </list> </property> </bean>
Ajouter enfin le bean jcifsConfig, qui done les options de configuration de JCIFS :
<bean name="jcifsConfig" class="org.jasig.cas.support.spnego.authentication.handler.support.JCIFSConfig"> <property name="jcifsServicePrincipal" value="HTTP/cas.ifsic.univ-rennes1.fr" /> <property name="kerberosDebug" value="true" /> <property name="kerberosRealm" value="UNIV-RENNES1.FR" /> <property name="kerberosKdc" value="kerb.ifsic.univ-rennes1.fr" /> <property name="loginConf" value="/usr/local/cas-server-3.3.5/cas-server-webapp/src/main/webapp/WEB-INF/login.conf" />
Configuration de JCIFS
La configuration de JCIFS se fait également dans le fichier login.conf pointé par le bean jcifsConfig. Créer ce fichier avec le contenu suivant :
jcifs.spnego.initiate { com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true keyTab="/etc/http.keytab" }; jcifs.spnego.accept { com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true keyTab="/etc/http.keytab" };
On peut également ajouter l'option debug=true pour obtenir des informations dans catalina.out.
Configuration de Tomcat
Il faut passer à la JVM qui exécute Tomcat l'option -Djavax.security.auth.useSubjectCredsOnly=false, par exemple en éditant le fichier /etc/tomcat5/tomcat5.conf et en ajoutant la ligne suivante :
JAVA_OPTS="$JAVA_OPTS -Djavax.security.auth.useSubjectCredsOnly=false"
Test
Un navigateur bien configuré et possédant des credentials Kerberos valides doit maintenant se connecter au serveur CAS sans aucune interaction....