【发布时间】:2015-03-30 04:21:20
【问题描述】:
我正在使用 Spring Ldap 与需要 tls 身份验证的 openLdap 服务器进行交互。为了进行身份验证,我必须将 contextSource 设置为:
TransactionAwareContextSourceProxy ctx = (TransactionAwareContextSourceProxy) ldapTemplate.getContextSource();
SecureLdapContextSource secureContextSource = new SecureLdapContextSource();
secureContextSource.afterPropertiesSet();
ldapTemplate.setContextSource(secureContextSource);
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();
}
之后我就可以通过这样的调用验证管理员身份了:
ldapTemplate.authenticate(queryAdmin, password);
然后是我的问题。我想用 unbind 方法从 ldap 中删除一个用户: ldapTemplate.unbind("dnOfMyWorsteColeague");
在测试中运行它,我从 ldap 服务器收到以下异常: [LDAP:错误代码 8 - 修改需要身份验证]
所以,我不能(就像我使用旧的 ldap 接口,没有 Spring Ldap 一样)进行身份验证并保持会话执行只有管理员才能执行的命令。
有什么想法吗?我想为此使用 Spring Ldap...
感谢您的帮助, 马可
【问题讨论】:
-
不使用 beans.xml?
-
beans.xml 是什么意思?
-
好的,我看到安东尼奥了。但是,无论 bean 以何种方式连接在一起,我仍然无法在 Ldap 上进行某些需要管理员权限的操作。使用 Spring-Ldap。
-
嗨,我试试你的代码,但告诉我 EmblSSLSocketFactory not found..确定它存在吗?
标签: ssl unbind spring-ldap