AppFuse provides a sweet starting point for developing web applications. You choose the frameworks, AppFuse generates the skeleton application.
At its core, the web security of AppFuse 2.0.2+ applications relies on the modular and extensible Spring Security authentication framework. In this tutorial, we look at a basic integration of Crowd with Spring Security, using an application generated by AppFuse.
Step 1. Get AppFuse
In this tutorial, we will be using the Struts2-basic archetype to create the project, but the other types should be similar. For more information, consult the AppFuse quickstart guide. In particular, it outlines the database requirements for AppFuse.
- Create the project.
- Since we will be editing the core Spring Security configuration, we will need the full source code of the application.
- Build it.
- Run it.
- Play with it.
- Shut it down.
Step 2. Let Crowd Know about AppFuse
appfuse as an application via the Crowd Console. See Adding an Application for more information.
Step 3. Add the Crowd Spring Security Connector to AppFuse
Open up the
pom.xml and add the Crowd client libraries as a project dependency:
You will also need to create the file
In particular, the application name and password must match the values defined for the application added in Step 2.
Finally, copy the
myproject/src/main/resources/crowd-ehcache.xml. This file defines the cache properties, such as cache timeouts, used when accessing data from the Crowd server.
Step 4. Hook Up Centralised Authentication
Before modifying the security configuration, you will need to add the Spring configuration file to wire up the Crowd client beans. Add the
applicationContext-CrowdClient.xml configuration file to the list of
AppFuse neatly stores all the Spring Security configuration in
myproject/src/main/webapp/WEB-INF/security.xml. In order to get centralised authentication, we will need to set up Spring Security to use Crowd components for user information. Edit the beans in
- Add the definition of the CrowdUserDetailsService:
- Add the definition of the RemoteCrowdAuthenticationProvider that delegates Spring Security authentication requests to Crowd:
- Comment out the default authentication provider, as we've replaced it with Crowd:
- Now do a:
- Head over to
You should now be able to authenticate the users in your Crowd repository that meet all of the following conditions:
- They are in a Crowd directory assigned to the AppFuse application in Crowd. See more information.
- They are in Crowd groups named
ADMIN. You will need to add these groups and assign the user as a member of the groups. These Crowd group names map to the Spring Security authorisation roles defined in the AppFuse application.
- They are allowed to authenticate with the AppFuse application because EITHER they are in a group allowed to authenticate with Crowd (click for details) OR their container directory allows all users to authenticate (click for details).
Congratulations. You have centralised authentication
Step 5. Hook Up Single Sign-On
Enabling single sign-on (SSO) requires quite a bit more tweaking of the
- Remove defaults from the
- Remove the
auto-configattribute and add an
entry-point-ref="crowdAuthenticationProcessingFilterEntryPoint"attribute to the http element.
- Remove the
You should end up with an http element similar to this:
- Remove the
- Change the default processing filter to Crowd's SSO filter by adding the following bean definitions:
- Add the definition of the CrowdLogoutHandler and add in a LogoutFilter that references it:
- Now repeat:
SSO will only work for users that are able to authenticate with both appplications and are authorised to use both applications. Try out the following:
- Log in to Crowd – you should be logged in to AppFuse.
- Log out of AppFuse – you should be logged out of Crowd.
- Log in to AppFuse; log out of Crowd; log in to Crowd as another user; refresh AppFuse – you should be logged in as the new user.
Congratulations, you have SSO