2011-08-25 100 views
1

憑據無效這些是我現在用的是進口:LDAPException:無效憑證(49)使用Grails

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

,我試圖這樣做,我發現了一個很簡單的密碼驗證的:

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

我似乎無法得到綁定工作。有沒有人有更好的方式來做到這一點與Grails或Java。我發現自己真的迷失了,任何例子或指導都會有所幫助。

謝謝。

+0

這些都不是插件,它們是進口。你在使用插件嗎? –

+0

你的權利,我的不好。我正在使用gldapo插件,然後切換到這些導入。對不起,混在一起 – xander528

回答

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; 
     } 
    } 
    } 
} 
+0

感謝您的留言。今天早上我和一位同事解決了我的問題。在放入主機文件時,我正在放入整個ldap網址,在那裏我應該放置網址 – xander528