Chúng tôi đang sử dụng bảo mật mùa xuân để xác thực người dùng từ LDAP trong ứng dụng của chúng tôi. Phần xác thực đang hoạt động đúng nhưng phần ủy quyền không hoạt động.Cách điền chính quyền LDAP từ Active Directory LDAP bằng bảo mật mùa xuân?
Chúng tôi không thể truy xuất vai trò của người dùng từ LDAP.
Từ cuốn sách "Xuân An 3" bởi Peter Mularien
"Điều này là do kích hoạt các cửa hàng thư mục nhóm thành viên như là thuộc tính trên các mục LDAP của người sử dụng tự. Ra khỏi hộp (tính thời gian xuất bản), Bảo mật mùa xuân không cung cấp LdapAuthoritiesPopulator có thể được định cấu hình để hỗ trợ cấu trúc của cây LDAP Active Directory điển hình. "
Dưới đây là tệp cấu hình bảo mật mùa xuân của tôi.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http use-expressions="true" >
<intercept-url pattern="/resources/**" filters="none" />
<intercept-url pattern="/login" access="permitAll"/>
<intercept-url pattern="/**" access="isAuthenticated()" />
<form-login login-page="/login"
default-target-url="/home"
always-use-default-target="true"
authentication-failure-url="/login?login_error=1" />
<logout invalidate-session="true"
logout-success-url="/"
logout-url="/logout"/>
</http>
<authentication-manager alias="ldapAuthenticationManager">
<authentication-provider ref="ldapAuthenticationProvider"/>
</authentication-manager>
<beans:bean id="ldapAuthenticationProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<beans:constructor-arg ref="ldapBindAuthenticator"/>
<beans:constructor-arg ref="ldapAuthoritiesPopulator"/>
<beans:property name="userDetailsContextMapper" ref="ldapUserDetailsContextMapper"/>
</beans:bean>
<beans:bean id="ldapServer" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<!-- MS Active Directory -->
<beans:constructor-arg value="ldap://localhost:389/dc=myOrg,dc=net"/>
<beans:property name="userDn" value="admin"/>
<beans:property name="password" value="admin"/>
<beans:property name="baseEnvironmentProperties">
<beans:map>
<beans:entry key="java.naming.referral" value="follow" />
</beans:map>
</beans:property>
</beans:bean>
<beans:bean id="ldapBindAuthenticator" class="org.springframework.security.ldap.authentication.BindAuthenticator">
<beans:constructor-arg ref="ldapServer"/>
<beans:property name="userSearch" ref="ldapSearchBean"/>
</beans:bean>
<beans:bean id="ldapSearchBean" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<!-- MS Active Directory -->
<!-- user-search-base; relative to base of configured context source -->
<beans:constructor-arg value="ou=Software OU"/>
<!-- user-search-filter -->
<beans:constructor-arg value="(sAMAccountName={0})"/>
<beans:constructor-arg ref="ldapServer"/>
</beans:bean>
<beans:bean id="ldapAuthoritiesPopulator" class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<beans:constructor-arg ref="ldapServer" />
<beans:constructor-arg value="" />
<beans:property name="groupSearchFilter" value="(sAMAccountName={0})"/>
<beans:property name="groupRoleAttribute" value="memberOf" />
<beans:property name="rolePrefix" value=""/>
<beans:property name="searchSubtree" value="true"/>
<beans:property name="convertToUpperCase" value="false"/>
<beans:property name="ignorePartialResultException" value="true"/>
</beans:bean>
<beans:bean class="org.springframework.security.ldap.userdetails.InetOrgPersonContextMapper" id="ldapUserDetailsContextMapper"/>
</beans:beans>
Xin vui lòng trợ giúp.
Điều gì bị thiếu trong mã của bạn? Việc chấp nhận giải pháp/siêu liên kết được cung cấp là một điều, nhưng chỉ ra phần còn thiếu sẽ là tuyệt vời để giúp những người khác (như tôi) có cùng một vấn đề chính xác. Cảm ơn bạn đã chia sẻ giải pháp chi tiết của bạn. –
@CharlesMorin Tôi nhận ra câu trả lời của tôi là phụ cận, xin lỗi. Thêm cấu hình Spring của chúng tôi cho AD. –
@ MarcelStör Cảm ơn bạn. Bạn đang sử dụng máy chủ ứng dụng nào? Tôi đang cố gắng để có những điều tương tự làm việc trên JBoss AS 7.2, mà không có bất kỳ thành công. Sẽ xem xét cấu hình của bạn. –