@Test public void shouldLoadUserByUsername_authentication_usernameNotFound() { Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn("username"); when(userDetailsService.loadUserByUsername("username")).thenReturn(Maybe.error(new UsernameNotFoundException("username"))); TestObserver<User> testObserver = inlineAuthenticationProvider.loadUserByUsername(authentication).test(); testObserver.assertError(UsernameNotFoundException.class); }
@Override public Maybe<User> loadUserByUsername(Authentication authentication) { return userDetailsService.loadUserByUsername((String) authentication.getPrincipal()) .map(user -> { String presentedPassword = authentication.getCredentials().toString(); if (!passwordEncoder.matches(presentedPassword, user.getPassword())) { LOGGER.debug("Authentication failed: password does not match stored value"); throw new BadCredentialsException("Bad credentials"); } return createUser(user); }); }
InlineAuthenticationProvider implements AuthenticationProvider, InitializingBean { @Override public Maybe<User> loadUserByUsername(Authentication authentication) { return userDetailsService.loadUserByUsername((String) authentication.getPrincipal()) .map(user -> { String presentedPassword = authentication.getCredentials().toString(); if (!passwordEncoder.matches(presentedPassword, user.getPassword())) { LOGGER.debug("Authentication failed: password does not match stored value"); throw new BadCredentialsException("Bad credentials"); } return createUser(user); }); } }
InlineAuthenticationProvider implements AuthenticationProvider, InitializingBean { @Override public Maybe<User> loadUserByUsername(Authentication authentication) { return userDetailsService.loadUserByUsername((String) authentication.getPrincipal()) .map(user -> { String presentedPassword = authentication.getCredentials().toString(); if (!passwordEncoder.matches(presentedPassword, user.getPassword())) { LOGGER.debug("Authentication failed: password does not match stored value"); throw new BadCredentialsException("Bad credentials"); } return createUser(user); }); }  }
InlineAuthenticationProvider implements AuthenticationProvider, InitializingBean { @Override public Maybe<User> loadUserByUsername(Authentication authentication) { return userDetailsService.loadUserByUsername((String) authentication.getPrincipal()) .map(user -> { String presentedPassword = authentication.getCredentials().toString(); if (!passwordEncoder.matches(presentedPassword, user.getPassword())) { LOGGER.debug("Authentication failed: password does not match stored value"); throw new BadCredentialsException("Bad credentials"); } return createUser(user); }); }  @Override void afterPropertiesSet(); @Override Maybe<User> loadUserByUsername(Authentication authentication); @Override Maybe<User> loadUserByUsername(String username); }
InlineAuthenticationProvider implements AuthenticationProvider, InitializingBean { @Override public Maybe<User> loadUserByUsername(Authentication authentication) { return userDetailsService.loadUserByUsername((String) authentication.getPrincipal()) .map(user -> { String presentedPassword = authentication.getCredentials().toString(); if (!passwordEncoder.matches(presentedPassword, user.getPassword())) { LOGGER.debug("Authentication failed: password does not match stored value"); throw new BadCredentialsException("Bad credentials"); } return createUser(user); }); }  @Override void afterPropertiesSet(); @Override Maybe<User> loadUserByUsername(Authentication authentication); @Override Maybe<User> loadUserByUsername(String username);  }