【问题标题】:LDAPException: Invalid Credentials (49) Invalid Credentials with grailsLDAPException: Invalid Credentials (49) Invalid Credentials with grails
【发布时间】:2011-08-25 16:33:10
【问题描述】:

这些是我正在使用的导入:

import com.novell.ldap.*;
import java.io.UnsupportedEncodingException;

我正在尝试做一个非常简单的密码验证,我在以下位置找到:

http://developer.novell.com/documentation/samplecode/jldap_sample/index.htm

我似乎无法让绑定工作。有没有人有更好的方法用 grails 或 java 来做这件事。我发现自己真的迷路了,任何示例或指导都会有所帮助。

谢谢。

【问题讨论】:

  • 那些不是插件,它们是进口的。你在用插件吗?
  • 你是对的,我的错。我正在使用 gldapo 插件,然后我切换到这些导入。很抱歉混淆了

标签: java grails ldap bind openldap


【解决方案1】:

此 Java 示例使用 UnboundID LDAP SDK 连接并绑定到目录服务器。像这样运行它:

$ java -cp YOUR_CLASSPATH BindExample hostname port bindDn password

BindExample.java:

import com.unboundid.ldap.sdk.BindRequest;
import com.unboundid.ldap.sdk.BindResult;
import com.unboundid.ldap.sdk.Control;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.ldap.sdk.SimpleBindRequest;

public final class BindExample {

    public static void main(String... args) {
    if(args.length == 4) {
        final String hostname = args[0];
        final String dn = args[2];
        final String password = args[3];
        int port;
        LDAPConnection ldapConnection;
        try {
            port = Integer.parseInt(args[1]);
        } catch(NumberFormatException nfx) {
            System.err.println(args[1] + " is not an integer, using 389");
            port = 389;
        }
        try {
            ldapConnection =
                new LDAPConnection(hostname,port);
        } catch(final LDAPException lex) {
            System.err.println("failed to connect to "
                   + hostname + " " +
                   lex.getMessage());
            return;
        }
        try {
            final BindRequest bindRequest =
                new SimpleBindRequest(dn,password);
            BindResult bindResult = 
                ldapConnection.bind(bindRequest);
            if(bindResult.getResultCode() == ResultCode.SUCCESS) {
                System.out.println("authentication successful");
            }
            if(bindResult.hasResponseControl()) {
                Control[] controls = 
                    bindResult.getResponseControls();
                // handle response controls ...
            }
            ldapConnection.close();
        } catch(final LDAPException lex ) {
            System.err.println("bind failed");
            ldapConnection.close();
            return;
        }
    }
  }
}

【讨论】:

  • 感谢您的帖子。今天早上我和一位同事解决了我的问题。放入主机文件时,我放入了整个 ldap url,我应该只放入 url
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-04-02
  • 2017-10-18
  • 2021-07-06
  • 2013-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多