1

我已经安装了 weblogic '10.3.4.0' 并创建了一个域并在默认安全领域business创建了一个用户。身份验证器与 weblogic 中的一样。现在,我想在我的独立 java 应用程序中使用 LDAP 对用户进行身份验证。我也尝试过更改 LDAP 凭据。执行应用程序后,系统响应以下错误:。businessusermyrealmDefaultAuthenticatorjavax.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)
4

1 回答 1

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();  
      }  

  }
}
于 2014-02-24T17:43:41.620 回答