Showing posts with label atlassian-crowd. Show all posts
Showing posts with label atlassian-crowd. Show all posts

Getting rid of "LDAP: error code 53 - 0000001F: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0" in Crowd

While adding new user in crowd this error may appear when you accidently attempt to create new user in Active Directory(LDAP).

INFO: [LDAP: error code 53 - 0000001F: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0
]; nested exception is javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000001F: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0
]; remaining name 'cn=newtestuser,cn=users,dc=vantage,dc=com'


Solution :
If you dont want to add new user in Active Directory then you can:
Remove 'Add User' permission from Active directory in your crowd application settings:
1) Goto Aplications list in crowd server.
2) Select your application..
3)Select Permissions tab.
4)Select Active directory from the list of directories in your application.
5)Uncheck Add User.
6) Click Update.
Make sure you have other directories in the list with 'Add User' permission.

Crowd : Getting all users removing duplicates in an application using Crowd REST java client

  1. //your crowd server settings
  2. String url = "http://auth.staging.company.com/crowd/";//crowd base url
  3. String applicationName = "appincrowd";
  4. String applicationPass = "apppassword";
  5. String groupName = "usergroup";//a user group under the app
  6. CrowdClient client = new RestCrowdClientFactory().newInstance(url, applicationName, applicationPass);
  7. //initialze crowd client

  1. //a single user can be more than one group,so let's remove duplicate users by using Set
  2.         Set<CrowdUser> allCrowdUsers = new HashSet<>();
  3.         List<String> newGroupList = client.searchGroupNames(NullRestrictionImpl.INSTANCE, 0, maxGroupSearchResult);
  4.         //get all users in a single list
  5.         for (String currGroupName : newGroupList) {
  6.             List<User> currGroupUsers = client.getUsersOfGroup(currGroupName, 0, maxUserSearchResult);
  7.             for (User grpUser : currGroupUsers) {
  8.                 allCrowdUsers.add(new CrowdUser(grpUser));
  9.             }
  10.         }
  11.         //traverse the all users list
  12.         for (User usr : allCrowdUsers) {
  13.             System.out.println(usr.getName() + " " + usr.getFirstName() + " " + usr.getLastName() + " (" + usr.getEmailAddress() + ")");
  14.         }
Output:
  1. //john cooper (cooper@company.com)
  2. //sam peters (sam@company.com)
  3. //...............................
  4. //Istiak Ahmad (iask@company.com)
Extended crowd user class:
CrowdUser.java:
  1. import com.atlassian.crowd.model.user.User;
  2. import com.atlassian.crowd.model.user.UserTemplate;
  3. /**
  4. *Extend user with overridden equals() and hashCode() method according to user email address so that we can build a collection(Set<>) with no different users with same email address
  5. *
  6. */
  7. public class CrowdUser extends UserTemplate {
  8.     public CrowdUser(User user) {
  9.         super(user);
  10.     }
  11.     /**
  12.      compare only user email address
  13.      */
  14.     @Override
  15.     public boolean equals(Object object) {
  16.         boolean result = false;
  17.         if (object == null || object.getClass() != getClass()) {
  18.             result = false;
  19.         } else {
  20.             CrowdUser muser = (CrowdUser) object;
  21.             if (this.getEmailAddress().compareTo(muser.getEmailAddress()) == 0) {
  22.                 result = true;
  23.             }
  24.         }
  25.         return result;
  26.     }
  27.     // only email address
  28.     @Override
  29.     public int hashCode() {
  30.         return this.getEmailAddress().hashCode();
  31.     }
  32.     
  33. }

Creating/registering new user in Crowd with Crowd REST java client

Put the dependecy in your pom.xml

<dependency>
<groupId>com.atlassian.crowd.client</groupId>
<artifactId>atlassian-crowd-rest-client</artifactId>
<version>1.1</version>
</dependency>

In your java code:
  1. import com.atlassian.crowd.embedded.api.PasswordCredential;
  2. import com.atlassian.crowd.exception.ApplicationPermissionException;
  3. import com.atlassian.crowd.exception.GroupNotFoundException;
  4. import com.atlassian.crowd.exception.InvalidAuthenticationException;
  5. import com.atlassian.crowd.exception.OperationFailedException;
  6. import com.atlassian.crowd.model.user.*;
  7. import com.atlassian.crowd.exception.UserNotFoundException;
  8. import com.atlassian.crowd.service.client.CrowdClient;
  9. import com.atlassian.crowd.integration.rest.service.factory.RestCrowdClientFactory;
  10. import com.atlassian.crowd.service.client.ClientPropertiesImpl;
  11. 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);