Java Code Examples for org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator

The following examples show how to use org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: taskana   Source File: WebSecurityConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator() {
  Function<Map<String, List<String>>, GrantedAuthority> authorityMapper =
      record -> {
        String role = record.get("spring.security.ldap.dn").get(0);
        return new SimpleGrantedAuthority(role);
      };

  DefaultLdapAuthoritiesPopulator populator =
      new DefaultLdapAuthoritiesPopulator(
          defaultSpringSecurityContextSource(), ldapGroupSearchBase);
  populator.setGroupSearchFilter(ldapGroupSearchFilter);
  populator.setSearchSubtree(true);
  populator.setRolePrefix("");
  populator.setAuthorityMapper(authorityMapper);
  return populator;
}
 
Example 2
Source Project: taskana   Source File: WebSecurityConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator() {
  Function<Map<String, List<String>>, GrantedAuthority> authorityMapper =
      record -> {
        String role = record.get("spring.security.ldap.dn").get(0);
        return new SimpleGrantedAuthority(role);
      };

  DefaultLdapAuthoritiesPopulator populator =
      new DefaultLdapAuthoritiesPopulator(
          defaultSpringSecurityContextSource(), ldapGroupSearchBase);
  populator.setGroupSearchFilter(ldapGroupSearchFilter);
  populator.setSearchSubtree(true);
  populator.setRolePrefix("");
  populator.setAuthorityMapper(authorityMapper);
  return populator;
}
 
Example 3
Source Project: blackduck-alert   Source File: LdapManager.java    License: Apache License 2.0 5 votes vote down vote up
private LdapAuthoritiesPopulator createAuthoritiesPopulator(FieldAccessor configurationModel, LdapContextSource contextSource) {
    String groupSearchBase = configurationModel.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_GROUP_SEARCH_BASE);
    String groupSearchFilter = configurationModel.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_GROUP_SEARCH_FILTER);
    String groupRoleAttribute = configurationModel.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_GROUP_ROLE_ATTRIBUTE);
    MappingLdapAuthoritiesPopulator mappingLdapAuthoritiesPopulator = new MappingLdapAuthoritiesPopulator(contextSource, groupSearchBase, this.authoritiesPopulator);
    mappingLdapAuthoritiesPopulator.setGroupSearchFilter(groupSearchFilter);
    mappingLdapAuthoritiesPopulator.setGroupRoleAttribute(groupRoleAttribute);
    // expect the LDAP group name for the role to be ROLE_<ROLE_NAME> where ROLE_NAME defined in UserRoles
    // Set the prefix to the empty string because the prefix is by default set to ROLE_ we don't want the populator to create ROLE_ROLE_<ROLE_NAME> due to the default prefix
    mappingLdapAuthoritiesPopulator.setRolePrefix("");
    return mappingLdapAuthoritiesPopulator;
}
 
Example 4
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {

	LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapConfigurer = auth.ldapAuthentication();

	ldapConfigurer.contextSource()
			.url(ldapSecurityProperties.getUrl().toString())
			.managerDn(ldapSecurityProperties.getManagerDn())
			.managerPassword(ldapSecurityProperties.getManagerPassword());

	if (!StringUtils.isEmpty(ldapSecurityProperties.getUserDnPattern())) {
		ldapConfigurer.userDnPatterns(ldapSecurityProperties.getUserDnPattern());
	}

	if (!StringUtils.isEmpty(ldapSecurityProperties.getUserSearchFilter())) {
		ldapConfigurer
				.userSearchBase(ldapSecurityProperties.getUserSearchBase())
				.userSearchFilter(ldapSecurityProperties.getUserSearchFilter());
	}

	if (!StringUtils.isEmpty(ldapSecurityProperties.getGroupSearchFilter())) {
		ldapConfigurer.groupSearchBase(ldapSecurityProperties.getGroupSearchBase())
				.groupSearchFilter(ldapSecurityProperties.getGroupSearchFilter())
				.groupRoleAttribute(ldapSecurityProperties.getGroupRoleAttribute());
	}
	else {
		ldapConfigurer.ldapAuthoritiesPopulator(new LdapAuthoritiesPopulator() {
			@Override
			public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) {
				return Collections.singleton(new SimpleGrantedAuthority("ROLE_ADMIN"));
			}
		});
	}

}
 
Example 5
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public LdapAuthenticationProvider authenticationProvider(BindAuthenticator ba,
                                                         LdapAuthoritiesPopulator lap,
                                                         UserDetailsContextMapper cm){
    return new LdapAuthenticationProvider(ba, lap){{
        setUserDetailsContextMapper(cm);
    }};
}
 
Example 6
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public LdapAuthenticationProvider authenticationProvider(BindAuthenticator ba,
                                                         LdapAuthoritiesPopulator lap,
                                                         UserDetailsContextMapper cm){
    return new LdapAuthenticationProvider(ba, lap){{
        setUserDetailsContextMapper(cm);
    }};
}
 
