2013-05-28 16 views
0

這是我的彈簧security.xml文件的某個部分。 我的要求是 - 我想只能用嵌入式LDAP服務器,並且希望使用LdapAuthoritiesPopulator在與ITT如何實現定製LdapAuthoritiesPopulator在

<security:authentication-manager> 
      <security:ldap-authentication-provider 
        user-search-filter="(uid={0})" 
        user-search-base="ou=users" 
        group-search-filter="(uniqueMember={0})" 
        group-search-base="ou=groups" 
        group-role-attribute="cn" 
        role-prefix="ROLE_"> 
      </security:ldap-authentication-provider> 
    </security:authentication-manager> 

    <!-- Use an embedded LDAP server. We need to declare the location of the LDIF file 
      We also need to customize the root attribute default is --> 
    <security:ldap-server ldif="classpath:mojo.ldif" root="dc=springframework,dc=org"/> 

我想用我的自定義好的LdapAuthoritiesPopulator。 如何使用嵌入式LDAP服務器中使用它。 我是新來的春天到現在爲止。

回答

0

你可以配置DefaultLDAPAuthoritesPopulator您的身份驗證提供者提供的細節,以找到角色的組。如果您的案例中有更具體的內容,您可以擴展此課程。查看春季安全樣本。我是新來的春季安全太多,但我發現源代碼是非常有益的。祝你好運。

FYI contextSource bean DefaultSpringSecurityContextSource應該使用url配置到LDAP服務器。

希望這會有所幫助。

<bean id="ldapAuthenticationProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"> 
    <constructor-arg> 
     <bean class="org.springframework.security.ldap.authentication.BindAuthenticator"> 
      <constructor-arg ref="contextSource"/> 
       <property name="userSearch"> 
        <bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"> 
         <constructor-arg index="0" value="ou=Google,ou=People"/> 
         <constructor-arg index="1" value="(uid={0})"/> 
         <constructor-arg index="2" ref="contextSource"/> 
        </bean> 
       </property> 
     </bean> 
    </constructor-arg> 
    <constructor-arg> 
     <bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator"> 
       <constructor-arg ref="contextSource"/> 
       <constructor-arg value="ou=Groups"/> 
       <property name="groupSearchFilter" value="member={0}"/> 
       <property name="searchSubtree" value="true"/> 
     </bean> 
    </constructor-arg> 
    <property name="authoritiesMapper"> 
     <bean class="org.springframework.security.core.authority.mapping.SimpleAuthorityMapper"> 
       <property name="convertToUpperCase" value="true"/> 
      </bean> 
    </property> 
</bean> 

<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"> 
    <constructor-arg value="ldap://127.0.0.1:389/dc=google,dc=com"/> 
</bean> 
+0

什麼可以是conextSource的嵌入式服務器。你可以給它嗎? – Discovery

+0

@Learner我更新了我的答案代碼。 –