private BaseLdapPathContextSource getContextSource() throws Exception { if (contextSource == null) { contextSource = contextSourceBuilder.build(); } return contextSource; }
/** * Adds an {@link ObjectPostProcessor} for this class. * * @param objectPostProcessor * @return the {@link ChannelSecurityConfigurer} for further customizations */ public LdapAuthenticationProviderConfigurer<B> withObjectPostProcessor( ObjectPostProcessor<?> objectPostProcessor) { addObjectPostProcessor(objectPostProcessor); return this; }
/** * @return the {@link PasswordCompareConfigurer} for further customizations */ public PasswordCompareConfigurer passwordCompare() { return new PasswordCompareConfigurer().passwordAttribute("password") .passwordEncoder(NoOpPasswordEncoder.getInstance()); } }
LOG.debug("Setting up LDAP authentication against {}.", providerUrl); auth.ldapAuthentication() .userDnPatterns(userDnPatterns) .userSearchBase(userSearchBase) .userSearchFilter(userSearchFilter) .groupRoleAttribute(groupRoleAttribute) .groupSearchFilter(groupSearchFilter) .groupSearchBase(groupSearchBase) .contextSource() .url(providerUrl) .managerDn(providerUserDn) .managerPassword(providerPassword) .and() .passwordCompare() .passwordEncoder(new LdapShaPasswordEncoder()) .passwordAttribute(passwordAttribute); } else if (activeProfiles.contains(MetronRestConstants.DEV_PROFILE) || activeProfiles.contains(MetronRestConstants.TEST_PROFILE)) {
/** * Creates the {@link LdapAuthenticator} to use * * @param contextSource the {@link BaseLdapPathContextSource} to use * @return the {@link LdapAuthenticator} to use */ private LdapAuthenticator createLdapAuthenticator( BaseLdapPathContextSource contextSource) { AbstractLdapAuthenticator ldapAuthenticator = passwordEncoder == null ? createBindAuthenticator(contextSource) : createPasswordCompareAuthenticator(contextSource); LdapUserSearch userSearch = createUserSearch(); if (userSearch != null) { ldapAuthenticator.setUserSearch(userSearch); } if (userDnPatterns != null && userDnPatterns.length > 0) { ldapAuthenticator.setUserDnPatterns(userDnPatterns); } return postProcess(ldapAuthenticator); }
private LdapAuthenticationProvider build() throws Exception { BaseLdapPathContextSource contextSource = getContextSource(); LdapAuthenticator ldapAuthenticator = createLdapAuthenticator(contextSource); LdapAuthoritiesPopulator authoritiesPopulator = getLdapAuthoritiesPopulator(); LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider( ldapAuthenticator, authoritiesPopulator); ldapAuthenticationProvider.setAuthoritiesMapper(getAuthoritiesMapper()); if (userDetailsContextMapper != null) { ldapAuthenticationProvider .setUserDetailsContextMapper(userDetailsContextMapper); } return ldapAuthenticationProvider; }
@Override public void configure(B builder) throws Exception { LdapAuthenticationProvider provider = postProcess(build()); builder.authenticationProvider(provider); }
/** * Add LDAP authentication to the {@link AuthenticationManagerBuilder} and return a * {@link LdapAuthenticationProviderConfigurer} to allow customization of the LDAP * authentication. * * <p> * This method <b>does NOT</b> ensure that a {@link UserDetailsService} is available * for the {@link #getDefaultUserDetailsService()} method. * * @return a {@link LdapAuthenticationProviderConfigurer} to allow customization of * the LDAP authentication * @throws Exception if an error occurs when adding the LDAP authentication */ public LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthentication() throws Exception { return apply(new LdapAuthenticationProviderConfigurer<>()); }
@Test public void getAuthoritiesMapper() throws Exception { assertThat(configurer.getAuthoritiesMapper()).isInstanceOf(SimpleAuthorityMapper.class); configurer.authoritiesMapper(new NullAuthoritiesMapper()); assertThat(configurer.getAuthoritiesMapper()).isInstanceOf(NullAuthoritiesMapper.class); } }
/** * @return the {@link PasswordCompareConfigurer} for further customizations */ public PasswordCompareConfigurer passwordCompare() { return new PasswordCompareConfigurer().passwordAttribute("password") .passwordEncoder(NoOpPasswordEncoder.getInstance()); } }
/** * Creates the {@link LdapAuthenticator} to use * * @param contextSource the {@link BaseLdapPathContextSource} to use * @return the {@link LdapAuthenticator} to use */ private LdapAuthenticator createLdapAuthenticator( BaseLdapPathContextSource contextSource) { AbstractLdapAuthenticator ldapAuthenticator = passwordEncoder == null ? createBindAuthenticator(contextSource) : createPasswordCompareAuthenticator(contextSource); LdapUserSearch userSearch = createUserSearch(); if (userSearch != null) { ldapAuthenticator.setUserSearch(userSearch); } if (userDnPatterns != null && userDnPatterns.length > 0) { ldapAuthenticator.setUserDnPatterns(userDnPatterns); } return postProcess(ldapAuthenticator); }
private LdapAuthenticationProvider build() throws Exception { BaseLdapPathContextSource contextSource = getContextSource(); LdapAuthenticator ldapAuthenticator = createLdapAuthenticator(contextSource); LdapAuthoritiesPopulator authoritiesPopulator = getLdapAuthoritiesPopulator(); LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider( ldapAuthenticator, authoritiesPopulator); ldapAuthenticationProvider.setAuthoritiesMapper(getAuthoritiesMapper()); if (userDetailsContextMapper != null) { ldapAuthenticationProvider .setUserDetailsContextMapper(userDetailsContextMapper); } return ldapAuthenticationProvider; }
@Override public void configure(B builder) throws Exception { LdapAuthenticationProvider provider = postProcess(build()); builder.authenticationProvider(provider); }
@Before public void setUp() { configurer = new LdapAuthenticationProviderConfigurer<>(); }
private BaseLdapPathContextSource getContextSource() throws Exception { if (contextSource == null) { contextSource = contextSourceBuilder.build(); } return contextSource; }
/** * Adds an {@link ObjectPostProcessor} for this class. * * @param objectPostProcessor * @return the {@link ChannelSecurityConfigurer} for further customizations */ public LdapAuthenticationProviderConfigurer<B> withObjectPostProcessor( ObjectPostProcessor<?> objectPostProcessor) { addObjectPostProcessor(objectPostProcessor); return this; }
/** * Add LDAP authentication to the {@link AuthenticationManagerBuilder} and return a * {@link LdapAuthenticationProviderConfigurer} to allow customization of the LDAP * authentication. * * <p> * This method <b>does NOT</b> ensure that a {@link UserDetailsService} is available * for the {@link #getDefaultUserDetailsService()} method. * * @return a {@link LdapAuthenticationProviderConfigurer} to allow customization of * the LDAP authentication * @throws Exception if an error occurs when adding the LDAP authentication */ public LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthentication() throws Exception { return apply(new LdapAuthenticationProviderConfigurer<>()); }
private BaseLdapPathContextSource getContextSource() throws Exception { if (contextSource == null) { contextSource = contextSourceBuilder.build(); } return contextSource; }
/** * Adds an {@link ObjectPostProcessor} for this class. * * @param objectPostProcessor * @return the {@link ChannelSecurityConfigurer} for further customizations */ public LdapAuthenticationProviderConfigurer<B> withObjectPostProcessor( ObjectPostProcessor<?> objectPostProcessor) { addObjectPostProcessor(objectPostProcessor); return this; }
private BaseLdapPathContextSource getContextSource() throws Exception { if(contextSource == null) { contextSource = contextSourceBuilder.build(); } return contextSource; }