针对LDAP验证weblogic安全领域用户失败

时间:2012-12-04 23:06:50

标签: ldap weblogic openldap ldap-query ldapconnection

我安装了weblogic '10 .3.4.0'并创建了一个域business,并在默认安全域businessuser中创建了一个用户myrealm。验证者是weblogic中的DefaultAuthenticator。现在,我想使用LDAP在我的独立Java应用程序中验证用户。我也尝试过更改LDAP凭据。执行应用程序后,系统正在响应以下错误:javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]

代码:

Properties l_props = new Properties();
LdapContext l_ctx = null;
l_props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
l_props.put(Context.PROVIDER_URL, "ldap://localhost:7001");
l_props.put(Context.SECURITY_AUTHENTICATION, "simple");
l_props.put(Context.SECURITY_PRINCIPAL, "cn=username");
l_props.put(Context.SECURITY_CREDENTIALS, "password");
l_ctx = new InitialLdapContext(l_props, null);

错误:

javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
    at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3041)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2987)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2789)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2703)
    at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:293)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
    at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
    at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.init(InitialContext.java:223)
    at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:134)
    at com.iflex.fcat.misc.TestLDAP.createInitialLdapContext(TestLDAP.java:258)
    at com.iflex.fcat.misc.TestLDAP.authenticate(TestLDAP.java:170)
    at com.iflex.fcat.misc.TestLDAP.main(TestLDAP.java:125)

1 个答案:

答案 0 :(得分:1)

试试这个:

package br.com.cliente.projeto;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;


public class Autenticacao
{
  @SuppressWarnings({ "unchecked", "deprecation" })
public static void main(String args[])
  {

      String username = "jstein";  
      String password = "welcome1";  

      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); 
      env.put(Context.SECURITY_PRINCIPAL, username);
      env.put(Context.SECURITY_CREDENTIALS, password);
      env.put(Context.PROVIDER_URL, "t3://10.19.2.99:7001");
      try {  
          InitialContext ctx = new InitialContext(env);
          System.out.println("Autenticado");  
      } catch (Exception e) {  
          e.printStackTrace();  
      }  

  }
}
相关问题