LDAP + Java Aplication身份验证错误代码49-52e [英] LDAP + Java Aplication Authentication error code 49 - 52e

查看:652
本文介绍了LDAP + Java Aplication身份验证错误代码49-52e的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有问题.我想对一个应用程序进行身份验证,但是我遇到过同样的问题.

I have a problem with my code. I want to do the authentication for one application and I have the same problem ever.

我有ldap服务器的URL.以及LDAP中用户的用户名和密码.现在,向我们展示我使用的类:

I have the URL of the ldap server. And the username and password of the users in LDAP. Now I show us the Class that I use:

public final class ldapAuth {

    private String usuario;
    private String clave;
    private String servidor;
    private String dn;
    private String tipoAuth;
    private boolean autenticado;

    DirContext dc;

    /**
     * Constructor de la conexion con el Motor de LDAP
     *
     * @param server  Servidor en donde se encuentra el LDAP
     * @param dn      Directoria del arbol del LDAP
     * @param ta      Tipo de Autenticacion
     * @param usuario Usuario que desea realizar la conexion
     * @param clave   Clave del usuario
     *
     */
    public ldapAuth(String server, String dn, String ta,String usuario,String clave) {
        this.servidor = server;
        this.dn = dn;
        this.tipoAuth = ta;
        this.usuario=usuario;
        this.clave=clave;
        inicializarConexion();
    }

    public void inicializarConexion() {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, servidor);
        env.put(Context.SECURITY_AUTHENTICATION, tipoAuth);
        env.put(Context.SECURITY_PRINCIPAL, dn);
        env.put(Context.SECURITY_CREDENTIALS, clave);

        try {
            dc = new InitialDirContext(env);
            setAutenticado(true);
        } catch (NamingException ex) {
            System.out.println("Error Autenticando mediante LDAP, Error causado por : " + ex.toString());
            setAutenticado(false);
        }
    }

    /**
     * Retorna el Atributo de la conexion con LDAP actual
     * 
     * @param atributo Nombre del Atributo que se desea obtener
     * @return Attribute con la informacion correspondiente
     */

    public Attribute cargarPropiedadConexion(String atributo) {
        Attribute propiedad = null;

        try {
            Attributes attrs = dc.getAttributes(dn);

            if (attrs == null) {
                propiedad = null;
            } else {
                propiedad = attrs.get(atributo);
            }
        } catch (Exception e) {
            propiedad = null;
        }
        return propiedad;
    }


    /*Get's y Set's*/
    public boolean isAutenticado() {
        return autenticado;
    }
    public void setAutenticado(boolean autenticado) {
        this.autenticado = autenticado;
    }
    public String getUsuario() {
        return usuario;
    }
    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }
}

现在,我向我们展示调用此功能的主要代码:

Now I show us the main code that call this functions:

import javax.naming.NamingException;
import javax.naming.directory.Attribute;


public class main {

    public static void main(String[] args) throws NamingException{
        System.out.println("Iniciando Autenticacion");

        String server="ldap://10.201.69.xxx"; // servidor de LDAP
        String usuario="CN =user, OU=Generic Users,OU=Ofimatica, OU=User Organizations, DC=mycompany, DC=vwg; // Usuario de Autenticacion
        String dn="ou=users,ou=ofimatica,ou=user organizations,dc=mycompany,dc=vwg"; // Ruta del Arbol LDAP
        String tipoAth="simple";//tipo de autentuicacion simple o por SSL
        String clave="mypassword";

        ldapAuth ldapAuth=new ldapAuth(server,dn,tipoAth,usuario,clave);

        if(ldapAuth.isAutenticado()){
            System.out.println("Usuario "+ldapAuth.getUsuario()+" Autenticado Correctamente");


        }
        else{
            System.out.println("Usuario "+ldapAuth.getUsuario()+" No se Puedo Autenticar");
        }
    }
}

执行时,我看到错误代码49数据52e,我在Google上对其进行了搜索,并看到它是通过无效的凭据显示的,因此我不知道如何解决此问题.

When I execute I see the error code 49 data 52e, I google it and I see that it by invalid credentials so I don't understand how to solve this.

稍后我进行了一些更改,如果退出了用户名和密码,则错误不会显示出来.

Later I make some changes and if I quit the User and Password the error doesn't show it.

谢谢:)

推荐答案

您没有为绑定帐户提供正确的凭据.您的DC不允许匿名LDAP查找.因此,您需要提供凭据才能传递请求.我们必须提供诸如domainShortName \ administrator密码之类的内容.否则,您可以将DC配置为允许匿名LDAP绑定.

Your not providing the correct credentials for the binding account. Your DC does not allow anonymous LDAP look ups. So you need to provide credentials to pass the request. we had to provide something like domainShortName\administrator password etc. Or you could configure your DC to allow anonymous LDAP binding.

这篇关于LDAP + Java Aplication身份验证错误代码49-52e的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