Creating a Crowd Client using Crowd Integration Libraries

Crowd ships with Java integration libraries that allow you to create a Crowd client (also known as a Crowd-connected application) with minimal effort. This page gives a small demo of a stand-alone Crowd client to help you get started with using these libraries.

Please be aware that the Java integration libraries may change between releases.

For further help and questions on Crowd development, please see answers from the community.

Creating a Crowd Client using Crowd Integration Libraries

Create an Application in Crowd Console for your Client

If you do not yet have an application defined in Crowd, go ahead and create one via the Crowd Administration Console under 'Applications'.

  • Give your application an Application Name and Password.
  • You can specify remote IP addresses that can authenticate to this application.
  • For this example, we recommend that you use a new Crowd internal directory.
  • In this application's Permissions tab, give the application permission to add new users.

Prepare your Crowd Client

Copy the files from your Crowd installation folder CROWD_INSTALL/client for your project. These are the contents from a Crowd 1.6 installation:

1
2
3
4
5
- crowd-integration-client-X.X.jar (Crowd Integration Library)
+ lib (libraries you will need to include in your CLASSPATH)
+ conf
-- crowd.properties (Settings for defining where your Crowd Server is, and what the Application you're trying to connect to is)
-- crowd-ehcache.xml (Settings for Crowd Client cache)

Modify your local copy of crowd.properties such that crowd.server.url, application.name and application.password match the URL of your Crowd server and the application name and password you just defined.

Sample Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import com.atlassian.crowd.integration.service.soap.client.SecurityServerClientFactory;
import com.atlassian.crowd.integration.service.soap.client.SecurityServerClient;
import com.atlassian.crowd.integration.authentication.PasswordCredential;
import com.atlassian.crowd.integration.soap.SOAPPrincipal;
import com.atlassian.crowd.integration.soap.SOAPAttribute;
import com.atlassian.crowd.integration.model.UserConstants;

public class CrowdClientDemo
{
    public static void main(String[] argv)
    {
        SecurityServerClient crowdClient = SecurityServerClientFactory.getSecurityServerClient();

        try
        {
            crowdClient.authenticate();
            SOAPPrincipal principal = new SOAPPrincipal("test-user");
            principal.setActive(true);
            principal.setAttributes(new SOAPAttribute[]{
                    new SOAPAttribute(UserConstants.EMAIL, "test@example.com"),
                    new SOAPAttribute("givenName","Paul"),
                    new SOAPAttribute("sn","Smith")
            });

            PasswordCredential pwd = new PasswordCredential("secret");
            crowdClient.addPrincipal(principal,pwd);
        }
        catch (Exception e)
        {
            System.err.println(e.toString());
        }
    }
}

Hints

  • The class SOAPPrincipalHelper has many helper methods you may find useful for extracting information from SOAPPrincipal objects.
  • Ensure crowd.properties and crowd-ehcache.xml are in your classpath. You can force it to use a specific location with the option java CrowdSOAPClient -Dcrowd.properties=/path/to/the/crowd.properties.

Creating a Crowd Client using AXIS 1.x

If you prefer not to use the Crowd integration libraries and want to interface via the SOAP service directly, that can be done as well. In fact, the Crowd integration libraries actually use SOAP to communicate to the Crowd Server. One practical reason why you may want to interface via SOAP directly is to avoid the possibility of updating the Crowd Client libraries if they change in the future. Please see the example in the Axis 1.x client stub generation guide that performs the same function as the above example.

Java Integration Libraries Creating a Crowd Client for your Custom Application