Documentation for Crowd 1.0. Documentation for other versions of Crowd is available too.

This page provides sample code for creating a Crowd Client using the supplied Java Integration Libraries.

SecurityServerClient

The SecurityServerClient is useful for common create, update and delete operations for principals, groups and roles. To accomplish this, the SecurityServerClient maps 1-to-1 with the SOAP API of the Crowd server. The class works by first reading in the crowd.properties configuration file from your application's class path, once the crowd.properties configuration values have been parsed. The client will then authenticate the application with the Crowd security server for future SOAP requests.

A full list of the available methods for the SecurityServerClient is available here:

HttpAuthenticator

The HttpAuthenticator simplifies the authentication of HTTP based clients. When an authentication or invalidation is performed, the HttpAuthenticator manages the setting and resetting of integration variables for the principal's HTTP session. If the application has little need beyond authentication and validation, the HttpAuthenticator is a simple and very straightforward integration piece. Shown below is a code example of authenticating and logging off a principal:

Example 1:

HttpAuthenticator.authenticate(request, response, username, password);

Example 2:

HttpAuthenticator.authenticate(request, response);

If there were any issues with the authentication or logoff calls, an Exception will be thrown to the application.

The HttpAuthenticator manages the following:

  • Authenticating an HTTP request, and setting the session with the correct attributes for other integration points of the IDX framework.
  • Invalidating an HTTP request includes removing session related attributes.
  • Obtaining a principal's authenticated token from a session or browser cookie.
  • Validating an existing HTTP authentication for single sign-on. If another application in the same domain has already authenticated the principal, the HttpAuthenticator will attempt to validate the existing authentication.
  • Building a standard AuthenticationContext for a principal. This can be used to assure the authentication is consistent across all applications when setting validation factors of the application client.

VerifyTokenFilter

The VerifyTokenFilter is an HTTP servlet filter that protects secured resources by verifying the session or cookie token is active and the principal has access to the requesting application. The token filter works in conjunction with the HttpAuthenticator validating and setting various session and cookie attributes. Should the principal's token become expired or invalid due to security restrictions, the principal will be redirected to the URL provided by the crowd.properties.

Using the token filter is very straight forward, simply edit your web.xml deployment descriptor to reflect the filter and desired resource mapping:

<filter>
    <filter-name>VerifyTokenFilter</filter-name>
    <filter-class>com.atlassian.crowd.integration.http.VerifyTokenFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>VerifyTokenFilter</filter-name>
    <url-pattern>/secure/*</url-pattern>
</filter-mapping>

In this example, the verify token filter will prevent any pages on the /secure/ path from being accessed unless a valid token is found.

Should the token expire or be found invalid, the original URL will be stored in the principal's session at a String with the key of VerifyTokenFilter.ORIGINAL_URL. This is useful because, when the principal later authenticates, the original URL and parameters can then be used as a redirect bringing the principal back to their original POST. An example of how this can be accomplished at login is shown below:

HttpAuthenticator.authenticate(request, response, username, password);

// Check if principal was requesting a page that was prevented, if so, redirect.
String requestingPage = (String) getSession().getAttribute(VerifyTokenFilter.ORIGINAL_URL);

if (requestingPage != null) {
    // redirect the principal to the requesting page
    response().sendRedirect(requestingPage);

} else {
    // return the to the login page
    return SUCCESS;
}


Related Topics  

Crowd 1.0 Documentation  

  • No labels

1 Comment

  1. Anonymous

    Example 2 method should be logoff.