Example 7
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator(){
    return new DefaultLdapAuthoritiesPopulator(contextSource(),
            "ou=Groups"){{
                setGroupSearchFilter("(uniqueMember={0})");
    }};
}
 
Example 8
Source Project: apollo   Source File: ApolloLdapAuthenticationProvider.java    License: Apache License 2.0 5 votes vote down vote up
public ApolloLdapAuthenticationProvider(
    LdapAuthenticator authenticator,
    LdapAuthoritiesPopulator authoritiesPopulator,
    LdapExtendProperties properties) {
  super(authenticator, authoritiesPopulator);
  this.properties = properties;
}
 
Example 9
public CustomLdapAuthenticationProvider( LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator, DhisConfigurationProvider configurationProvider )
{
    super( authenticator, authoritiesPopulator );

    checkNotNull( configurationProvider );
    this.configurationProvider = configurationProvider;
}
 
Example 10
Source Project: osiam   Source File: OsiamLdapAuthenticationProvider.java    License: MIT License 5 votes vote down vote up
public OsiamLdapAuthenticationProvider(LdapAuthenticator authenticator,
                                       LdapAuthoritiesPopulator authoritiesPopulator,
                                       OsiamLdapUserContextMapper osiamLdapUserContextMapper,
                                       SCIMUserProvisioning userProvisioning,
                                       boolean syncUserData) {
    super(authenticator, authoritiesPopulator);
    this.osiamLdapUserContextMapper = osiamLdapUserContextMapper;
    this.userProvisioning = userProvisioning;
    this.syncUserData = syncUserData;
}
 
Example 11
Source Project: Kylin   Source File: LdapProvider.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param authenticator
 * @param authoritiesPopulator
 */
public LdapProvider(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) {
    super(authenticator, authoritiesPopulator);

    try {
        md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Failed to init Message Digest ", e);
    }
}
 
Example 12
Source Project: data-highway   Source File: LdapSecurityConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public LdapAuthenticationProvider authenticationProvider(
    BindAuthenticator bindAuthenticator,
    LdapAuthoritiesPopulator authoritiesPopulator) {
  return new LdapAuthenticationProvider(bindAuthenticator, authoritiesPopulator);
}
 
Example 13
Source Project: radman   Source File: SecurityConfiguration.java    License: MIT License 4 votes vote down vote up
@Bean
LdapAuthoritiesPopulator ldapAuthoritiesPopulator() {
    return new LocalLdapAuthoritiesPopulator(systemUserRepo);
}
 
Example 14
public LogsearchLdapAuthenticationProvider(LdapAuthenticator bindAuthenticator, LdapAuthoritiesPopulator ldapAuthoritiesPopulator) {
  super(bindAuthenticator, ldapAuthoritiesPopulator);
}
 
Example 15
Source Project: blackduck-alert   Source File: LdapManager.java    License: Apache License 2.0 4 votes vote down vote up
private LdapAuthenticationProvider updateAuthenticationProvider(FieldAccessor configurationModel, LdapContextSource contextSource) throws AlertConfigurationException {
    LdapAuthenticator authenticator = createAuthenticator(configurationModel, contextSource);
    LdapAuthoritiesPopulator ldapAuthoritiesPopulator = createAuthoritiesPopulator(configurationModel, contextSource);
    return new LdapAuthenticationProvider(authenticator, ldapAuthoritiesPopulator);
}
 
Example 16
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator(){
    return new ActiveDirectoryLdapAuthoritiesPopulator();
}
 
Example 17
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator(UserDetailsService userDetailsService){
    return new UserDetailsServiceLdapAuthoritiesPopulator(userDetailsService);
}
 
Example 18
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public LdapAuthenticationProvider authenticationProvider(BindAuthenticator ba,
                                                         LdapAuthoritiesPopulator lap){
    return new LdapAuthenticationProvider(ba, lap);
}
 
Example 19
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator(){
    return new ActiveDirectoryLdapAuthoritiesPopulator();
}
 
Example 20
Source Project: apollo   Source File: ApolloLdapAuthenticationProvider.java    License: Apache License 2.0 4 votes vote down vote up
public ApolloLdapAuthenticationProvider(
    LdapAuthenticator authenticator,
    LdapAuthoritiesPopulator authoritiesPopulator) {
  super(authenticator, authoritiesPopulator);
}
 
Example 21
@Bean
public LdapAuthoritiesPopulator ldapAuthoritiesPopulator() {
    return (dirContextOperations, s) -> null;
}
 
Example 22
public LdapAuthenticationProviderProxy(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) {
    super(authenticator, authoritiesPopulator);
}
 
Example 23
Source Project: unitime   Source File: SpringLdapAuthenticationProvider.java    License: Apache License 2.0 4 votes vote down vote up
public SpringLdapAuthenticationProvider(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) {
	super(authenticator, authoritiesPopulator);
}