标签: spring-ldap

Spring LDAP - 绑定成功连接

我正在尝试进行身份验证,然后使用Spring LDAP和Spring安全性查询我们的公司LDAP.我设法使身份验证工作,但当我尝试运行搜索时,我总是得到以下异常

为了执行此操作,必须在连接上完成成功绑定

经过大量研究后,我得到了一个理论,即在我进行身份验证之后,在我可以查询之前,我需要绑定到连接.我只是不知道是什么以及如何?

提一下 - 我可以使用JXplorer成功浏览和搜索我们的LDAP,所以我的参数是正确的.

这是我的securityContext.xml的一部分

<security:http auto-config='true'>
    <security:intercept-url pattern="/reports/goodbye.html" 
            access="ROLE_LOGOUT" />
    <security:intercept-url pattern="/reports/**" access="ROLE_USER" />
    <security:http-basic />
    <security:logout logout-url="/reports/logout" 
            logout-success-url="/reports/goodbye.html" />
</security:http>
<security:ldap-server url="ldap://s140.foo.com:1389/dc=td,dc=foo,dc=com" />
<security:authentication-manager>
    <security:authentication-provider ref="ldapAuthProvider">
</security:authentication-provider>
</security:authentication-manager>
<!-- Security beans -->
<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldap://s140.foo.com:1389/dc=td,dc=foo,dc=com" />
</bean>
<bean id="ldapAuthProvider" 
   class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
        <bean class="foo.bar.reporting.server.security.ldap.LdapAuthenticatorImpl">
            <property name="contextFactory" ref="contextSource" />
            <property name="principalPrefix" value="TD\" />
            <property name="employee" ref="employee"></property>
        </bean>
    </constructor-arg>
    <constructor-arg>
      <bean class="foo.bar.reporting.server.security.ldap.LdapAuthoritiesPopulator" />
    </constructor-arg>
</bean>
<!-- DAOs -->
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
  <constructor-arg ref="contextSource" />
Run Code Online (Sandbox Code Playgroud)

LdapAuthenticatorImpl …

bind ldap spring-security spring-ldap

7
推荐指数
1
解决办法
3万
查看次数

尝试使用Spring LDAP进行编码

我正在尝试使用Spring LDAP进行编码

<ldap-server ldif="classpath:my-ldap-clone.ldif" />
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个错误

NoClassDefFoundError: org/apache/directory/server/core/DirectoryService
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

java spring spring-security spring-ldap apacheds

7
推荐指数
3
解决办法
6333
查看次数

Spring 3.1 LDAP身份验证过程:凭据"良好"时出现"错误凭据"消息

Spring 3.1 Tomcat 6.*

我正在制作一个Spring 3.1 webapp,用LDAP进行身份验证.

我使用我编写的JNDI样式的Java程序测试了LDAP凭据(用户名,密码,ldap URL,搜索模式)(引用如下).该程序工作,转储所有用户属性,包括密码,似乎在LDAP服务器上加密.

当我尝试在Spring 3.1中使用相同的凭据登录时,我收到错误消息"Bad Credentials".

我在日志中收到此消息:

DEBUG [org.springframework.security.authentication.ProviderManager:authenticate] (ProviderManager.java:152) - Authentication attempt using org.springframework.security.ldap.authentication.LdapAuthenticationProvider
DEBUG [org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider:authenticate] (AbstractLdapAuthenticationProvider.java:51) - Processing authentication request for user: John.A.Smith
DEBUG [org.springframework.security.ldap.authentication.BindAuthenticator:bindWithDn] (BindAuthenticator.java:108) - Attempting to bind as uid=John.A.Smith,ou=People,o=acme.com,o=acme.com
DEBUG [org.springframework.security.ldap.DefaultSpringSecurityContextSource$1:setupEnvironment] (DefaultSpringSecurityContextSource.java:76) - Removing pooling flag for user uid=John.A.Smith,ou=People,o=acme.com,o=acme.com
DEBUG [org.springframework.security.ldap.authentication.BindAuthenticator:handleBindException] (BindAuthenticator.java:152) - Failed to bind as uid=John.A.Smith,ou=People,o=acme.gov: org.springframework.ldap.AuthenticationException: [LDAP: error code 32 - No Such Object]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 32 - No Such Object] …
Run Code Online (Sandbox Code Playgroud)

java spring-security spring-ldap

7
推荐指数
1
解决办法
2万
查看次数

Spring Security Active Directory 忽略 PartialResultException

我的 spring 安全 xml 文件中有以下配置。当我尝试进行身份验证时,我收到以下消息但无法继续。

信息:忽略 PartialResultException

