java 修改ad密码,用Java更改AD用户过期密码

I'm using JNDI to change LDAP user's password. In most cases (when user's password isn't expired) this code works just fine:

public InitialLdapContext connect(String url, String securityPrincipal, String password) throws AuthenticationException, NamingException {

System.setProperty("javax.net.ssl.trustStore", truststore);

Properties env = new Properties();

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL, url);

env.put(Context.SECURITY_PRINCIPAL, "EE\\" + securityPrincipal);

env.put(Context.SECURITY_CREDENTIALS, password);

env.put(Context.SECURITY_PROTOCOL, "ssl");

env.put("java.naming.ldap.version", "3");

env.put(Context.REFERRAL, "follow");

return new InitialLdapContext(env,null);

}

But when user with expired password tries to change it my app throws:

Exception: javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 773, v1db1 ]

com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3041)

com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2987)

com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2789)

com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2703)

com.sun.jndi.ldap.LdapCtx.(LdapCtx.java:293)

com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)

com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)

com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)

com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)

So my question is: Is it possible to change LDAP expired passwords? If it's possible, then tell how.

Thanx for help!

解决方案

The problem was resolved by creating Super User in Ad, which has rights to change every AD password. And when AD user password is expired, then the Super User changes his password.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值