use of org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder in project gravitee-management-rest-api by gravitee-io.
the class LdapAuthenticationProvider method configure.
@Override
public SecurityConfigurer configure() throws Exception {
LOGGER.info("Configuring an LDAP Identity Provider");
LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationProviderConfigurer = new LdapAuthenticationProviderConfigurer<>();
// Create LDAP context
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(environment.getProperty("context.url"));
contextSource.setBase(environment.getProperty("context.base"));
contextSource.setUserDn(environment.getProperty("context.username"));
contextSource.setPassword(environment.getProperty("context.password"));
contextSource.afterPropertiesSet();
ldapAuthenticationProviderConfigurer.userSearchBase(environment.getProperty("authentication.user.base", "")).userSearchFilter(environment.getProperty("authentication.user.filter")).groupSearchBase(environment.getProperty("authentication.group.base", "")).groupSearchFilter(environment.getProperty("authentication.group.filter", "(uniqueMember={0})")).groupRoleAttribute(environment.getProperty("authentication.group.role.attribute", "cn")).rolePrefix("");
DefaultLdapAuthoritiesPopulator populator = new DefaultLdapAuthoritiesPopulator(contextSource, environment.getProperty("authentication.group.base", ""));
populator.setRolePrefix("");
populator.setGroupRoleAttribute(environment.getProperty("authentication.group.role.attribute", "cn"));
populator.setGroupSearchFilter(environment.getProperty("authentication.group.filter", "(uniqueMember={0})"));
ldapAuthenticationProviderConfigurer.ldapAuthoritiesPopulator(populator).contextSource(contextSource);
// set up LDAP mapper
UserDetailsContextPropertiesMapper userDetailsContextPropertiesMapper = new UserDetailsContextPropertiesMapper();
userDetailsContextPropertiesMapper.setEnvironment(environment);
userDetailsContextPropertiesMapper.afterPropertiesSet();
ldapAuthenticationProviderConfigurer.userDetailsContextMapper(userDetailsContextPropertiesMapper);
return ldapAuthenticationProviderConfigurer;
}
use of org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder in project gravitee-management-rest-api by gravitee-io.
the class BasicSecurityConfigurerAdapter method configure.
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
LOGGER.info("--------------------------------------------------------------");
LOGGER.info("Portal API BasicSecurity Config");
LOGGER.info("Loading authentication identity providers for Basic authentication");
List<io.gravitee.rest.api.security.authentication.AuthenticationProvider> providers = authenticationProviderManager.getIdentityProviders().stream().filter(authenticationProvider -> !authenticationProvider.external()).collect(Collectors.toList());
for (AuthenticationProvider provider : providers) {
String providerType = provider.type();
LOGGER.info("Loading authentication provider of type {} at position {}", providerType, provider.index());
Collection<IdentityProvider> identityProviders = identityProviderManager.getAll();
if (identityProviders != null) {
Optional<io.gravitee.rest.api.idp.api.authentication.AuthenticationProvider> authenticationProviderPlugin = identityProviders.stream().filter(ip -> ip.type().equalsIgnoreCase(providerType)).map(ip -> identityProviderManager.loadIdentityProvider(ip.type(), provider.configuration())).filter(Objects::nonNull).findFirst();
if (authenticationProviderPlugin.isPresent()) {
Object authenticationProvider = authenticationProviderPlugin.get().configure();
if (authenticationProvider instanceof org.springframework.security.authentication.AuthenticationProvider) {
auth.authenticationProvider((org.springframework.security.authentication.AuthenticationProvider) authenticationProvider);
} else if (authenticationProvider instanceof SecurityConfigurer) {
auth.apply((SecurityConfigurer) authenticationProvider);
}
} else {
LOGGER.error("No authentication provider found for type: {}", providerType);
}
}
}
LOGGER.info("--------------------------------------------------------------");
}
Aggregations