我知道 spring 的文档指出您可以将 ignorePartialResultException 设置为 true ,但此属性似乎位于 LdapTemplate 类中,可能需要额外的编码。我想通过 bean 配置完成所有这些,因为我对角色映射不感兴趣。

<authentication-manager>
        <authentication-provider ref="activeDirectoryAuthProvider" />
    </authentication-manager>
    <beans:bean id="activeDirectoryAuthProvider"
        class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
        <beans:constructor-arg value="mydomain.com" />
        <beans:constructor-arg value=" ldap://mydomain.com:389" />
    </beans:bean>
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security spring-ldap

7
推荐指数
1
解决办法
1万
查看次数

Ldap查询 - 使用Spring Boot进行配置

我有一个需要执行LDAP查询的Spring启动应用程序.我试图从Spring启动文档中获取以下建议:

"许多Spring配置示例已在Internet上发布,使用XML配置.如果可能,请尽量使用等效的基于Java的配置."

在Spring XML配置文件中,我会使用:

 <ldap:context-source
          url="ldap://localhost:389"
          base="cn=Users,dc=test,dc=local"
          username="cn=testUser"
          password="testPass" />

   <ldap:ldap-template id="ldapTemplate" />

   <bean id="personRepo" class="com.llpf.ldap.PersonRepoImpl">
      <property name="ldapTemplate" ref="ldapTemplate" />
   </bean>
Run Code Online (Sandbox Code Playgroud)

我如何使用基于Java的配置来配置它?我需要能够在没有代码重建的情况下更改ldap:context-source的URL,base,username和password属性.

spring-ldap spring-boot

7
推荐指数
1
解决办法
1万
查看次数

为什么Spring LDAP的LdapTemplate不会返回标题,部门和公司属性?

我使用spring-ldap-core-2.3.1.RELEASE.jarJDK 1.8Tomcat 8.0通过访问AD信息LdapTemplate.属性如title,department&company不被返回的ldapTemplate.search(..,.,..)方法.

我正在使用以下代码行进行搜索: -

LdapQuery ldapQuery = LdapQueryBuilder.query()
                                       .where("objectclass").is("user")
                                       .and("objectcategory").is("person")
                                       .and("cn").like(strWildcardText+"*");
ldapTemplate.search(ldapQuery, new ADUserAttributesMapper());
Run Code Online (Sandbox Code Playgroud)

以下是ADUserAttributesMapper班级: -

