我有一个我正在编写的LDAP应用程序的beans.xml文件.我允许用户选择几个LdapContextSource.对于每一个我有一个不同的豆,例如
<bean id="ldapTemplate" class="yyy.LdapTemplate">
<constructor-arg ref="contextSource1" />
</bean>
<bean id="contextSource1" class="xxx.LdapContextSource">
...
</bean>
<bean id="contextSource2" class="xxx.LdapContextSource">
...
</bean>
<bean id="contextSource3" class="xxx.LdapContextSource">
...
</bean>
Run Code Online (Sandbox Code Playgroud)
您可以看到只有一个上下文源bean被实例化,因为ldapTemplate bean只引用了一个.但是,当我运行我的应用程序时,stdout中的Spring日志消息提供了有关每个上下文源的信息,即使只依赖于其中一个.
2011年1月25日上午11:56:36 org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet INFO:未设置属性'userDn' - 匿名上下文将用于读写操作Jan 25,2011 11:56:37 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet INFO:未设置属性'userDn' - 匿名上下文将用于读写操作2011年1月25日上午11:56:37 org.springframework.ldap.core. support.AbstractContextSource afterPropertiesSet INFO:未设置属性'userDn' - 匿名上下文将用于读写操作
我的问题是:
(1)Spring使用未引用/依赖的上下文源做什么?它们永远不应该在我的应用程序中实例化,它让我担心Spring正在为每个bean提供日志信息.
(2)我应该注释掉应用程序中未使用的上下文源bean吗?让他们没有注释会有什么后果?什么是标准做法?
谢谢,
ktm
我想从 ldap 搜索特定用户详细信息。所以我写下了以下代码来检索用户详细信息,但它返回用户对象列表。基本上我只想要人对象而不是人对象列表。使用 LDAP 模板检索 IM。我如何修改此代码以使其返回 person 对象?
public void searchByFirstName(String loginId) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "Person"));
filter.and(new EqualsFilter("cn", loginId));
List list = ldapTemplate.search("",
filter.encode(),
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs) throws NamingException {
return attrs.get("sn").get();
}
});
}
Run Code Online (Sandbox Code Playgroud) 我们正在尝试使用Spring安全性来对我们的企业LDAP进行身份验证.我正在使用ActiveDirectoryLdapAuthenticationProvider.下面是Spring配置文件的片段:
<security:authentication-manager erase-credentials="true">
<security:authentication-provider ref="ldapActiveDirectoryAuthProvider"/>
</security:authentication-manager>
<bean id="ldapActiveDirectoryAuthProvider" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
<constructor-arg value="DC=xxx,DC=ds,DC=yyy,DC=com" />
<constructor-arg value="ldap://xxx.ds.yyy.com:389" />
<property name="convertSubErrorCodesToExceptions" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
我得到:ActiveDirectoryLdapAuthenticationProvider handleBindException Active Directory身份验证失败:提供的密码无效错误.
我的理解是,这是因为LDAP绑定失败,因为它正在寻找userDN /凭证.我们如何在配置文件中指定此信息?
在使用之前ActiveDirectoryLdapAuthenticationProvider,我使用<ldap-authentication-provider>和使用了这个DefaultSpringSecurityContextSource.我可以在配置DefaultSpringSecurityContextSourcebean 时指定userDN /密码.在配置使用时,有人能告诉我如何指定userDn和密码ActiveDirectoryLdapAuthenticationProvider吗?
我想使用Spring LDAP实现一个基本的用户存储库,它是对象目录映射(ODM)的概念.
我的User类非常简单:
@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "shadowAccount", "top" }, base = "ou=people")
public class User {
[...]
@Id
private Name dn;
@Attribute(name = "uid")
@DnAttribute(value = "uid")
private String username;
@Attribute(name = "cn")
private String fullName;
@Attribute(name = "givenName")
private String firstName;
@Attribute(name = "sn")
private String lastName;
@Attribute(name = "o")
private String organization;
@Attribute(name = "userPassword")
private String password;
// Getters & Setters
[...]
}
Run Code Online (Sandbox Code Playgroud)
和我的存储库的基本方法:
public User findByUid(String uid) {
return ldapTemplate.findOne(query().where("uid").is(uid), User.class);
}
public …Run Code Online (Sandbox Code Playgroud) 在Spring LDAP中使用LdapTemplate,我有这样的代码:
Object object=null;
try{
String dn = "cn=readers,ou=groups,dc=mycompany, dc=com";
object = this.ldapTemplate.lookup(dn);
} catch(final NameNotFoundException e){
// create Object
}
Run Code Online (Sandbox Code Playgroud)
但是因为我读过我的Joshua Bloch,我知道不应该将异常用于控制流程.有没有办法查找一个dn,看看它是否存在而不抛出异常,如果不存在?一定有,但我找不到.我正在寻找像这样(或类似)的代码:
String dn = "cn=readers,ou=groups,dc=mycompany, dc=com";
Object object=this.ldapTemplate.someMethod(dn);
if(object==null){
// create Object
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
BTW:只是看看JavaDoc无济于事.抛出的方法都没有NameNotFoundException在JavaDocs中说明.
我使用Grails + spring-security + LDAP来验证用户身份.验证现在可以正常工作但我需要使用纯文本密码来验证第二个服务.
我尝试了SpringSecurityService属性,但没有包含密码.
我是否必须实现自己的UserDetailsMapper,或者LdapUserDetailsMapper是否也提供从Web表单检索的纯文本密码的映射?
1.2.1是可用的,我可以得到它
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap</artifactId>
<version>1.2.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但我无法获得最新版本.我用过
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我有兴趣使用LdapTemplate的authenticate方法.
可能重复:
使用Spring Security时,获取bean中当前用户名(即SecurityContext)信息的正确方法是什么?
spring security如何检索用户名
我使用spring ldap来验证我的网络应用程序,
<ldap-server id="sss" port="389"
url="ldap://ldap.example.com:389/ou=active,ou=employees,ou=people,o=example.com?uid?sub"/>
<authentication-manager alias="authenticationManager">
<ldap-authentication-provider
server-ref="sss"
role-prefix="ROLE_">
</ldap-authentication-provider>
</authentication-manager>
Run Code Online (Sandbox Code Playgroud)
它工作,但我不知道如何在登录页面填写用户名,因为我想在我的页面顶部显示它.
谢谢.
我正在尝试使用Spring的LDAP软件包针对活动目录进行身份验证,但是我一直收到一条错误消息,提示我指定了错误的baseDN(Ldap错误代码32):
org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001E4, problem 2001 (NO_OBJECT), data 0, best match of:
[testng] 'OU=People,DC=example,DC=com'
[testng] ]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001E4, problem 2001 (NO_OBJECT), data 0, best match of:
[testng] 'OU=People,DC=example,DC=com'
[testng] ]; remaining name 'ou=people,dc=example,dc=com'
Run Code Online (Sandbox Code Playgroud)
奇怪的是ldapsearch命令使用完全相同的basedn,并且可以正常工作:
ldapsearch -V -x -H ldap://ad.example.com:389 -b 'ou=people,dc=example,dc=com' -D '<user>' -w '<password>' (sAMAccountName=<user>)
Run Code Online (Sandbox Code Playgroud)
以下代码设置DN(以编程方式设置ldapContextSource):
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("sAMAccountName", user));
DistinguishedName dn = new DistinguishedName("ou=people,dc=example,dc=com");
boolean in = ldapTemplate.authenticate(dn, …Run Code Online (Sandbox Code Playgroud) 我们正在创建一个grails aplication,我们希望用户使用他们的Active Directory凭据登录.此外,我们希望为此应用程序的业务所有者提供控制谁可以访问某些链接(操作)的能力.因此我们在grails应用程序中使用以下插件:
因为我们希望授权业务用户在必要时动态创建具有特定权限(操作)的自定义角色,我们认为最好的Spring Security配置是基于Requestmap数据库的方法
到目前为止,我们已完成如下:
问题/问题
spring-security-core插件创建了以下表:
这些是支持角色创建的表,即角色的URL分配.但是,Person_Authoritity表作为约定名称意味着它是PERSON和AUTHORITY(ROLE)之间的多对多关系,因为一个人可能有多个角色.我的问题是我没有Person,因为该人已存在于Active Directory(外部源)中,并且未在应用程序中创建.
有没有办法让经过身份验证的用户成为PERSON?Spring安全解决方案需要Person行或对象,但您更喜欢引用它.
我也在这里发布了这个问题:
谢谢,
grails spring-security spring-ldap grails-plugin spring-security-ldap
我需要向我的 LDAP 添加一个新的用户条目。以下是我的代码:
javax.naming.Name name = new DistinguishedName("cn=" + userName +",ou=Users,dc=wso2,dc=org");
Attribute objectClass = new BasicAttribute("objectClass");
{
objectClass.add("top");
objectClass.add("inetOrgPerson");
objectClass.add("person");
objectClass.add("organizationalPerson");
}
Attributes userAttributes = new BasicAttributes();
userAttributes.put(objectClass);
userAttributes.put("cn", userName);
userAttributes.put("sn", "abctest");
userAttributes.put(ATTRIBUTE_USER_PASSWORD, password);
LdapTemplate ldapTemplate = (LdapTemplate) SpringBeanFactory
.getBean("ldapTemplate");
ldapTemplate.bind(name, null, userAttributes);
Run Code Online (Sandbox Code Playgroud)
尽管执行这段代码时我得到以下异常:
org.apache.cxf.interceptor.Fault: [LDAP: error code 32 - No Such Object];
nested exception is javax.naming.NameNotFoundException:
[LDAP: error code 32 - No Such Object]; remaining name 'cn=myname,ou=Users,dc=wso2,dc=org'
Run Code Online (Sandbox Code Playgroud)
我遵循http://kaustuvmaji.blogspot.in/2014/12/simple-example-of-spring-ldap.html中指定的示例代码。有人可以帮助我理解此错误的根本原因或正确的代码。
我无法使用真实的活动目录进行身份验证,让我更好地解释一下我尝试使用 spring.io 提出的示例进行身份验证,没有问题,内部服务启动没有任何问题。参考https://spring.io/guides/gs/authenticating-ldap/
我试图通过插入我的活动目录的配置来修改下面的代码,但没有成功。您能否指导我或向我展示一个真实的案例,在不使用示例中的内部服务的情况下建立真正的连接?我在网上查看,但发现一切都与官方示例相似,没有任何实际案例
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("uid={0},ou=people")
.groupSearchBase("ou=groups")
.contextSource()
.url("ldap://localhost:8389/dc=springframework,dc=org")
.and()
.passwordCompare()
.passwordEncoder(new LdapShaPasswordEncoder())
.passwordAttribute("userPassword");
}
Run Code Online (Sandbox Code Playgroud)
错误显示:LDAP处理过程中出现未分类异常;嵌套异常是 javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0907C2, comment: 为了执行此操作,必须在连接上完成成功的绑定。, data 0, v2580