I'm using Spring Ldap to interact with my openLdap server which needs tls authentication. In order to authenticate I had to set the contextSource like:
TransactionAwareContextSourceProxy ctx = (TransactionAwareContextSourceProxy) ldapTemplate.getContextSource();
SecureLdapContextSource secureContextSource = new SecureLdapContextSource();
secureContextSource.afterPropertiesSet();
ldapTemplate.setContextSource(secureContextSource);
Where is SecureLdapContextSource
public void afterPropertiesSet() {
//http://forum.spring.io/forum/spring-projects/data/ldap/33910-ldaps-external-certificate-contains-unsupported-critical-extensions-2-5-29-17
this.setUrl("ldaps://myLdapServer.com:636/");
super.afterPropertiesSet();
Hashtable<String, Object> envProps = new Hashtable<String, Object>();
envProps.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
envProps.put(Context.PROVIDER_URL, "ldaps://myLdapServer.com:636/");
envProps.put(Context.SECURITY_PRINCIPAL, "adminUsername");
envProps.put(Context.SECURITY_CREDENTIALS, "adminPwd");
envProps.put(Context.SECURITY_AUTHENTICATION, "simple");
envProps.put("java.naming.security.protocol", "ssl");
envProps.put("com.sun.jndi.ldap.connect.pool", "true");
envProps.put("java.naming.ldap.factory.socket", "org.springframework.ldap.samples.useradmin.EmblSSLSocketFactory");
System.setProperty("java.naming.ldap.factory.socket", "org.springframework.ldap.samples.useradmin.EmblSSLSocketFactory");
//set the environment
super.setupAuthenticatedEnvironment(envProps, keyStore, keyStorePassword);
// set the base environment again
super.setBaseEnvironmentProperties(envProps);
System.setProperty("javax.net.ssl.keyStore", keyStore);
System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
// it is necessary to call super.afterPropertiesSet() again!!!
super.afterPropertiesSet();
}
After that I've been able to authenticate the admin with such call:
ldapTemplate.authenticate(queryAdmin, password);
After that comes my problem. I want to delete a user from the ldap with the unbind method: ldapTemplate.unbind("dnOfMyWorsteColeague");
Running it on a test I get the following exception from the ldap server: [LDAP: error code 8 - modifications require authentication]
So, I cannot (as I'm doing with my old ldap interface, w/o Spring Ldap) do an authentication and keep the session to execute commands that only the admin is allowed to do.
Any idea? I'd like to use Spring Ldap for that...
Thanks for any help, Marco