使用 LDAP 进行 Spring Security 身份验证
我是 spring security 的新手,我尝试运行一个基于 spring-security ldap 示例的示例应用程序。以下是我的 applicationContext-security.xml 配置:
<http>
<intercept-url pattern="/Login.jsp" filters="none"></intercept-url>
<intercept-url pattern="/nnn/**" access="ROLE_ADMIN" />
<intercept-url pattern="/common/**" access="ROLE_USER" />
<form-login login-page="/Login.jsp" authentication-failure-url="/Login.jsp?login_error=1"
default-target-url="/common/home.jsp"/>
<logout logout-success-url="/Login.jsp" invalidate-session="true"/>
</http>
<authentication-manager>
<ldap-authentication-provider group-search-filter="member={0}"
group-search-base="ou=groups"
user-search-base="ou=people"
user-search-filter="uid={0}" />
<authentication-provider ref='secondLdapProvider' />
</authentication-manager>
<ldap-server ldif="classpath:users.ldif" port="33389"/>
<b:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<b:constructor-arg value="ldap://localhost:33389/dc=springframework,dc=org"/>
</b:bean>
我按原样使用了 user.ldif 文件。 如果我使用默认值,应用程序将成功运行。但是,如果我在 ldif 文件和 applicationContext-security.xml 中的 contextSource bean 中放置任何其他值来代替 springframework(例如 google),那么我会收到以下错误:
Your login attempt was not successful, try again.
Reason: [LDAP: error code 32 - NO_SUCH_OBJECT: failed for SearchRequest baseDn :
'2.5.4.11=people,0.9.2342.19200300.100.1.25=google,0.9.2342.19200300.100.1.25=org' filter : '(0.9.2342.19200300.100.1.1=rod)' scope :whole
subtree typesOnly : false Size Limit : no limit Time Limit : no limit Deref Aliases : deref Always attributes : : Cannot find a partition for
2.5.4.11=people,0.9.2342.19200300.100.1.25=google,0.9.2342.19200300.100.1.25=org:
org.apache.directory.shared.ldap.exception.LdapNameNotFoundException: Cannot find a partition for
2.5.4.11=people,0.9.2342.19200300.100.1.25=google,0.9.2342.19200300.100.1.25=org at
org.apache.directory.server.core.partition.DefaultPartitionNexus.getPartition(DefaultPartitionNexus.java:1082) at
org.apache.directory.server.core.partition.DefaultPartitionNexus.hasEntry(DefaultPartitionNexus.java:1037) at
org.apache.directory.server.core.interceptor.InterceptorChain$1.hasEntry(InterceptorChain.java:167) at
有人可以告诉我为什么会出现上述情况吗?错误...
这是 ldif 文件:
dn: ou=groups,dc=google,dc=org
objectclass: top
objectclass: organizationalUnit
ou: groups
dn: ou=people,dc=google,dc=org
objectclass: top
objectclass: organizationalUnit
ou: people
dn: uid=rod,ou=people,dc=google,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Rod Johnson
sn: Johnson
uid: rod
userPassword: koala
dn: uid=dianne,ou=people,dc=google,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Dianne Emu
sn: Emu
uid: dianne
userPassword: emu
dn: uid=scott,ou=people,dc=google,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Scott
sn: Wombat
uid: scott
userPassword: wombat
dn: cn=user,ou=groups,dc=google,dc=org
objectclass: top
objectclass: groupOfNames
cn: user
member: uid=rod,ou=people,dc=google,dc=org
member: uid=dianne,ou=people,dc=google,dc=org
member: uid=scott,ou=people,dc=google,dc=org
dn: cn=teller,ou=groups,dc=google,dc=org
objectclass: top
objectclass: groupOfNames
cn: USER
member: uid=rod,ou=people,dc=google,dc=org
member: dianne=rod,ou=people,dc=google,dc=org
dn: cn=supervisor,ou=groups,dc=google,dc=org
objectclass: top
objectclass: groupOfNames
cn: ADMIN
member: uid=rod,ou=people,dc=google,dc=org
它不是 google,而是示例应用程序的原始文件中的 springframework。我是不是在这件事上遗漏了什么……
I am new to spring security and i've tried to run a sample application based on the spring-security ldap example. Below is my configuration of the applicationContext-security.xml:
<http>
<intercept-url pattern="/Login.jsp" filters="none"></intercept-url>
<intercept-url pattern="/nnn/**" access="ROLE_ADMIN" />
<intercept-url pattern="/common/**" access="ROLE_USER" />
<form-login login-page="/Login.jsp" authentication-failure-url="/Login.jsp?login_error=1"
default-target-url="/common/home.jsp"/>
<logout logout-success-url="/Login.jsp" invalidate-session="true"/>
</http>
<authentication-manager>
<ldap-authentication-provider group-search-filter="member={0}"
group-search-base="ou=groups"
user-search-base="ou=people"
user-search-filter="uid={0}" />
<authentication-provider ref='secondLdapProvider' />
</authentication-manager>
<ldap-server ldif="classpath:users.ldif" port="33389"/>
<b:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<b:constructor-arg value="ldap://localhost:33389/dc=springframework,dc=org"/>
</b:bean>
I've used the user.ldif file as it is.
The application runs successfully if I use the default values. But if I put any other value in place of springframework, say google, in the ldif file and in the contextSource bean in the applicationContext-security.xml, then I get the below error:
Your login attempt was not successful, try again.
Reason: [LDAP: error code 32 - NO_SUCH_OBJECT: failed for SearchRequest baseDn :
'2.5.4.11=people,0.9.2342.19200300.100.1.25=google,0.9.2342.19200300.100.1.25=org' filter : '(0.9.2342.19200300.100.1.1=rod)' scope :whole
subtree typesOnly : false Size Limit : no limit Time Limit : no limit Deref Aliases : deref Always attributes : : Cannot find a partition for
2.5.4.11=people,0.9.2342.19200300.100.1.25=google,0.9.2342.19200300.100.1.25=org:
org.apache.directory.shared.ldap.exception.LdapNameNotFoundException: Cannot find a partition for
2.5.4.11=people,0.9.2342.19200300.100.1.25=google,0.9.2342.19200300.100.1.25=org at
org.apache.directory.server.core.partition.DefaultPartitionNexus.getPartition(DefaultPartitionNexus.java:1082) at
org.apache.directory.server.core.partition.DefaultPartitionNexus.hasEntry(DefaultPartitionNexus.java:1037) at
org.apache.directory.server.core.interceptor.InterceptorChain$1.hasEntry(InterceptorChain.java:167) at
Could someone please tell me why am I getting the above error...
This is the ldif file:
dn: ou=groups,dc=google,dc=org
objectclass: top
objectclass: organizationalUnit
ou: groups
dn: ou=people,dc=google,dc=org
objectclass: top
objectclass: organizationalUnit
ou: people
dn: uid=rod,ou=people,dc=google,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Rod Johnson
sn: Johnson
uid: rod
userPassword: koala
dn: uid=dianne,ou=people,dc=google,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Dianne Emu
sn: Emu
uid: dianne
userPassword: emu
dn: uid=scott,ou=people,dc=google,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Scott
sn: Wombat
uid: scott
userPassword: wombat
dn: cn=user,ou=groups,dc=google,dc=org
objectclass: top
objectclass: groupOfNames
cn: user
member: uid=rod,ou=people,dc=google,dc=org
member: uid=dianne,ou=people,dc=google,dc=org
member: uid=scott,ou=people,dc=google,dc=org
dn: cn=teller,ou=groups,dc=google,dc=org
objectclass: top
objectclass: groupOfNames
cn: USER
member: uid=rod,ou=people,dc=google,dc=org
member: dianne=rod,ou=people,dc=google,dc=org
dn: cn=supervisor,ou=groups,dc=google,dc=org
objectclass: top
objectclass: groupOfNames
cn: ADMIN
member: uid=rod,ou=people,dc=google,dc=org
Instead of google, it was springframework in the original file from the sample application. Am I missing something in this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将
root
设置为所需的基本 dn/后缀(在您的情况下为 dc=google,dc=org)才能使其正常工作。因此,总共有三个地方需要进行更改:默认根是
dc=springframework,dc=org
即为什么您不需要在您发布的示例中设置它。要使用任何其他基本 DN,请遵循下面的示例 ldap-server 定义:You need to set
root
to desired base-dn/suffix (dc=google,dc=org, in your case) to get it to work. so, in all, there are three places where you need to make changes:The default root is
dc=springframework,dc=org
that is why you did not need to set it in the example you posted. To use any other base dn, follow the example ldap-server definition below:搜索请求必须至少包含基础对象、范围和过滤器。查询中指定的基础对象不存在,因此搜索失败。正如您所看到的,错误代码 32 是“没有这样的对象”,在本例中是基础对象。
A search request must contain a base object, a scope, and a filter at minimum. The base object that is specified in your query does not exist, therefore the search fails. Error code 32 is, as you can see, 'no such object', in this case, the base object.