Documentation for Crowd 2.3. Documentation for other versions of Crowd is available too.
Crowd provides centralised authentication and single sign-on connectors for the web security framework Spring Security. Spring Security provides a modular and highly configurable approach to authentication and authorisation for J2EE applications.
If your web application already makes use of the Spring Security framework for authentication and authorisation, you can use the Crowd Spring Security connector to allow your application to easily delegate authentication and authorisation requests to Crowd.
Spring, Acegi and Crowd versions
Spring Security was formerly known as Acegi. There is a separate tutorial for integrating Acegi with Crowd.The connector is available with Crowd 1.6 and later and has been developed and tested with Spring Security 2.0.4. We have not yet developed a tutorial for use with Spring 3.x. If you are interested, please watch and/or vote for CWD-1807.
Please consult the Spring Security suggested steps or reference guide for a thorough insight into the Spring Security framework. You might also find useful information in our Appfuse integration tutorial.
This guide assumes developer-level knowledge and a Spring Security-based web application
This guide is for developers rather than administrators. This guide assumes you have Crowd 1.6 or later installed and that you want to integrate your Spring Security-based web application with Crowd's security server. The documentation below describes how to integrate Crowd with your own application that uses the Spring Security framework. It assumes you already use Spring Security in your application. If you need help integrating the Spring Security framework with your web application, have look at some of the Spring Security documentation.
CROWD
.Crowd needs to be aware that SpringSecApp will be making authentication requests to Crowd. In brief, you will need to do the following:
Please see Adding an Application for a detailed guide.
You will need to add the Crowd Spring Security connector library and its associated dependencies to your Spring Security application. You can do this manually by copying over the JAR files to your Spring Security application or, if your Spring Security application is a Maven project, you can add the Crowd Spring Security connector as a project dependency. Both methods are described below.
Follow either 2.1.1 or 2.1.2 (not both).
Copy the Crowd integration libraries and configuration files. This is described in the Client Configuration documentation. You will need to copy at least the following file to your Spring Security application:
Copy From |
Copy To |
---|---|
CROWD/client/crowd-integration-client-X.X.X.jar |
SpringSecApp/WEB-INF/lib |
CROWD/client/lib/*.jar |
SpringSecApp/WEB-INF/lib |
Follow either 2.1.1 or 2.1.2 (not both).
See more information on Maven 2 integration.
Copy the following file into your application's classpath:
Copy From |
Copy To |
---|---|
CROWD/client/conf/crowd-ehcache.xml |
SpringSecApp/WEB-INF/classes/crowd-ehcache.xml |
This file can be tweaked to change the cache behaviour.
The Crowd Spring Security connector needs to be configured with the details of the Crowd server.
crowd.properties
file to the classpath of your Spring Security application:
Copy From |
Copy To |
---|---|
CROWD/client/conf/crowd.properties |
SpringSecApp/WEB-INF/classes |
crowd.properties
and populate the following fields appropriately:
Key |
Value |
---|---|
application.name |
Same as application name defined when adding the application to Crowd in Step 1. |
application.password |
Same as application password defined when adding the application to Crowd in Step 1. |
crowd.server.url |
|
session.validationinterval |
This is the time interval between requests which validate whether the user is logged in or out of the Crowd SSO server. Set to 0, if you want authentication checks to occur on each request. Otherwise set to the number of minutes you wish to wait between requests. Setting this value to 1 or higher will increase the performance of Crowd's integration. |
You can read more about the crowd.properties file.
There are two ways you can integrate your application with Crowd:
First, you will need to add the Crowd client application context to wire up the Crowd beans that manage the communication to Crowd. You can do this by including the applicationContext-CrowdClient.xml
Spring configuration file, found in crowd-integration-client.jar
. For example, if you are configuring Spring using a context listener, you can add the following parameter in your your Spring Security application's WEB-INF/web.xml
:
<context-param> <param-name>contextConfigLocation</param-name> <param-value> ... classpath:/applicationContext-CrowdClient.xml ... </param-value> </context-param>
The following sections assume that you have the Spring Security schema mapped to the security
namespace. Perform the following updates to your Spring Security configuration:
<bean id="crowdUserDetailsService" class="com.atlassian.crowd.integration.springsecurity.user.CrowdUserDetailsServiceImpl"> <property name="authenticationManager" ref="crowdAuthenticationManager"/> <property name="groupMembershipManager" ref="crowdGroupMembershipManager"/> <property name="userManager" ref="crowdUserManager"/> <property name="authorityPrefix" value="ROLE_"/> </bean>
<bean id="crowdAuthenticationProvider" class="com.atlassian.crowd.integration.springsecurity.RemoteCrowdAuthenticationProvider"> <security:custom-authentication-provider /> <constructor-arg ref="crowdAuthenticationManager"/> <constructor-arg ref="httpAuthenticator"/> <constructor-arg ref="crowdUserDetailsService"/> </bean>
Further extensions
Crowd's remote API
We recommend that applications do not store the Crowd users locally. Rather, applications should query users via Crowd's remote API.
SSO is optional and requires centralised user management
Single sign-on is optional. If you wish to configure SSO you must first configure centralised user management as described in step 3.1 above.
Perform the following additional updates to your Spring Security configuration:
<http/>
element:
auto-config
attribute and add an entry-point-ref="crowdAuthenticationProcessingFilterEntryPoint"
attribute to the http element.<form-login>
element.<http lowercase-comparisons="false" entry-point-ref="crowdAuthenticationProcessingFilterEntryPoint"> <!-- note: no auto-config attribute! --> <!--intercept-url pattern="/images/*" filters="none"/> <intercept-url pattern="/styles/*" filters="none"/> <intercept-url pattern="/scripts/*" filters="none"/--> <intercept-url pattern="/admin/*" access="ROLE_ADMIN"/> <intercept-url pattern="/passwordHint.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> <intercept-url pattern="/signup.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> <intercept-url pattern="/a4j.res/*.html*" access="ROLE_ANONYMOUS,ROLE_ADMIN,ROLE_USER"/> <!-- APF-737, OK to remove line below if you're not using JSF --> <intercept-url pattern="/**/*.html*" access="ROLE_ADMIN,ROLE_USER"/> <!-- <form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?error=true" login-processing-url="/j_security_check"/> --> <remember-me user-service-ref="userDao" key="e37f4b31-0c45-11dd-bd0b-0800200c9a66"/> </http>
<authentication-manager alias="authenticationManager"/> <beans:bean id="crowdAuthenticationProcessingFilterEntryPoint" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint"> <beans:property name="loginFormUrl" value="/login.jsp"/> </beans:bean> <beans:bean id="crowdAuthenticationProcessingFilter" class="com.atlassian.crowd.integration.springsecurity.CrowdSSOAuthenticationProcessingFilter"> <custom-filter position="AUTHENTICATION_PROCESSING_FILTER"/> <beans:property name="httpAuthenticator" ref="httpAuthenticator"/> <beans:property name="authenticationManager" ref="authenticationManager"/> <beans:property name="authenticationFailureUrl" value="/login.jsp?error=true"/> <beans:property name="defaultTargetUrl" value="/"/> <beans:property name="filterProcessesUrl" value="/j_security_check"/> </beans:bean>
<beans:bean id="crowdLogoutHandler" class="com.atlassian.crowd.integration.springsecurity.CrowdLogoutHandler"> <beans:property name="httpAuthenticator" ref="httpAuthenticator"/> </beans:bean> <beans:bean id="logoutFilter" class="org.springframework.security.ui.logout.LogoutFilter"> <custom-filter position="LOGOUT_FILTER"/> <beans:constructor-arg value="/index.jsp"/> <beans:constructor-arg> <beans:list> <beans:ref bean="crowdLogoutHandler"/> <beans:bean class="org.springframework.security.ui.logout.SecurityContextLogoutHandler"/> </beans:list> </beans:constructor-arg> <beans:property name="filterProcessesUrl" value="/logout.jsp"/> </beans:bean>
Bounce your application. You should now have centralised authentication and single sign-on with Crowd.
For the purposes of Crowd integration with Spring Security, you should map Spring Security's roles to Crowd's groups. To put it another way: in order to use Spring Security's authorisation features, users in Crowd will have their Spring Security roles specified by their group names.
For example if user 'admin' is in the 'crowd-admin' group, then the user 'admin' will be authorised to view pages restricted to the 'crowd-admin' role in Spring Security.
<!-- authorisation --> <bean id="filterInvocationInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor"> <property name="authenticationManager" ref="authenticationManager"/> <property name="accessDecisionManager" ref="accessDecisionManager"/> <property name="objectDefinitionSource"> <value> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON PATTERN_TYPE_APACHE_ANT /console/secure/**=ROLE_crowd-admin /console/user/**=IS_AUTHENTICATED_FULLY </value> </property> </bean> <bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased"> <property name="allowIfAllAbstainDecisions" value="false"/> <property name="decisionVoters"> <list> <bean class="org.springframework.security.vote.RoleVoter"/> <bean class="org.springframework.security.vote.AuthenticatedVoter"/> </list> </property> </bean>