2013-05-02 31 views
0

嗨朋友,在GWT中使用LDAP的簡單登錄屏幕

我必須在GWT中使用LDAP進行簡單的登錄認證。 我已經完成了Java.But我不知道在GWT中實現相同。 幫助我,如果有人知道...
我粘貼在這裏我的Java源代碼在這裏:

package com.ldap.test; 
import java.util.*; 
import javax.naming.*; 
import javax.naming.directory.*; 
public class ldaptest { 

    @SuppressWarnings("unchecked") 
    public static void main(String[] args) { 

     try { 
      @SuppressWarnings("rawtypes") 
      Hashtable env = new Hashtable(); 
      env.put(Context.INITIAL_CONTEXT_FACTORY, 
        "com.sun.jndi.ldap.LdapCtxFactory"); 
      env.put(Context.PROVIDER_URL, 
        "LDAP://localhost:389"); //replace with your server URL/IP 
        //only DIGEST-MD5 works with our Windows Active Directory 
      env.put(Context.SECURITY_AUTHENTICATION, 
        "Simple"); //No other SALS worked with me 
      env.put(Context.SECURITY_PRINCIPAL, 
        "uid=karthick,ou=users,ou=system"); // specify the username ONLY to let Microsoft Happy 
      env.put(Context.SECURITY_CREDENTIALS, "karthick"); //the password 

      DirContext ctx = new InitialDirContext(env); 

      ctx.close(); 
    enter code here 
      } catch(NamingException ne) { 
      System.out.println("Error authenticating user:"); 
      System.out.println(ne.getMessage()); 
      return; 
     } 

      //if no exception, the user is already authenticated. 
      System.out.println("OK, successfully authenticating user"); 
     } 

} 

// samething我在GWT做..

+2

您必須將其公開爲[遠程servlet服務](https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC)並從您的GWT代碼中使用它 – shyam 2013-05-02 11:58:53

回答

1

實現一個遠程的servlet服務,通過在客戶端側上的異步回調傳遞用戶名和憑證給服務。上面的代碼可以作爲實現工作。