【问题标题】:Spring ldap: creating connectionSpring ldap:创建连接
【发布时间】: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


    【解决方案1】:

    Spring 安全性现在提供到 LDAP/AD 的连接。但是您可以尝试的一件事是设置:

    com.sun.jndi.ldap.LdapCtxFactory
    

    作为Context.INITIAL_CONTEXT_FACTORY

    InitialLdapContext 作为上下文连接吗?

    Hashtable env = new Hashtable();
    
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    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 InitialLdapContext(env, null);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    

    如果可以的话,那就是配置有问题。

    Good reading with examples.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 2022-01-25
      • 2015-01-17
      • 2011-07-12
      • 2016-04-13
      • 2015-01-18
      相关资源
      最近更新 更多