我在我的localhost上运行了openldap,我正在尝试从我的spring应用程序更改用户帐户密码,但我得到的是Exception。
请帮忙。
org.springframework.security.authentication.BadCredentialsException: Authentication for password change failed.
at org.springframework.security.ldap.userdetails.LdapUserDetailsManager$3.executeWithContext(LdapUserDetailsManager.java:204) ~[spring-security-ldap-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:817) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.executeReadWrite(LdapTemplate.java:812) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.security.ldap.userdetails.LdapUserDetailsManager.changePassword(LdapUserDetailsManager.java:191) ~[spring-security-ldap-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at com.atulsia.controller.UserController.getTemplate(UserController.java:417) ~[classes/:na]
at com.atulsia.controller.UserController.getAllUsers(UserController.java:437) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
代码:
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://localhost:389");
contextSource.setUserDn("cn=Anil Pawar,cn=mts,ou=mm,dc=example,dc=com");
contextSource.setPassword("123456");
try {
contextSource.afterPropertiesSet();
} catch (Exception ex) {
ex.printStackTrace();
}
LdapTemplate template = new LdapTemplate();
template.setContextSource(contextSource);
LdapUserDetailsManager ldapUserDetailsManager = new LdapUserDetailsManager(template.getContextSource());
ldapUserDetailsManager.changePassword("123456", "111111");