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

The following examples show how to use org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator. 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 File: WebSecurityConfig.java    From taskana with 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 File: WebSecurityConfig.java    From taskana with 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 File: SecurityConfig.java    From Spring-Security-Third-Edition with 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 #4
Source File: LdapProvider.java    From Kylin with 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 #5
Source File: OsiamLdapAuthenticationProvider.java    From osiam with 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 #6
Source File: CustomLdapAuthenticationProvider.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public CustomLdapAuthenticationProvider( LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator, DhisConfigurationProvider configurationProvider )
{
    super( authenticator, authoritiesPopulator );

    checkNotNull( configurationProvider );
    this.configurationProvider = configurationProvider;
}
 
Example #7
Source File: ApolloLdapAuthenticationProvider.java    From apollo with 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 #8
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator(){
    return new DefaultLdapAuthoritiesPopulator(contextSource(),
            "ou=Groups"){{
                setGroupSearchFilter("(uniqueMember={0})");
    }};
}
 
Example #9
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with 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 #10
Source File: LdapAuthenticationConfiguration.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: LdapManager.java    From blackduck-alert with 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 #12
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator(){
    return new ActiveDirectoryLdapAuthoritiesPopulator();
}
 
Example #13
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator(UserDetailsService userDetailsService){
    return new UserDetailsServiceLdapAuthoritiesPopulator(userDetailsService);
}
 
Example #14
Source File: LdapSecurityConfiguration.java    From data-highway with Apache License 2.0 4 votes vote down vote up
@Bean
public LdapAuthenticationProvider authenticationProvider(
    BindAuthenticator bindAuthenticator,
    LdapAuthoritiesPopulator authoritiesPopulator) {
  return new LdapAuthenticationProvider(bindAuthenticator, authoritiesPopulator);
}
 
Example #15
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public LdapAuthenticationProvider authenticationProvider(BindAuthenticator ba,
                                                         LdapAuthoritiesPopulator lap){
    return new LdapAuthenticationProvider(ba, lap);
}
 
Example #16
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator authoritiesPopulator(){
    return new ActiveDirectoryLdapAuthoritiesPopulator();
}
 
Example #17
Source File: ApolloLdapAuthenticationProvider.java    From apollo with Apache License 2.0 4 votes vote down vote up
public ApolloLdapAuthenticationProvider(
    LdapAuthenticator authenticator,
    LdapAuthoritiesPopulator authoritiesPopulator) {
  super(authenticator, authoritiesPopulator);
}
 
Example #18
Source File: WebTestConfiguration.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Bean
public LdapAuthoritiesPopulator ldapAuthoritiesPopulator() {
    return (dirContextOperations, s) -> null;
}
 
Example #19
Source File: LdapManager.java    From blackduck-alert with 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 #20
Source File: LdapAuthenticationProviderProxy.java    From gravitee-management-rest-api with Apache License 2.0 4 votes vote down vote up
public LdapAuthenticationProviderProxy(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) {
    super(authenticator, authoritiesPopulator);
}
 
Example #21
Source File: LogsearchLdapAuthenticationProvider.java    From ambari-logsearch with Apache License 2.0 4 votes vote down vote up
public LogsearchLdapAuthenticationProvider(LdapAuthenticator bindAuthenticator, LdapAuthoritiesPopulator ldapAuthoritiesPopulator) {
  super(bindAuthenticator, ldapAuthoritiesPopulator);
}
 
Example #22
Source File: SpringLdapAuthenticationProvider.java    From unitime with Apache License 2.0 4 votes vote down vote up
public SpringLdapAuthenticationProvider(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) {
	super(authenticator, authoritiesPopulator);
}
 
Example #23
Source File: SecurityConfiguration.java    From radman with MIT License 4 votes vote down vote up
@Bean
LdapAuthoritiesPopulator ldapAuthoritiesPopulator() {
    return new LocalLdapAuthoritiesPopulator(systemUserRepo);
}