标签: spring-ldap

Spring LDA:contextSource Bean的问题

我正在编写一个使用LDAP的Spring应用程序.这是我的bean文件.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

   <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
      <property name="url" value="xxxxx:xxx" />
      <property name="base" value="ou=xxxxx,dc=xxxxxxx,dc=xxxxxx" />
      <property name="userDn" value="uid=xxxxxxx" />
      <property name="password" value="xxxxxxxx" />
   </bean>

   <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
      <constructor-arg ref="contextSource" />
   </bean>

   <bean id="helloLdap" class="a.b.c.HelloLdap">
      <property name="ldapTemplate" ref="ldapTemplate" />
   </bean>

</beans>
Run Code Online (Sandbox Code Playgroud)

这是我的bean创建代码:

ApplicationContext fac = new ClassPathXmlApplicationContext(
                "a/b/c/ldap.xml");
HelloLdap hello = (HelloLdap) fac.getBean("helloLdap");
Run Code Online (Sandbox Code Playgroud)

这是我的错误消息:

线程"main"org.springframework.beans.factory.BeanCreationException中的异常:在类路径资源[xxxxxxxxxxxx]中定义名称为'contextSource'的bean时出错:设置属性值时出错; 嵌套异常是org.springframework.beans.PropertyBatchUpdateException; 嵌套的PropertyAccessExceptions(1)是:PropertyAccessException 1:org.springframework.beans.MethodInvocationException:属性'base'抛出异常; 嵌套异常是java.lang.NoClassDefFoundError:org/apache/commons/lang/StringUtils

所以它说(最重要的)

"Property 'base' threw exception". 
Run Code Online (Sandbox Code Playgroud)

我想知道这是否是因为身份验证需要StartTLS.我没有在我的beans文件中的任何地方指示StartTLS身份验证,因此可能导致错误.不过,我希望在创建bean 之后,而不是在创建bean期间进行身份验证.

有谁知道这是不是原因(StartTLS authenticaton)?如果没有,任何想法我在我的XML中做错了什么?

谢谢,ktm

java xml spring ldap spring-ldap

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

Spring/LDAP - 在bean配置中调用setter方法

我正在编写Spring LDAP应用程序,我必须为ContextSource设置身份验证策略.我想在我的bean XML文件中执行此操作.在为好的ContextSource JavaDoc的说,它有一个叫做setter方法

setAuthenticationStrategy(
    DirContextAuthenticationStrategy authenticationStrategy
)
Run Code Online (Sandbox Code Playgroud)

要从我的beans文件调用此setter,以下XML是否足够?

<bean id="authStrategy"
    class="org.springframework...DefaultTlsDirContextAuthenticationStrategy">
 ...
</bean>

<bean id="contextSource"
    class="org.springframework.ldap.core.support.LdapContextSource">

    <property name="url" ... />
    <property name="base" ... />
     ...
    <property name="authenticationStrategy" ref="authStrategy" /> 
</bean>
Run Code Online (Sandbox Code Playgroud)

也就是说,究竟是什么决定了方法的调用setAuthenticationStrategy?这是我的财产名称authenticationStrategy吗?Spring会自动将属性名称转换为适当的setter方法吗?

java spring javabeans spring-ldap

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

Spring嵌入式LDAP与LdapTemplate

,嵌入式如何与模板一起使用.目前,我的配置是 -

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:security="http://www.springframework.org/schema/security" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
      http://www.springframework.org/schema/security 
      http://www.springframework.org/schema/security/spring-security-3.0.xsd">
    <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
        <property name="url" value="${PROVIDER_URL}" />
        <property name="base" value="${Search_Base}" />
        <property name="userDn" value="${SECURITY_PRINCIPAL}" />
        <property name="password" value="${SECURITY_CREDENTIALS}" />
    </bean>
    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
        <constructor-arg ref="contextSource" />
    </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

ContextSource值在属性文件中可用.现在我想使用嵌入式ldap -

<security:ldap-server ldif="classpath:sample.ldif"  root="cn=mojo"/>
Run Code Online (Sandbox Code Playgroud)

我将在LdapContextSource值中指定什么默认端口.

java spring spring-security spring-ldap

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

Spring LDAP querybuilder PartialResultException

我正在尝试从LDAP服务器中获取所有用户,并从基础上进行搜索,这是我的代码:

public LdapTemplate ldapTemplate() {
        LdapContextSource ctxSrc = new LdapContextSource();
        ctxSrc.setUrl("ldap://127.0.0.1:389/");
        ctxSrc.setBase("dc=test,dc=com");
        ctxSrc.setUserDn("admin");
        ctxSrc.setPassword("password");
        ctxSrc.afterPropertiesSet();
        LdapTemplate lt = new LdapTemplate(ctxSrc);
        return lt;
}
private LdapTemplate ldapTemplate = ldapTemplate();
public List<User> getAllUsers() {

        LdapQuery query= query().base("").where("objectclass").is("user");
        return ldapTemplate.search(query, new UserAttributesMapper());
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

10:07:09.406 [main] DEBUG o.s.l.c.s.AbstractContextSource - AuthenticationSource not set - using default implementation
10:07:09.413 [main] DEBUG o.s.l.c.s.AbstractContextSource - Not using LDAP pooling
10:07:09.416 [main] DEBUG o.s.l.c.s.AbstractContextSource - Trying provider Urls: ldap://127.0.0.1:389/dc=test,dc=com
10:07:09.548 [main] DEBUG o.s.l.c.s.AbstractContextSource - Got Ldap context on …
Run Code Online (Sandbox Code Playgroud)

spring spring-ldap

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

如何在Java中将SID转换为String,反之亦然?

我正在使用Spring-LDAP编写Java程序.我需要实现一个方法,该方法应该通过SID搜索用户.出于这个原因,我使用过滤器"&((objectClass=User)(objectSid="+sid+"))".搜索不适用于字符串格式的sid "S-1-12-345677-5676743-223344-...".

使用Apache Directory Studio,我可以使用如下过滤器定期查询我的AD LDAP数据库:(objectSid=\ff\01\03\04\1a\2b\...)成功.这是十六进制格式的objectSid.

现在,如何在Java中将SID从String转换为十六进制,反之亦然?

java string hex sid spring-ldap

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

java.net.ConnectException:连接到 ldap 时连接超时

我正在尝试使用spring ldap 1.3.1.RELEASE连接到Windows Server 2008上的ldap 活动目录 ,并且 ldap 配置如下:

  • LDAP 网址为:ldap://dc.fabrikam.com
  • 用户名:管理员
  • 密码:123456

- spring ldap配置如下:

    <bean id="contextSource" 
    class="org.springframework.ldap.core.support.LdapContextSource">
    <property name="url" value="ldap://dc.fabrikam.com" />
    <property name="base" value="dc=fabrikam,dc=com" />     
    <property name="userDn" value="CN=administrator,CN=Users,DC=fabrikam,DC=com" />     
    <property name="password" value="123456" />


    <property name="baseEnvironmentProperties">
    <map>
        <entry key="java.naming.referral">
            <value>follow</value>
        </entry>
    </map>
    </property>

</bean>

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    <constructor-arg ref="contextSource" />
</bean>
Run Code Online (Sandbox Code Playgroud)
  • LDAPContactDAO:

    @Service
    public class LDAPContactDAO implements ContactDAO {
    
    @Autowired
    private LdapTemplate ldapTemplate;
    
    public List getAllContactNames() {
        return ldapTemplate.search("", "(objectclass=person)", …
    Run Code Online (Sandbox Code Playgroud)

spring ldap active-directory spring-ldap

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

Spring LDAP,在java中设置连接细节

我想设置LDAP连接以列出AD中的所有用户.我用XML中存储的信息成功完成了这项工作

<ldap:context-source
url="ldap://<url>"
base="dc=example,dc=local"
username="<user>@example.local"
password="<pass>" />
Run Code Online (Sandbox Code Playgroud)

但是如何从Java而不是XML中设置这些信息呢?试过:

LdapContextSource ctxSrc = new LdapContextSource();
    ctxSrc.setUrl("ldap://<url>");
    ctxSrc.setBase("dc=example,dc=local");
    ctxSrc.setUserDn("<user>@example.local");
    ctxSrc.setPassword("<pass>");
LdapTemplate tmpl = new LdapTemplate(ctxSrc);
setLdapTemplate(tmpl);
Run Code Online (Sandbox Code Playgroud)

但是在跑步的时候

List users = (List<User>) ldapTemplate.search(LdapUtils.emptyLdapName(), "(&(objectCategory=person)(objectClass=user))", new UserAttributesMapper());

我得到NullPointerExeption.在没有从java设置属性的情况下运行(即从xml读取)一切正常

java spring spring-ldap

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

在LDAP中实现超时

我一直在处理我们使用LDAP获取用户详细信息的应用程序.有时需要更多时间来获取用户详细信息.我想在获取详细信息的方法上实现超时,以便在最坏的情况下我们可以避免在服务器中挂起事务.

这里我们使用LdapUtil的是已配置LdapTemplate类的类来获取所需的详细信息.

我们如何在LDAP方法上实现超时? (在这种情况下的ldapTemplate.search(...)方法)

public class LdapUtil {

    @Autowired(required = true)
    @Qualifier(value = "ldapTemplateApp")
    LdapTemplate ldapTemplate;

    public Set < ProductGroup > findProducts(String UserId) {
        final Set < ProductGroup > products = newHashSet();
        // Lookup the user         
        String usrFilter = String.format(USERID_FILTER, globalUserId);

        ldapTemplate.search("ou=Members", usrFilter, // note this line
        new NameClassPairCallbackHandler() {

            public void handleNameClassPair(NameClassPair nameClassPair) {
                SearchResult result = (SearchResult) nameClassPair;
                String user = result.getNameInNamespace();

                String GrpFilter = String.format(GROUP_FILTER, user);

                List …
Run Code Online (Sandbox Code Playgroud)

java spring ldap ldapconnection spring-ldap

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

LDAPTemplate.ignorePartialResultException的Spring Java配置

应用程序学问题很长,但总之我想知道如何org.springframework.ldap.core.LdapTemplate#ignorePartialResultException使用Spring Java Config 设置标志。

长期存在的问题是...

我想使用我们公司的Active Directory进行身份验证(这意味着用户/密码检查),然后再进行授权(因此他们有权使用哪些角色)。

我采用了春季ldap指南,并进行了更改以连接到我们公司的Active Directory,而不是使用指南的LDIF文件。通过调试,我知道程序连接到Active Directory并正确验证了用户身份,但是在检索权限时,出现以下异常:

Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException
Run Code Online (Sandbox Code Playgroud)

从谷歌搜索中,我看到这是一个常见的LDAP / ActiveDirectory问题,我需要设置标志以忽略引用。我遵循了这个SO问题中的示例。但是,我仍然遇到异常,通过调试,我可以发现在为用户搜索角色时,以下方法中发生了错误。

org.springframework.ldap.core.LdapTemplate#search(org.springframework.ldap.core.SearchExecutor, org.springframework.ldap.core.NameClassPairCallbackHandler, org.springframework.ldap.core.DirContextProcessor) 
Run Code Online (Sandbox Code Playgroud)

作为参考,我的WebSecurityConfig文件:

Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException
Run Code Online (Sandbox Code Playgroud)

active-directory spring-ldap spring-security-ldap spring-java-config

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

按多个属性搜索 LDAP 模板

尝试使用 userid、emailid、firstname、lastname、GUID 等搜索用户详细信息...将来需要添加更多值

应该使用所有不为空的属性来执行搜索。在网上找到这段代码*

字符串过滤器 = "(&(sn=YourName)(mail=*))";

* 是否有任何其他预定义模板或类似的模板来进行搜索,而不是直接将值指定为 Null 或为每个属性使用 if else 语句的更优化方法?所有值都必须传递给该方法,非空值必须用于使用 LDAP 进行搜索。任何事物?请帮忙。

spring spring-ldap

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