簡體   English   中英

LDAPException:無效的憑證(49)帶有grails的無效的憑證

[英]LDAPException: Invalid Credentials (49) Invalid Credentials with grails

這些是我正在使用的導入:

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

並且我正在嘗試做一個非常簡單的密碼驗證,該驗證在以下位置找到:

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

而且我似乎無法使綁定工作。 沒有人有使用grails或java的更好方法。 我發現自己真的迷路了,任何示例或指導都將有所幫助。

謝謝。

此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;
        }
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM