private static OneTimePasswordAuthenticationProvider createProvider(boolean loginOtp, boolean extAuthOtp) { SecurityConfigurationProperties properties = createMockProperties(loginOtp, extAuthOtp); UserDetailsService userDetailsService = Mockito.mock(UserDetailsService.class); Mockito.when(userDetailsService.loadUserByUsername(ArgumentMatchers.eq(USER))).thenReturn( new User(USER, USER, AuthorityUtils.createAuthorityList("ROLE_USER"))); Mockito.when(userDetailsService.loadUserByUsername(ArgumentMatchers.eq(ADMIN))).thenReturn( new User(ADMIN, ADMIN, AuthorityUtils.createAuthorityList("ROLE_ADMIN"))); Mockito.when(userDetailsService.loadUserByUsername(ArgumentMatchers.eq(MODERATOR))).thenReturn( new User(MODERATOR, MODERATOR, AuthorityUtils.createAuthorityList("ROLE_MODERATOR"))); OneTimePasswordAuthenticationProvider provider = new OneTimePasswordAuthenticationProvider(); provider.setSecurityConfigurationProperties(properties); provider.setUserDetailsService(userDetailsService); provider.setPasswordEncoder(new PlaintextPasswordEncoder()); OneTimePasswordCodeService codeService = new OneTimePasswordCodeService(properties); ReflectionTestUtils.setField(provider, "oneTimePasswordCodeService", codeService); return provider; }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { KonkerDaoAuthenticationProvider authenticationProvider = new KonkerDaoAuthenticationProvider(); authenticationProvider.setLoginAuditService(loginAuditService); authenticationProvider.setUserDetailsService(userDetailsService); authenticationProvider.setPasswordEncoder(new PlaintextPasswordEncoder() { @Override public boolean isPasswordValid(String encPass, String rawPass, Object salt) { try { Random random = new Random(); Boolean result = new PasswordManager().validatePassword(rawPass, encPass); // Delay time introduced to prevent user enumeration attack int delayTime = random.nextInt(MAX_DELAY_TIME - MIN_DELAY_TIME) + MIN_DELAY_TIME; Thread.sleep(delayTime); return result; } catch (NoSuchAlgorithmException | InvalidKeySpecException | InterruptedException e) { LOGGER.error(e.getMessage(), e); return false; } } }); auth.authenticationProvider(authenticationProvider); }
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider(); authenticationProvider.setUserDetailsService(detailsService); authenticationProvider.setPasswordEncoder(new PlaintextPasswordEncoder() { @Override public boolean isPasswordValid(String encPass, String rawPass, Object salt) { try { return new PasswordManager().validatePassword(rawPass, encPass); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { LOGGER.error(e.getMessage(), e); return false; } } }); auth.authenticationProvider(authenticationProvider); }
@Autowired public void configure(AuthenticationManagerBuilder auth) throws Exception { PlaintextPasswordEncoder passwordEncoder = new PlaintextPasswordEncoder(); passwordEncoder.setIgnorePasswordCase(true); CustomAuthenticationProvider provider = new CustomAuthenticationProvider(); provider.setPasswordEncoder(passwordEncoder); provider.setUserDetailsService(userDetailsService()); auth.authenticationProvider(provider); }
@Bean protected AuthenticationManager authenticationManager() throws Exception { return new AuthenticationManagerBuilder(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR) .authenticationProvider(autoLoginAuthenticationProvider) // auto login .userDetailsService(userDetailService) .passwordEncoder(new PlaintextPasswordEncoder()) .and().build(); // user detail }
public static BasePasswordEncoder passwordEncoder() { return new PlaintextPasswordEncoder(); }
/** * @return */ public PasswordCompareConfigurer passwordCompare() { return new PasswordCompareConfigurer().passwordAttribute("password") .passwordEncoder(new PlaintextPasswordEncoder()); }