Announcement Announcement Module
Collapse
No announcement yet.
how to change password of Activity Directory by Spring-LDAP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to change password of Activity Directory by Spring-LDAP

    I want to change AD user's password by using Spring-LDAP,
    but i get a Exception , i don't know why,Can anyone tell the solution,Thanks

    org.springframework.ldap.UncategorizedLdapExceptio n: Operation failed; nested exception is javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000001F: SvcErr: DSID-031A0FBC, problem 5003 (WILL_NOT_PERFORM), data 0

    My code is:

    public class ObjectDaoTest extends
    AbstractTransactionalDataSourceSpringContextTests {

    private LdapTemplate ldapTemplate;

    protected String[] getConfigLocations() {
    return new String[] { "applicationContext.xml" };
    }

    public void setObjectDao(LdapTemplate ldapTemplate) {
    this.ldapTemplate = ldapTemplate;
    }

    public void testLdap() throws UnsupportedEncodingException {

    String oldpass = this.encodePassword("aaa");

    String newpass = this.encodePassword("Padsllds12221211");

    Attribute oldattr = new BasicAttribute("unicodePwd", "aaa");
    Attribute newattr = new BasicAttribute("unicodePwd", newpass);

    ModificationItem olditem = new ModificationItem(
    DirContext.REMOVE_ATTRIBUTE, oldattr);

    ModificationItem newitem = new ModificationItem(
    DirContext.ADD_ATTRIBUTE, newattr);

    ModificationItem repitem = new ModificationItem(
    DirContext.REPLACE_ATTRIBUTE, newattr);

    ModificationItem[] mods = new ModificationItem[2];
    mods[0] = olditem;
    mods[1] = newitem;

    // ldapTemplate.modifyAttributes("cn=administrator,cn =Users", mods);

    ldapTemplate.modifyAttributes("cn=aaa,cn=Users",
    new ModificationItem[] { repitem });
    }

    private String encodePassword(String password) {

    String quotedPassword = "\"" + password + "\"";
    char unicodePwd[] = quotedPassword.toCharArray();
    byte pwdArray[] = new byte[unicodePwd.length * 2];

    for (int i = 0; i < unicodePwd.length; i++) {
    pwdArray[i * 2 + 1] = (byte) (unicodePwd[i] >>> 8);
    pwdArray[i * 2 + 0] = (byte) (unicodePwd[i] & 0xff);
    }

    return new String(pwdArray);
    }
    }

    // applicationContext.xml
    <bean id="contextSource" class="org.springframework.ldap.support.LdapContex tSource">
    <property name="url" value="ldap://192.168.1.5:389" />
    <property name="base" value="DC=demo,DC=local" />
    <property name="userName" value="CN=administrator,CN=Users,DC=demo,DC=local" />
    <property name="password" value="Password1234" />
    </bean>

    <bean id="ldapTemplate" class="org.springframework.ldap.LdapTemplate">
    <constructor-arg ref="contextSource" />
    </bean>

  • #2
    I think you need an SSL connection in order to change passwords in AD. Your URL should look something like this:

    Code:
    <property name="url" value="ldaps://192.168.1.5:636" />

    Comment


    • #3
      Thanks

      I hava found the way by SSL

      Comment

      Working...
      X