LDAP密码修改_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > LDAP密码修改

LDAP密码修改

 2013/10/2 0:55:54  songxh2  程序员俱乐部  我要评论(0)
  • 摘要://LDAP密码修改finalStringhost="192.168.1.101";finalintport=389;finalLDAPConnectionFactoryfactory=newLDAPConnectionFactory(host,port);Connectionconnection=null;try{connection=factory.getConnection();//checkSupportedExtendedOperations(connection)
  • 标签:
class="java" name="code">
//LDAP密码修改

final String host = "192.168.1.101";
final int port = 389;

final LDAPConnectionFactory factory = new LDAPConnectionFactory(host, port);
Connection connection = null;

try {
    connection = factory.getConnection();
    
    //checkSupportedExtendedOperations(connection);
    extendedOperations=RootDSE.readRootDSE(connection).getSupportedExtendedOperations();

    final String ladpAdmin = "cn=Directory Manager";
    final char[] ladpAdminPassword = "xerllent".toCharArray();
    connection.bind(ladpAdmin, ladpAdminPassword);

    // Uncomment a method to run one of the examples.

    // For a Cancel Extended request, see the SearchAsync example.
    //usePasswordModifyExtendedRequest(connection);
        if (extendedOperations != null && !extendedOperations.isEmpty() && extendedOperations.contains(PasswordModifyExtendedRequest.OID)) {

            //final String userIdentity = "uid=test3,ou=People,dc=example,dc=com"; //通过
            final String userIdentity = "u:test3"; //通过
            //final String userIdentity = "uid:test3"; //错误写法
            final char[] oldPassword = "test3".toCharArray();
            final char[] newPassword = "test3".toCharArray();

            final PasswordModifyExtendedRequest ldaprequest =
                    Requests.newPasswordModifyExtendedRequest()
                        .setUserIdentity(userIdentity)
                        .setOldPassword(oldPassword)
                        .setNewPassword(newPassword);

            final PasswordModifyExtendedResult result = connection.extendedRequest(ldaprequest);
            if (result.isSuccess()) {
                System.out.println("Changed password for " + userIdentity);
            } else {
                System.err.println(result.getDiagnosticMessage());
            }
        } else {
            System.err.println("PasswordModifyExtendedRequest not supported");
        }


} catch (ErrorResultException e) {
    System.err.println(e.getMessage());
    System.exit(e.getResult().getResultCode().intValue());
    return;
} finally {
    if (connection != null) {
        connection.close();
    }
}



--------------------------------------------------------------------------
Changed password for uid=test3,ou=People,dc=example,dc=com
Changed password for u:test3
Protocol Error: 无法处理密码修改扩展请求,因为它包含无效的 userIdentity 字段。提供的 userIdentity 字符串为 "uid:test3"
上一篇: 关于技术经验的几点感悟 下一篇: 没有下一篇了!
  • 相关文章
发表评论
用户名: 匿名