Spring @PathVariable Head-slapper
August 12th, 2010
A simple oversight in the documentation and potentially unnecessary default in the Spring @PathVariable annotation can cause runtime trouble.
This article will demonstrate how to integrate OpenSSO/OpenAM with Liferay Portal to achieve single-signon.
Liferay Portal and OpenSSO both require a minimum 1.5 JVM, but I would recommend using Java 6 (as Java 1.5 reached its End of Service Life in October, 2009). Make sure that your JAVA_HOME
environment variable is correctly set to point to your Java 6 installation.
For OpenSSO to work correctly with Liferay Portal, both servers need to be running in the same domain. To solve this issue while running both servers on a single machine, edit the hosts file (/etc/hosts
or %SystemRoot%system32driversetc
) and add/update your localhost entry: 127.0.0.1 localhost localhost.example.com
where example.com
is your actual domain.
Install Liferay Portal Liferay Portal is an open source portal. Liferay comes in two editions, Enterprise Edition (EE) and Community Edition (CE). For a full discussion on the differences, see this. Downloads are available here. For this article, I used Liferay Portal 5.2.3 CE bundled with Tomcat 6.0 (6.0.18).
Installation consisted of:
Unzip liferay-portal-tomcat-6.0-5.2.3.zip
to a directory. This will create a liferay-portal-5.2.3
folder.
chmod +x *.sh
liferay-portal-5.2.3/tomcat-6.0.18/bin/
, executing startup.sh
(or startup.bat
) will start Tomcat, and deploy Liferay Portal.http://localhost.example.com:8080
, and you will see the Liferay login page. You can login with test@liferay.com/test
.Install OpenSSO/OpenAM OpenSSO is an open source access management and federation server platform. Announced by Sun Microsystems in July 2005, OpenSSO was based on Sun Java System Access Manager, and was the core of Sun’s commercial access management and federation product, OpenSSO Enterprise (formerly Sun Access Manager and Sun Federation Manager). Oracle completed their acquisition of Sun Microsystems in February 2010 and announced that OpenSSO would no longer be their strategic product. OpenSSO will continue to be developed and supported by ForgeRock under the name of OpenAM (see this).
I downloaded the latest OpenAM build (OpenAM Snapshot 9.5.1 RC1) from here. For consistency, I will refer to OpenSSO as OpenAM for the remainder of this article.
As OpenAM also requires a servlet container, I downloaded the latest Tomcat (6.0.29) from here. Installation of the Tomcat server consisted of:
apache-tomcat-6.0.29 zip
file. This will create an apache-tomcat-6.0.29
folder.As both Liferay Portal and OpenAM will be running on the same machine, I needed to update the ports that the OpenAM Tomcat server was using.
apache-tomcat-6.0.29/conf/server.xml
. I changed all of the ports from 8xxx
to 9xxx
. For example, 8080
to 9080
, 8443
to 9443
, etc.chmod +x *.sh
catalina.sh
(or catalina.bat
) and add the following line to the start of the file, after the comment block listing the various Environment Variable Prequisites: Linux/MacOS: JAVA_OPTS="$JAVA_OPTS -Xmx1024m -XX:MaxPermSize=256m"
Windows: set JAVA_OPTS="%JAVA_OPTS% -Xmx1024m -XX:MaxPermSize=256m"
Installation of OpenAM consisted of:
openam_snapshot_951RC1.zip
to a directory. This will create an opensso
folder.opensso.war
from opensso/deployable-war/
to apache-tomcat-6.0.29/webapps/
.In apache-tomcat-6.0.29/bin/
, execute startup.sh
(or startup.bat
) to start Tomcat and deploy OpenAM.
apache-tomcat-6.0.29/webapps/opensso
.http://localhost.example.com:9080/opensso
, which should redirect you to http://localhost.example.com:9080/opensso/config/options.htm
, to complete the OpenAM configuration.You should see the OpenAM configuration options page. Under Custom Configuration click Create New Configuration. Enter the following:
~/opensso
(or c:Documents and Settings{username}opensso
).When this completes, in the Configuration Complete dialog, click Proceed to Login, which should now redirect you to http://localhost.example.com:9080/opensso/UI/Login
. Type amAdmin as the username, password as the password, and click Log In. You should now see the OpenAM Console.
opensso.war
file from apache-tomcat-6.0.29/webapps/
directory.Additional OpenAM Configuration To get OpenAM to work correctly with Liferay, you need to set Encode Cookie Value to Yes. This will prevent infinite redirection between Liferay and OpenAM on login.
Other people have reported having to set the com.iplanet.am.cookie.c66Encode
property to true as well, to resolve the infinite redirection problem:
com.iplanet.am.cookie.c66Encode
property, and set the value to true.Before updating Liferay to use OpenAM, I recommend adding the default Liferay user, test@liferay.com, to OpenAM.
/ (Top Level Realm)
realm.Setup the default Liferay user:
test@liferay.com
for the Email Address, and click Save.Integrate Liferay Portal with OpenAM Now you are ready to update Liferay Portal to integrate with OpenAM for authentication.
bin/shutdown
).liferay-portal-5.2.3/tomcat-6.0.18/webapps/ROOT/WEB-INF/classes/
.open.sso.auth.enabled=true open.sso.login.url= http://localhost.example.com:9080/opensso/UI/Login?goto= http://localhost.example.com:8080/c/portal/login open.sso.logout.url= http://localhost.example.com:9080/opensso/UI/Logout?goto= http://localhost.example.com:8080/web/guest/home open.sso.service.url=http://localhost.example.com:9080/opensso open.sso.screen.name.attr=uid open.sso.email.address.attr=mail open.sso.first.name.attr=givenname open.sso.last.name.attr=sn
bin/startup
).http://localhost.example.com/8080
, and you should be redirected to the OpenAM login page (http://localhost.example.com:9080/opensso/UI/Login
). Enter joebloggs for the User Name, and password for the Password. Click Log In.You will be authenticated against OpenAM, and redirected to Liferay.
Now that Liferay is using OpenAM for authentication, if you create a new user in OpenAM, that user will also be created in Liferay on the first log in. That newly created user in Liferay will only have the basic information filled in - First Name, Last Name, Screenname, Email Address - and will have the default Roles, Groups, and Organizations assigned.
This article demonstrated a basic integration with OpenAM and Liferay Portal. Now you are ready to explore more advanced topics include configuring OpenAM to use an existing LDAP or other user datastore, creating a custom datastore plugin (e.g. JDBC) for OpenAM, setting up a separate realm for Liferay users, as well as taking advantage of OpenAM for incoming and outbound SSO in conjuction with Liferay Portal. Enjoy!
A simple oversight in the documentation and potentially unnecessary default in the Spring @PathVariable annotation can cause runtime trouble.
A quick trip through some examples of how to define, find, and ultimately use annotations to get work done on diverse classes.
The Mac has some nice tools to turn your jar file into a first class Mac application. This is most useful if the application has a GUI interface; Swing, SWT, etc. There are three parts to this process: Package your application as a jar file Create an…
Steve has over 16 years of professional experience. During his career, he has led the design, development, implementation and support of enterprise solutions utilizing a simple, pragmatic approach and agile methodologies. He has experience in many industries including online retail, healthcare, business travel, government and manufacturing.