【发布时间】:2011-08-10 13:50:32
【问题描述】:
以下是我的代码:
private DirContext createContext() {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.springframework.ldap.core.support.LdapContextSource");
env.put(Context.PROVIDER_URL, "ldap://FAKESERV.fakedom:389/");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "fakeuser@fakedom");
env.put(Context.SECURITY_CREDENTIALS, "1qaz!QAZ");
try {
return new InitialDirContext(env);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
它工作正常,但我应该使用 xml 配置。
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://FAKESERV.fakedom:389/"/>
<property name="base" value="ou=FAKESERV.fakedom"/>
<property name="userDn" value="uid=fakeuser@fakedom"/>
<property name="password" value="1qaz!QAZ"/>
<property name="contextFactory" value="com.sun.jndi.ldap.LdapCtxFactory"/>
</bean>
使用ldapTemplate.getContextSource().getReadOnlyContext()
我有 525 错误 - “找不到用户”。如何修改这个xml?
server: FAKESERV
fomain: fakedom
user: fakeuser
url: ldap://FAKESERV.fakedom:389/
Active Directory 中的所有属性都是默认的。
另外,我如何执行 ldap 请求来搜索某些用户?
更新: 现在我使用了 impl。对于 ActiveDirectory:
<bean id="authenticationToken" class="org.springframework.security.authentication.UsernamePasswordAuthenticationToken">
<constructor-arg value="fakeuser@fakedom" />
<constructor-arg value="1qaz!QAZ" />
</bean>
<bean id="authenticationProvider"
class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
<constructor-arg value="fakedom" />
<constructor-arg value="ldap://FAKESERV.fakedom:389/" />
</bean>
没问题,谢谢。
现在我尝试将 ldap-request 发送到服务器...
【问题讨论】:
标签: java spring active-directory ldap