...
Installer un JDK, Maven et Tomcat comme spécifié sur cette page : Installation Java, Maven et Tomcat
Installation d'un serveur CAS basique
Installation
Télécharger la dernière version de CAS depuis http://www.jasig.org/cas/download et décompresser :
...
| Bloc de code |
|---|
[root@cas cas-server-webapp]# mvn package install [root@cas cas-server-webapp]# cp target/cas.war /var/lib/tomcat5/webapps/ROOT.war [root@cas cas-server-webapp]# /etc/init.d/tomcat5 restart |
Debuggage
Ajouter dans le fichier src/main/webapp/WEB-INF/classes/log4j.properties la ligne suivante :
...
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
Désactiver si nécessaire le firewall pour le port 8080 (system-config-firewall) et tester http://cas.ifsic.univ-rennes1.fr:8080 (user = test, password = test).
Passage en HTTPS
Génération du keystore
Rapatrier Jetty (par exemple dans /usr/local) depuis http://static.roopindersingh.com/jetty-6.1.7.jar .
...
| Bloc de code |
|---|
[root@cas private]# cd /etc/tomcat5/ [root@cas tomcat5]# chgrp tomcat cas.ifsic.univ-rennes1.fr.keystore [root@cas tomcat5]# chmod 640 cas.ifsic.univ-rennes1.fr.keystore [root@cas tomcat5]# |
Configuration de Tomcat
Dans /etc/tomcat5/server.xml, commenter le connecteur HTTP sur le port 8080 et décommenter le connecteur HTTPS sur le port 8443 en ajoutant l'attribut :
| Bloc de code |
|---|
keystoreFile="/etc/tomcat5/cas.ifsic.univ-rennes1.fr.keystore" |
Test
Redémarrer Tomcat, désactiver si nécessaire le firewall pour le port 8443 et tester https://cas.ifsic.univ-rennes1.fr:8443 (user = test, password = test).
Ajout de l'authentification LDAP
Script de déploiement de CAS
Pour faciliter le déploiement du serveur CAS, on pourra ajouter le script /usr/local/cas-server-3.3.5/deploy.sh suivant :
| Bloc de code |
|---|
#!/bin/bash /etc/init.d/tomcat5 stop pushd /usr/local/cas-server-3.3.5/cas-server-webapp mvn package install && rm -f /var/lib/tomcat5/webapps/ROOT.war && cp target/cas.war /var/lib/tomcat5/webapps/ROOT.war popd /etc/init.d/tomcat5 start |
Configuration de CAS pour LDAP
Dans le fichier src/main/webapp/WEB-INF/deployerConfigContext.xml, ajouter le bean suivant pour déclarer le contexte LDAP :
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<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 :
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<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 d'un frontal Apache
On va dans cette partie configurer un frontal Apache sur le port 443, qui va accéder au Tomcat du serveur CAS en AJP sur le port 8009.
Configuration de Apache
| Remarque |
|---|
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'admisnitration système (cette architecture est employée de manière générale sur les plateformes d'exploitation). |
Configuration de Apache
Installer le certificat du serveur en éditant /etc/httpdInstaller le certificat du serveur en éditant /etc/httpd/conf.d/ssl.conf et modifier les lignes suivantes dans le virtual host _default_:443 :
...
| Bloc de code |
|---|
ProxyPass / ajp://cas.ifsic.univ-rennes1.fr:8009/ min=0 max=100 smax=50 ttl=10 route=ori-indexing |
Configuration de Tomcat
Si S'assurer que le connecteur AJP sur le port 8009 n'avait pas été précédemment commenté, il n'y a rien de plus à configurer au niveau de Tomcat.
Le connecteur HTTPS sur le port 8443 peut en revanche être commenté.
Test
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 Kerberos
Configuration de Apache
On ajoute simplement mod_auth_kerb au serveur virtuel frontal :
| Bloc de code |
|---|
<Location />
#SSLRequireSSL
AuthType KerberosV5
AuthName "Kerberos Login"
KrbMethodNegotiate On
KrbMethodK5Passwd Off
KrbAuthRealms UNIV-RENNES1.FR
Krb5KeyTab /etc/httpd/conf/mod_auth_kerb.keytab
#require valid-user
</Location> |
Bien noter que l'on ne force pas l'authentification Kerberos (la directive require valid-user est commentée) pour que le serveur CAS bascule sur une authentification LDAP si l'authentification Kerberos n'est pas vérifiée.
Configuration de CAS
est décommenté et a bien le paramètres tomcatAuthentication positionné à false :
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<Connector port="8009"
debug="0"
enableLookups="false"
redirectPort="8443"
protocol="AJP/1.3"
tomcatAuthentication="false" /> |
Le connecteur HTTPS sur le port 8443 peut être commenté.
Test
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 Kerberos
La documentation de référence est http://www.ja-sig.orgLes instruction de configuration de CAS sont extraites de http://www.ja-sig.org/wiki/display/CASUM/TrustedSPNEGO .
Ajouter le support du handler trusted
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>org.jasig.cas</groupId>
<artifactId>cas-server-support-trusted</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="remoteAuthenticate">
<action bean="principalFromRemoteAction" />
<transition on="success" to="sendTicketGrantingTicket" />
<transition on="error" to="viewLoginForm" />
</action-state>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 :
| Bloc de code |
|---|
[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
Dans ce même fichier, remplacer les références à viewLoginForm par remoteAuthenticate pour les trois decision-state gatewayRequestCheck, renewRequestCheck et generateServiceTicket :
...
<decision-state id="gatewayRequestCheck">
<if
test="${externalContext.requestParameterMap['gateway'] != '' && externalContext.requestParameterMap['gateway'] != null && flowScope.service != null}"
then="redirect"
else="remoteAuthenticate" />
</decision-state>...
<decision-state id="renewRequestCheck">
<if
test="${externalContext.requestParameterMap['renew'] != '' && externalContext.requestParameterMap['renew'] != null}"
then="remoteAuthenticate"
else="generateServiceTicket" />
</decision-state>...
<action-state id="generateServiceTicket">
<action bean="generateServiceTicketAction" />
<transition on="success" to ="warn" />
<transition on="error" to="remoteAuthenticate" />
<transition on="gateway" to="redirect" />
</action-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-servletpom.xml et ajouter la dépendance suivante (par exemple juste avant le bean authenticationViaFormActionaprès la dépendance vers le module cas-server-support-ldap) :
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<bean<dependency> id="principalFromRemoteAction" class="org.jasig.cas.adaptors.trusted.web.flow.PrincipalFromRequestRemoteUserNonInteractiveCredentialsAction" p:centralAuthenticationService-ref="centralAuthenticationService" /> |
Modifier le schéma d'authentification
<groupId>${project.groupId}</groupId>
<artifactId>cas-server-support-spnego</artifactId>
<version>${project.version}</version>
</dependency> |
Modifier le login webflow
Editer le fichier <casPour modifier le schéma d'authentification, éditer le fichier <cas-home>/cas-server-webapp/src/main/webapp/WEB-INF/deployerConfigContextlogin-webflow.xml et modifier le bean authenticationManager en ajoutant :
...
ajouter l'état suivant juste avant l'état viewLoginForm :
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<bean<action-state id="authenticationManager" class="org.jasig.cas.authentication.AuthenticationManagerImplstartAuthenticate"> <property<action namebean="credentialsToPrincipalResolversnegociateSpnego" /> <transition on="success" <list> <!-- ... the others credentialsToPrincipalResolvers ... --to="spnego" /> </action-state> <action-state id="spnego"> <action bean="spnego" /> <transition <bean class="org.jasig.cas.adaptors.trusted.authentication.principal.PrincipalBearingCredentialsToPrincipalResolveron="success" to="sendTicketGrantingTicket" /> <transition </list> </property> <property name="authenticationHandlers"> <list> <bean class="org.jasig.cas.adaptors.trusted.authentication.handler.support.PrincipalBearingCredentialsAuthenticationHandler" /> <!-- ... the others authenticationHandlers... --> </list> </property> </bean> |
...
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 :
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<decision-state id="gatewayRequestCheck">
<if
test="${externalContext.requestParameterMap['gateway'] != '' && externalContext.requestParameterMap['gateway'] != null && flowScope.service != null}"
then="redirect"
else="startAuthenticate" />
</decision-state> |
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<bean <decision-state id="authenticationManagerrenewRequestCheck"> <if classtest="org.jasig.cas.authentication.AuthenticationManagerImpl"> <property name="credentialsToPrincipalResolvers">${externalContext.requestParameterMap['renew'] != '' && externalContext.requestParameterMap['renew'] != null}" <list>then="startAuthenticate" <bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolverelse="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) :
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<bean id="negociateSpnego" <bean class="org.jasig.cas.support.spnego.authenticationweb.principalflow.HttpBasedServiceCredentialsToPrincipalResolverSpnegoNegociateCredentialsAction" /> <bean id="spnego" <bean class="org.jasig.cas.adaptorssupport.trustedspnego.authenticationweb.principalflow.PrincipalBearingCredentialsToPrincipalResolverSpnegoCredentialsAction" /> <property </list> </property> <property name="authenticationHandlers"> <list> <bean class="org.jasig.cas.adaptors.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
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<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 à :
| Bloc de code | ||||
|---|---|---|---|---|
| ||||
<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 :
| Bloc de code |
|---|
<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.FRtrusted.authentication.handler.support.PrincipalBearingCredentialsAuthenticationHandler" /> <property <bean classname="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" "kerberosKdc" value="kerb.ifsic.univ-rennes1.fr" /> <property name="loginConf" 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> |
Test
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 :
| Bloc de code |
|---|
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"
}; |
| Astuce |
|---|
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 :
| Bloc de code |
|---|
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.ça doit marcher...