<dependency>
<groupId>com.atlassian.crowd.client</groupId>
<artifactId>atlassian-crowd-rest-client</artifactId>
<version>1.1</version>
</dependency>
In your java code:
- import com.atlassian.crowd.embedded.api.PasswordCredential;
- import com.atlassian.crowd.exception.ApplicationPermissionException;
- import com.atlassian.crowd.exception.GroupNotFoundException;
- import com.atlassian.crowd.exception.InvalidAuthenticationException;
- import com.atlassian.crowd.exception.OperationFailedException;
- import com.atlassian.crowd.model.user.*;
- import com.atlassian.crowd.exception.UserNotFoundException;
- import com.atlassian.crowd.service.client.CrowdClient;
- import com.atlassian.crowd.integration.rest.service.factory.RestCrowdClientFactory;
- import com.atlassian.crowd.service.client.ClientPropertiesImpl;
- import com.atlassian.crowd.service.client.ClientResourceLocator;
public static int registerNewUser(String userName, String emailAddress, String password) {
//your crowd server settings String url = "http://auth.staging.company.com/crowd/";//crowd base url String applicationName = "appincrowd"; String applicationPass = "apppassword"; String groupName = "usergroup";//a user group under the app CrowdClient client = new RestCrowdClientFactory().newInstance(url, applicationName, applicationPass); //initialze crowd client UserTemplate ut = new UserTemplate(userName); ut.setActive(true);//make it active ut.setEmailAddress(emailAddress); ut.setName(userName); PasswordCredential p = new PasswordCredential(password, false); client.addUser(ut, p); client.addUserToGroup(userName, groupName);//now add user to that group
}
Setting Crowd configuration with properties :
Instead of hard-coded crowd configuration we should read them from a properties file:
Properties crowdProp=//properties from your bean ClientPropertiesImpl newCrowdClient=ClientPropertiesImpl.newInstanceFromProperties(crowdProp); CrowdClient client = new RestCrowdClientFactory().newInstance(newCrowdClient);
No comments:
Post a Comment