I have managed this with the Tomcat's SSO Valve:
Put SSO Valve within Host (localhost) element of server.xml
file:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true"> <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> </Host>
Add users and roles (eg. in tomcat_users.xml
):
<user username="user1" password="user1" roles="employee"/>
In web-app
element of your app's web.xml
file, add security constraints:
<security-constraint> <web-resource-collection> <web-resource-name>App name</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>employee</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>FORM</auth-method> <realm-name>file</realm-name> <form-login-config> <form-login-page>/login.jsp</form-login-page> <form-error-page>/error.jsp</form-error-page> </form-login-config> </login-config> <security-role> <role-name>employee</role-name> </security-role>
That's it. Now, log in to the one of your apps, and you should be logged in to other apps.
Of course, you should not use a plain text password in the production, this is just a quick example. You shoud consider Digest authentication, as well as configuring SSL on Tomcat.
I hope this will help someone!
P.S. if you store users in the SQL database, please check my comment below this answer.