@Test public void shouldAuthenticateValidUsernamePassword() { when(gatewaySecurityService.login(USER, VALID_PASSWORD)).thenReturn(Optional.of(VALID_TOKEN)); Authentication auth = new UsernamePasswordAuthenticationToken(USER, VALID_PASSWORD); Authentication processedAuthentication = gatewayLoginProvider.authenticate(auth); assertTrue(processedAuthentication instanceof TokenAuthentication); assertTrue(processedAuthentication.isAuthenticated()); assertEquals(VALID_TOKEN, processedAuthentication.getCredentials()); assertEquals(USER, processedAuthentication.getName()); }
@Override public Authentication authenticate(Authentication authentication) { String username = authentication.getPrincipal().toString(); Optional<String> token = gatewaySecurityService.login(username, authentication.getCredentials().toString()); if (!token.isPresent()) { throw new BadCredentialsException("Username or password are invalid."); } TokenAuthentication tokenAuthentication = new TokenAuthentication(username, token.get()); tokenAuthentication.setAuthenticated(true); return tokenAuthentication; }
GatewayLoginProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { String username = authentication.getPrincipal().toString(); Optional<String> token = gatewaySecurityService.login(username, authentication.getCredentials().toString()); if (!token.isPresent()) { throw new BadCredentialsException("Username or password are invalid."); } TokenAuthentication tokenAuthentication = new TokenAuthentication(username, token.get()); tokenAuthentication.setAuthenticated(true); return tokenAuthentication; } }
GatewayLoginProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { String username = authentication.getPrincipal().toString(); Optional<String> token = gatewaySecurityService.login(username, authentication.getCredentials().toString()); if (!token.isPresent()) { throw new BadCredentialsException("Username or password are invalid."); } TokenAuthentication tokenAuthentication = new TokenAuthentication(username, token.get()); tokenAuthentication.setAuthenticated(true); return tokenAuthentication; }  }
GatewayLoginProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { String username = authentication.getPrincipal().toString(); Optional<String> token = gatewaySecurityService.login(username, authentication.getCredentials().toString()); if (!token.isPresent()) { throw new BadCredentialsException("Username or password are invalid."); } TokenAuthentication tokenAuthentication = new TokenAuthentication(username, token.get()); tokenAuthentication.setAuthenticated(true); return tokenAuthentication; }  @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> auth); }
GatewayLoginProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { String username = authentication.getPrincipal().toString(); Optional<String> token = gatewaySecurityService.login(username, authentication.getCredentials().toString()); if (!token.isPresent()) { throw new BadCredentialsException("Username or password are invalid."); } TokenAuthentication tokenAuthentication = new TokenAuthentication(username, token.get()); tokenAuthentication.setAuthenticated(true); return tokenAuthentication; }  @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> auth);  }