Безопасность Spring пользовательский поставщик аутентификации LDAP

Мне в настоящее время настраивали мой контекст аутентификации LDAP как это:

    
    
        
     

Теперь, я должен смочь настроить пользовательский картопостроитель полномочий (он использует другой ldap сервер) - таким образом, я предполагаю, что должен настроить свой ldap-сервер, подобный (http://static.springsource.org/spring-security/site/docs/2.0.x/reference/ldap.html):


  
    
      
      
        uid={0},ou=people
      
    
  
  
    
      
      
      
    
  

Но, как я ссылаюсь что 'ldapAuthProvider' к ldap-серверу в контексте защиты?

Я также использую пружинную безопасность 3, таким образом, '' не существует...

5
задан gdrt 20 March 2018 в 13:15
поделиться

1 ответ

Что я сделал, чтобы заставить это работать, так это просто добавил это в контекст безопасности:

<authentication-manager>
     <authentication-provider ref='ldapAuthProvider'/>
</authentication-manager>

А затем, настроив боб 'ldapAuthProvider' следующим образом:

<bean id="contextSource"
    class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldaps://url/dc=mock,dc=com" />
    <property name="userDn" value="cn=username,ou=People,dc=mock,dc=com" />
    <property name="password" value="password" />
</bean>

<bean id="ldapAuthProvider"
    class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
        <bean
            class="org.springframework.security.ldap.authentication.BindAuthenticator">
            <constructor-arg ref="contextSource" />
            <property name="userDnPatterns">
                <list>
                    <value>uid={0},ou=People</value>
                </list>
            </property>
        </bean>
    </constructor-arg>
    <constructor-arg>
        <bean
            class="com.mock.MyCustomAuthoritiesPopulator">
        </bean>
    </constructor-arg>
</bean>

С реализацией MyCustomAuthoritiesPopulator следующим образом:

public class MyCustomAuthoritiesPopulator implements LdapAuthoritiesPopulator {
    public Collection<GrantedAuthority> getGrantedAuthorities(
            DirContextOperations arg0, String arg1) {       
           ArrayList<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
            list.add((new SimpleGrantedAuthority("ROLE_USER"));
        return list;        
    }
}
5
ответ дан 13 December 2019 в 22:04
поделиться
Другие вопросы по тегам:

Похожие вопросы: