org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer Java Examples
The following examples show how to use
org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.
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 mojito with Apache License 2.0 | 6 votes |
void configureLdap(AuthenticationManagerBuilder auth) throws Exception { logger.debug("Configuring ldap server"); LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder>.ContextSourceBuilder contextSourceBuilder = auth.ldapAuthentication() .userSearchBase(ldapConfig.getUserSearchBase()) .userSearchFilter(ldapConfig.getUserSearchFilter()) .groupSearchBase(ldapConfig.getGroupSearchBase()) .groupSearchFilter(ldapConfig.getGroupSearchFilter()) .groupRoleAttribute(ldapConfig.getGroupRoleAttribute()) .userDetailsContextMapper(userDetailsContextMapperImpl) .contextSource(); if (ldapConfig.getPort() != null) { contextSourceBuilder.port(ldapConfig.getPort()); } contextSourceBuilder .root(ldapConfig.getRoot()) .url(ldapConfig.getUrl()) .managerDn(ldapConfig.getManagerDn()) .managerPassword(ldapConfig.getManagerPassword()) .ldif(ldapConfig.getLdif()); }
Example #2
Source File: LdapAuthenticationConfiguration.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
@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 #3
Source File: WebSecurityConfig.java From metron with Apache License 2.0 | 4 votes |
@Autowired public void configureJdbc(AuthenticationManagerBuilder auth) throws Exception { // Note that we can switch profiles on the fly in Ambari. List<String> activeProfiles = Arrays.asList(environment.getActiveProfiles()); if (activeProfiles.contains(MetronRestConstants.LDAP_PROFILE)) { LOG.info("Setting up LDAP authentication; url={}.", providerUrl); LdapAuthenticationProviderConfigurer providerConf = auth .ldapAuthentication() .authoritiesMapper(authoritiesMapper) .userDnPatterns(userDnPatterns) .userSearchBase(userSearchBase) .userSearchFilter(userSearchFilter) .groupRoleAttribute(groupRoleAttribute) .groupSearchFilter(groupSearchFilter) .groupSearchBase(groupSearchBase) .contextSource() .url(providerUrl) .managerDn(providerUserDn) .managerPassword(providerPassword) .and(); if(StringUtils.isNotBlank(passwordAttribute)) { // if a password attribute is provided, use that for authentication providerConf .passwordCompare() .passwordEncoder(new LdapShaPasswordEncoder()) .passwordAttribute(passwordAttribute); } else { // if no password attribute, set encoder to null which forces bind authentication providerConf .passwordCompare() .passwordEncoder(null); } } else if (activeProfiles.contains(MetronRestConstants.DEV_PROFILE) || activeProfiles.contains(MetronRestConstants.TEST_PROFILE)) { LOG.info("Setting up JDBC authentication with dev/test profiles"); auth.jdbcAuthentication() .dataSource(dataSource) .withUser("user").password("password").roles(SECURITY_ROLE_USER).and() .withUser("user1").password("password").roles(SECURITY_ROLE_USER).and() .withUser("user2").password("password").roles(SECURITY_ROLE_USER).and() .withUser("admin").password("password").roles(SECURITY_ROLE_USER, SECURITY_ROLE_ADMIN); } else { LOG.debug("Setting up JDBC authentication"); auth.jdbcAuthentication().dataSource(dataSource); } }