Announcement Announcement Module
No announcement yet.
how to add Active user from Ldap.. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to add Active user from Ldap..

    i try to adding new user account from spring ldap in AD.
    i facing a problem my new added user account authenticated when i try to login
    i want to set userAcountControl value 512normal account,no passwd Exp) but fail i addd userAcountControl=544 now

    i having a problem in userpassword it may be not setting or i unable to set it please can any One tell me whats going wrong in my code

    public void insertContact(ContactDTO contactDTO) {
    		Attributes personAttributes = new BasicAttributes();
    		BasicAttribute personBasicAttribute = new BasicAttribute("objectclass");
    //		personBasicAttribute.add("person");
    		personAttributes.put("givenName", contactDTO.getCommonName());
    		personAttributes.put("cn", contactDTO.getCommonName());
    		personAttributes.put("sn", contactDTO.getLastName());
    		personAttributes.put("description", contactDTO.getDescription());
    	        personAttributes.put("userPassword", "{SHA}" + this.encrypt(contactDTO.getPassword()));
    	//	personAttributes.put("userPassword", contactDTO.getPassword());
    		// personAttributes.put("unicodepwd", this.encodePassword(contactDTO.getPassword()) );
    		personAttributes.put("userPrincipalName", contactDTO.getUserLoginName());
    		personAttributes.put("sAMAccountName", contactDTO.getsAMAccountName());
    		personAttributes.put("displayname", contactDTO.getDisplayname());
    	personAttributes.put("userAccountControl", "544");
    		BasicAttribute roomAttribute = new BasicAttribute("roomNumber");
    		for(String r : contactDTO.getRoomNumber())
    		DistinguishedName newContactDN = new DistinguishedName();
    		newContactDN.add("cn", contactDTO.getCommonName());
    		ldapTemplate.bind(newContactDN, null, personAttributes);
    // my encode method 
    private byte[] encodePassword(String password) throws UnsupportedEncodingException {
    			String newQuotedPassword = "\"" + password + "\"";
    			return newQuotedPassword.getBytes("UTF-16LE");
    // encryption method
     private String encrypt(final String plaintext) {
    	        MessageDigest md = null;
    	        try {
    	            md = MessageDigest.getInstance("SHA");
    	        } catch (NoSuchAlgorithmException e) {
    	            throw new RuntimeException(e.getMessage());
    	        try {
    	        } catch (UnsupportedEncodingException e) {
    	            throw new RuntimeException(e.getMessage());
    	        byte raw[] = md.digest();
    	        String hash = (new BASE64Encoder()).encode(raw);
    	        return hash;

    if i add userPassword as a text or with encrypt it add successfully but not allow me to loin (error invalid username passwd from login to system or ldap unable to authenticate error code 49),

    but if i use unicodepwd below error occur
    org.springframework.ldap.UncategorizedLdapException: Operation failed; nested exception is javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000052D: SvcErr: DSID-031A11E5, problem 5003 (WILL_NOT_PERFORM), data 0
    please can any one tell me which One i use to save user Password and how to do.
    waiting for response
    Last edited by Noman sadiq; Nov 30th, 2010, 05:08 AM.