@Test public void shouldLoadUserByUsername_authentication() { Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn("username"); when(authentication.getCredentials()).thenReturn("password"); io.gravitee.am.identityprovider.inline.model.User user = mock(io.gravitee.am.identityprovider.inline.model.User.class); when(user.getUsername()).thenReturn("username"); when(user.getPassword()).thenReturn("password"); when(userDetailsService.loadUserByUsername("username")).thenReturn(Maybe.just(user)); when(passwordEncoder.matches((String) authentication.getCredentials(), user.getPassword())).thenReturn(true); TestObserver<User> testObserver = inlineAuthenticationProvider.loadUserByUsername(authentication).test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete(); testObserver.assertNoErrors(); testObserver.assertValue(u -> "username".equals(u.getUsername())); }
@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);  }