Foros del Web » Programación para mayores de 30 ;) » Java »

Autenticarse en el dominio con Java

Estas en el tema de Autenticarse en el dominio con Java en el foro de Java en Foros del Web. Hola a todos: Necesito saber como autenticarse en el dominio con java. Con un servidor de Dominio Windows Server 2003. Si me dicen una herramienta ...
  #1 (permalink)  
Antiguo 27/09/2006, 06:56
 
Fecha de Ingreso: junio-2004
Mensajes: 185
Antigüedad: 19 años, 11 meses
Puntos: 0
Pregunta Autenticarse en el dominio con Java

Hola a todos:

Necesito saber como autenticarse en el dominio con java. Con un servidor de Dominio Windows Server 2003.
Si me dicen una herramienta free que lo haga tambien me serviría de gran ayuda.
De todas formas para que lo sepan, intenté con este código que les pongo a continuacion pero me da este error:
Código PHP:
Naming exception javax.naming.CommunicationExceptiondominio.com:389 [Root exception is java.net.ConnectExceptionConnection timed outconnect]
Exception in thread "main" java.lang.NullPointerException
    at cu
.co.cenatav.utils.ldapfastbind.Authenticate(ldapfastbind.java:53)
    
at cu.co.cenatav.utils.fastbindclient.main(fastbindclient.java:19
Aqui les va el código:
Clase ldapfastbind
Código PHP:
/**
 * ldapfastbind.java
 * 
 * Sample JNDI application to use Active Directory LDAP_SERVER_FAST_BIND connection control
 * 
 */
 
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.naming.directory.*;
 
class 
FastBindConnectionControl implements Control {
    public 
byte[] getEncodedValue() {
            return 
null;
    }
      public 
String getID() {
        return 
"1.2.840.113556.1.4.1781";
    }
     public 
boolean isCritical() {
        return 
true;
    }
}
 
public class 
ldapfastbind {
    public 
Hashtable env null;
    public 
LdapContext ctx null;
    public 
Control[] connCtls null;
 
    public 
ldapfastbind(String ldapurl) {
        
env = new Hashtable();
        
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
        
env.put(Context.SECURITY_AUTHENTICATION,"simple");
        
env.put(Context.PROVIDER_URL,ldapurl);
                                                 
        
connCtls = new Control[] {new FastBindConnectionControl()};
 
        
//first time we initialize the context, no credentials are supplied
        //therefore it is an anonymous bind.        
 
        
try {
            
ctx = new InitialLdapContext(env,connCtls);
 
        }
        catch (
NamingException e) {
            
System.out.println("Naming exception " e);
        }
    }
    public 
boolean Authenticate(String usernameString password) {
        try {
            
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL,username);
            
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS,password);
            
ctx.reconnect(connCtls);
            
System.out.println(username " is authenticated");
            return 
true;
        }
 
        catch (
AuthenticationException e) {
            
System.out.println(username " is not authenticated");
            return 
false;
        }
        catch (
NamingException e) {
            
System.out.println(username " is not authenticated");
            return 
false;
        }
    }
    public 
void finito() {
        try {
            
ctx.close();
            
System.out.println("Context is closed");
        }
        catch (
NamingException e) {
            
System.out.println("Context close failure " e);
        }
    }

Clase fastbindclient
Código PHP:
/**
 * fastbindclient.java
 * 
 * Sample JNDI application to use LDAP_SERVER_FAST_BIND connection control
 * 
 * This is just a test harness to invoke the ldapfastbind methods
 */
 
class fastbindclient{
    public static 
void main (String[] args)    {
    
//Could also use ldaps over port 636 to protect the communication to the 
    //Active Directory domain controller. Would also need to add 
    //env.put(Context.SECURITY_PROTOCOL,"ssl") to the "server" code
    
String ldapurl "ldap://dominio.com:389";
    
boolean IsAuthenticated false;
    
ldapfastbind ctx = new ldapfastbind(ldapurl);
    
IsAuthenticated ctx.Authenticate("DOMINIO-DS\\usuario","password");
    
    
ctx.finito();
 
    }

Les agradecería mucho que me ayudara.
Salu2

Última edición por isaacrc82; 27/09/2006 a las 07:02
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:45.