exception - java access ldap server once the ldap server has been restarted

724 Views Asked by At

I have the next problem, I get a context from the LDAP setting Up JNDI Environment properties for the InitialContext as it showed below. Then I restart the ldap server, and each time I try to get again the InitialContext, the next exception is thrown.

Code to get the Context.

  Context ctx = null;

  Hashtable ht = new Hashtable();
  ht.put(Context.INITIAL_CONTEXT_FACTORY,
         "weblogic.jndi.WLInitialContextFactory");
  ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
  ht.put(Context.SECURITY_PRINCIPAL,"USER1");
  ht.put(Context.CREDENTIALS,"PASSWORD1");
  try {
    ctx = new InitialContext(ht);
  }
  catch (NamingException e) {
  }
  finally {
    try {ctx.close();
  }
  catch (Exception e) {
      // a failure occurred
  }
  }

Exception:

  java.security.PrivilegedActionException: javax.naming.ConfigurationException: Call to NamingManager.getObjectInstance() failed:
[Root exception is java.lang.SecurityException:
[Security:090398]Invalid Subject: principals=[ADMIN]]; remaining name ''
BEA-090398
1

There are 1 best solutions below

0
On

You are not providing a proper DN to authenticate with:

ht.put(Context.SECURITY_PRINCIPAL,"USER1");

You should have cn=user1,ou=something,dc=something,dc=com or the like.