CAS Liferay 6 Integration
The following are a set of instructions for integrating Liferay Portal with CAS Server to setup single sign on (SSO) between Liferay and an existing web application.
Setting up CAS server #
We will begin with setting up JA-SIG CAS server on Tomcat 6.0.x.
Download cas-server WAR from Liferay's download page and drop the cas-web.war file into Tomcat's webapps dir. In a production environment The CAS server should really run on its own tomcat instance but for testing purposes we'll drop it in the same instance as our Liferay portal.
We'll need to edit the server.xml file in tomcat and uncomment the SSL section to open up port 8443.
<!-- Define a SSL HTTP/1.1 Connector on port 8443 --> <Connector port="8443" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" />
Setting up the CAS client #
In version 6.0, the cas client is already available in ROOT/WEB-INF/lib folder.
Generate the SSL cert with Java keytool #
Now that we have everything we need, it's time to generate an SSL cert for our CAS server.
In any directory (I use my root) enter the command:
keytool -genkey -alias tomcat -keypass changeit -keyalg RSA
Note: Be sure to use the keytool that comes with the Java VM (%JAVA_HOME%/jre/bin/keytool), as on some systems the default points to the GNU version of keytool, where the two seem incompatible.
Answer the questions: (note that your firstname and lastname MUST be hostname of your server and cannot be a IP address; this is very important as an IP address will fail client hostname verification even if it is correct)
Enter keystore password: changeit What is your first and last name? [Unknown]: localhost What is the name of your organizational unit? [Unknown]: What is the name of your organization? [Unknown]: What is the name of your City or Locality? [Unknown]: What is the name of your State or Province? [Unknown]: What is the two-letter country code for this unit? [Unknown]: Is CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct? [no]: y
Then enter the command:
keytool -export -alias tomcat -keypass changeit -file %FILE_NAME%
I use server.cert for %FILE_NAME%. This command exports the cert you generated from your personal keystore (In windows your personal keystore is in C:\Documents and Settings\<username>\.keystore)
Finally import the cert into Java's keystore with this command. Tomcat uses the keystore in your JRE (%JAVA_HOME%/jre/lib/security/cacerts)
keytool -import -alias tomcat -file %FILE_NAME% -keypass changeit -keystore %JAVA_HOME%/jre/lib/security/cacerts
Startup the CAS server
Now you are ready to startup your CAS server. Simply startup Tomcat and access CAS with https://localhost:8443/cas-web/login You should see the CAS login screen and no errors in your catalina logs.
Startup Liferay and Configure #
Startup the portal and when the homepage loads up hit the login link. If all goes well you should be redirected to the CAS server's login screen.
Next steps #
If the above test worked, you already have a CAS server installed and integrated with Liferay. The next steps are more related to properly configuring the CAS server than with Liferay. That's out of the scope of this article but we'll give a very brief summary.
By integrating the CAS server, Liferay is no longer responsible for authenticating the users, it just trusts that the CAS server authenticates them properly. The CAS server has configurable strategies for authenticating users. So far the default one has been used, which just authenticates the user if the user and password are the same. That's completely unsecure so other options need to be considered before installing in a production environment. Some reasonable options would be:
- To authenticate with LDAP: The CAS server includes an authentication handler for LDAP. You can read about it in http://www.ja-sig.org/products/cas/server/ldapauthhandler/index.html or http://www.ja-sig.org/wiki/display/CASUM/LDAP. If this option is chosen it is recommended that you also configure Liferay to authenticate against LDAP using the instructions in: LDAP. Then you'll need to provide some way to synchronize the users between LDAP and Liferay's database. Two options are:
- Set up the automatic importer (see LDAP, available since v4.2)
- To authenticate with the portal's database: It is possible to develop your own CAS authentication handler that uses the information present in Liferay's database. One way of doing this would be using Liferay's services to authenticate the user.
- To authenticate against another user store: in this case you'll also need to write your own CAS authentication handler and also provide Liferay some way to add the user entries in its own database.
Some other steps that you might want to follow are:
- Modify the look and feel of the CAS server pages to match those provided by the portal: http://www.ja-sig.org/products/cas/server/views/index.html
- Clustering: http://www.ja-sig.org/products/cas/server/cluster/index.html
- Set up real certificates
Also, check the references at the end of the article for more information.
If you have the following error when you introduce user and password in CAS page:
[ERROR] CASReceipt - edu.yale.its.tp.cas.client.CASAuthenticationException: Unable to validate ProxyTicketValidator [ERROR] CASFilter - edu.yale.its.tp.cas.client.CASAuthenticationException: Unable to validate ProxyTicketValidator ERROR [CASFilter:148] javax.servlet.ServletException: Unable to validate ProxyTicketValidator javax.servlet.ServletException: Unable to validate ProxyTicketValidator
The problem is the digital certificate. You must check the version of JVM that Tomcat uses, you can see that in the log when you type startup to start Tomcat, and you must export the digital certificate in the cacerts of that JVM.
Note: By default in Windows Liferay uses its JVM that you can find in %LIFERAY_HOME%\tomcatxx\jre1.5_17, so you must export the digital certificate in %LIFERAY_HOME%\tomcatxx\jre1.5_17\win\lib\security\cacerts
If you created a cert with the %FILE_NAME%, you'll probably run into problems. Here are 2 commands to delete the tomcat alias from the keystore so you can start fresh:
keytool -delete -alias tomcat -keystore %JAVA_HOME%/jre/lib/security/cacerts keytool -delete -alias tomcat -file server.cert
- You may not be able to get https://localhost:8443/cas up and running after the cert key generation. If so, skip the test and try it after you've finished all the steps. If you can't login at that point, you've probably generated your cert incorrectly.
- I've had problems with certs on IE7, make sure you try it out on Firefox and Opera.
- Your certificate must be trusted. If you created a self-signed certificate, you must add it to your truststore. I mistakenly thought I could define the truststore settings on my Tomcat SSL Connector. That didn't work because CAS was redirecting (after logging in) to a non-SSL page. Since the HTTP connector didn't know to trust the self-signed certificate, I got the 'sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target' error. My solution was to follow the guidelines in the JSSE Reference Guide and define the truststore in the JAVA_OPTS (-Djavax.net.ssl.trustStore=/path/to/custom/truststore). I created both a custom keystore (needed by the SSL Connector and specified either in the Connector config or the JAVA_OPTS) and custom truststore.
- Lifecast: CAS Setup - Integrate Liferay Portal with a CAS server to access multiple applications with a single sign on.
- A short article regarding CAS, Active Directory and an example : http://www-128.ibm.com/developerworks/web/library/wa-singlesign/