public class ADUserAttributesMapper implements AttributesMapper<ADUserBean> {
    @Override
    public ADUserBean mapFromAttributes(Attributes attributes) throws NamingException {
        if(attributes==null) {
            return null;
        }

        adUserBean.setName((attributes.get("name")!=null) ? attributes.get("name").get().toString() : null);
        adUserBean.setCommonName((attributes.get("cn")!=null) ? attributes.get("cn").get().toString() : null);
        adUserBean.setDisplayName((attributes.get("displayname")!=null) ? attributes.get("displayname").get().toString() : null);
        adUserBean.setGivenName((attributes.get("givenname")!=null) ? attributes.get("givenname").get().toString() : null); // for FIRST NAME
        adUserBean.setMiddleName((attributes.get("initials")!=null) ? …
Run Code Online (Sandbox Code Playgroud)

jndi spring-mvc active-directory ldap-query spring-ldap

7
推荐指数
2
解决办法
2959
查看次数

为什么SpringLDAP /普通Java AD查询中的accountExpires和userAccountControl过滤器不能按预期工作?

我使用的SpringLDAPAPI基于web应用的弹簧内查询在Windows Server 2012上承载的ActiveDirectory下面是我的环境信息: - , Java 1.8.0_101,&apache-tomcat-8.0.36SpringMVC 4.3.1SpringLDAP 2.3.1

以下AD筛选器查询在基于Windows(基于C++/C#)的查询工具(例如,Lepide AD查询工具)中获取匹配帐户,并且还在eclipse IDE中的LDAP浏览器插件中提取,但是当获取匹配的记录/ AD帐户时在Java(基于JNDI/SpringLDAP API)代码中以及在基于Java的应用程序JXplorer中使用: -

(&(objectclass=user)(objectCategory=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(accountExpires>=131554368000000000)(userPrincipalName=cgm@*))
Run Code Online (Sandbox Code Playgroud)

我正在尝试获取一个活动的用户帐户,但是在给定日期并且userPrincipalName以字符串开头的值时尚未过期cgm@.

以下是spring-servlet.xml文件中的ldap配置: -

<util:map id="ldapBaseEnvProps">
        <entry key="java.naming.ldap.attributes.binary" value="objectGUID"/>
</util:map>
<ldap:context-source id="pooledLdapContextSrc" url="ldap://dc.myadserver.com:3268" base="DC=myadserver,DC=com" username="CN=adusername,OU=Mkt-Managers,DC=myadserver,DC=com" password="*****" base-env-props-ref="ldapBaseEnvProps">
    <ldap:pooling max-total="16" max-active="16" max-idle="8" min-idle="0" max-wait="90000" when-exhausted="BLOCK" test-on-borrow="true" test-while-idle="true"/>
</ldap:context-source>
Run Code Online (Sandbox Code Playgroud)

Java/SpringLDAP API是否支持这样的AD过滤器?如果是,需要更改上述AD查询过滤器才能在基于Java的代码中工作(获取匹配的AD帐户)?

java jndi spring-mvc active-directory spring-ldap

7
推荐指数
1
解决办法
376
查看次数

Spring Boot 测试:@TestPropertySource 未覆盖 @EnableAutoConfiguration

我正在使用 Spring Data LDAP 从 LDAP 服务器获取用户数据。

我的文件结构如下所示:

main
  java
    com.test.ldap
      Application.java
      Person.java
      PersonRepository.java
  resources
    application.yml
    schema.ldif

test
  java
    Tests.java
  resources
    test.yml
    test_schema.ldif
Run Code Online (Sandbox Code Playgroud)

这是我的测试课:

import com.test.ldap.Person;
import com.test.ldap.PersonRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {PersonRepository.class})
@TestPropertySource(locations = "classpath:test.yml")
@EnableAutoConfiguration
public class Tests {

    @Autowired
    private PersonRepository personRepository;

    @Test
    public void testGetPersonByLastName() {
        List<Person> names = personRepository.getPersonNamesByLastName("Bachman");
        assert(names.size() > 0);
    }

}
Run Code Online (Sandbox Code Playgroud)

问题是,Spring Boot 正在加载application.ymlschema.ldif …

java spring spring-ldap spring-boot

7
推荐指数
2
解决办法
1万
查看次数

在不支持PagedResultsControl的LDAP服务器上进行分页

我正在尝试使用Spring LDAP(版本2.3.2)获取LDAP服务器上的所有条目.在我的代码中,我使用了PagedResultsDirContextProcessor对所有结果进行分页.这在支持的服务器上工作正常PagedResultsControl.

但是,我现在需要连接到不支持的LDAP服务器PagedResultsControl.如何在不使用的情况下获取所有条目PagedResultsControl

java jndi ldap ldap-query spring-ldap

7
推荐指数
1
解决办法
430
查看次数

springframework ldap核心问题与java模块

主java模块有这种问题。

rg.springframework.beans.factory.BeanCreationException:创建类路径资源中定义的名为“ldapContextSource”的bean时出错[org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.class]:通过工厂方法实例化Bean失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.ldap.core.support.LdapContextSource]:工厂方法“ldapContextSource”抛出异常;嵌套异常是java.lang.IllegalAccessError:类org.springframework.ldap.core.support.AbstractContextSource(在模块spring.ldap.core中)无法访问类com.sun.jndi.ldap.LdapCtxFactory(在模块java.naming中),因为模块 java.naming 不会将 com.sun.jndi.ldap 导出到模块 spring.ldap.core
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.context@5.2.2.RELEASE/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.2.RELEASE.jar:na]
    在 spring.context@5.2.2.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.2.RELEASE.jar:na]
    在 spring.boot@2.2.2.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.2.RELEASE.jar:na]
    在 spring.boot@2.2.2.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.2.RELEASE.jar:na]
    在 spring.boot@2.2.2.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.2.RELEASE.jar:na]
    在 spring.boot@2.2.2.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.2.RELEASE.jar:na]
    在 app/com.test.app.App.main(App.java:9) ~[classes/:na]
引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.ldap.core.support.LdapContextSource]:工厂方法“ldapContextSource”抛出异常;嵌套异常是java.lang.IllegalAccessError:类org.springframework.ldap.core.support.AbstractContextSource(在模块spring.ldap.core中)无法访问类com.sun.jndi.ldap.LdapCtxFactory(在模块java.naming中),因为模块 java.naming 不会将 com.sun.jndi.ldap 导出到模块 spring.ldap.core
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.2.RELEASE.jar:na]
    在 spring.beans@5.2.2.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.2.2.RELEASE.jar:na]
    ... 17个常用帧省略
引起:java.lang.IllegalAccessError:类org.springframework.ldap.core.support.AbstractContextSource(在模块spring.ldap.core中)无法访问类com.sun.jndi.ldap.LdapCtxFactory(在模块java.naming中),因为模块 java.naming 不会将 …

java ldap spring-ldap java-module java-11

7
推荐指数
1
解决办法
1万
查看次数