Skip to main content

LdapContext with ActiveDirectory

No replies
trouby
Offline
Joined: 2006-02-27

Hi

I have written in Java SE code that connects to ActiveDirectory and it works fine when I run it standalone,

Here's the code:
-----------------------------------
Hashtable 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,"ldaps://myAdIP:636");
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
System.setProperty("javax.net.ssl.keyStore","c:/keystore");
System.setProperty("javax.net.ssl.trustStore", "c:/keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
env.put(Context.SECURITY_PRINCIPAL,"CN=Administrator,CN=Users,DC=myad,DC=com");
env.put(Context.SECURITY_CREDENTIALS,"mypassword");
try {
LdapContext ctx = new InitialLdapContext(env,null);
System.out.println("Got LdapContext!");
}
catch (Exception e) {
e.printStackTrace();
}
----------------------------------------

When the code is being executed by GF I get errors such as "Caused by: java.net.SocketException: Default SSL context init failed: Keystore was tampered with, or password was incorrect" or sometimes that the keystore was not found at all,

I'm almost sure that all of the System.setProperty calls has no effects,
An example is when I try to add 'System.setProperty("javax.net.debug", "all");' I do not see debug messages in server log.

What is wrong? Is it possible to use System.setProperty when executing server side code? or maybe GF makes some other initializations when 'InitialLdapContext' object is initialized?

Thanks a lot,

Asaf.