2011-12-14 24 views
7

Sto cercando di far sì che la mia applicazione java personalizzata utilizzi il nostro server Active Directory per l'autenticazione, ma non riesco a farlo funzionare per qualche motivo. Qualcuno può vedere perché questo è? Ecco il mio metodo di seguito:Problema di autenticazione ldap Java

private boolean authenticate(String serverName, String userId, String password) throws NamingException { 
    DirContext ctx = null; 
    Hashtable env = new Hashtable(11); 
    boolean b = false; 
    try { 
     env.put(Context.INITIAL_CONTEXT_FACTORY, 
     "com.sun.jndi.ldap.LdapCtxFactory"); 
     env.put(Context.PROVIDER_URL, "ldap://servername.org:389"); 
     env.put(Context.SECURITY_AUTHENTICATION, "simple"); 
     env.put(Context.SECURITY_PRINCIPAL, "uid="+ userId +",ou=All Users,dc=site,dc=org"); 
     env.put(Context.SECURITY_CREDENTIALS, password); 
     System.out.println("before context"); 
     // If there isn't a naming exception then the user is authenticated. Return true 
     ctx = new InitialDirContext(env); 
     //The user is authenticated. 
     b = true; 
    } catch (NamingException e) { 
     System.out.println("the user is not authenticated return false"); 
     b = false; 
    }finally{ 
     if(ctx != null) 
      ctx.close(); 
    } 
    return b; 
} 

Risultato:

[12/14/11 16:27:47:746 CST] 0000001f SystemErr  R 
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece 
+1

cosa succede? puoi pubblicare una traccia dello stack? –

+0

Ricevo un codice di errore ldap 49 che è un errore di autenticazione. Tuttavia, le credenziali che sto fornendo sono corrette. Sono in grado di accedere al mio computer Windows e ad altri server con esso. – bschupbach

+0

il tuo ldap richiede la crittografia? usi specifici parametri di connessione, che potresti trovare importanti da condividere? Altrimenti è solo una supposizione. – hovanessyan

risposta

4

Hai provato in questo modo?

//... 
env.put(Context.SECURITY_PRINCIPAL, "cn="+ userId +",ou=All Users,dc=site,dc=org"); 
//... 

sostituire anche

Hashtable env = new Hashtable(11); 

con

Hashtable env = new Hashtable(); 
+1

Grazie !! Questo ha fatto il trucco ... Sapevo che doveva essere qualcosa di semplice. – bschupbach

Problemi correlati