@Test void authenticateInvalidToken() { when(tokenService.findUserByToken("token")) .thenThrow(new UnknownTokenException("Invalid token")); assertThrows( AuthenticationException.class, () -> tokenAuthenticationProvider.authenticate(new RestAuthenticationToken("token"))); }
@Override @RunAsSystem public Authentication authenticate(Authentication authentication) { if (!supports(authentication.getClass())) throw new IllegalArgumentException("Only RestAuthenticationToken is supported"); RestAuthenticationToken authToken = (RestAuthenticationToken) authentication; if (authToken.getToken() != null) { UserDetails userDetails = tokenService.findUserByToken(authToken.getToken()); userDetailsChecker.check(userDetails); authToken = new RestAuthenticationToken( userDetails, userDetails.getPassword(), userDetails.getAuthorities(), authToken.getToken()); } return authToken; }
TokenAuthenticationProvider implements AuthenticationProvider { @Override @RunAsSystem public Authentication authenticate(Authentication authentication) { if (!supports(authentication.getClass())) throw new IllegalArgumentException("Only RestAuthenticationToken is supported"); RestAuthenticationToken authToken = (RestAuthenticationToken) authentication; if (authToken.getToken() != null) { UserDetails userDetails = tokenService.findUserByToken(authToken.getToken()); userDetailsChecker.check(userDetails); authToken = new RestAuthenticationToken( userDetails, userDetails.getPassword(), userDetails.getAuthorities(), authToken.getToken()); } return authToken; } }
TokenAuthenticationProvider implements AuthenticationProvider { @Override @RunAsSystem public Authentication authenticate(Authentication authentication) { if (!supports(authentication.getClass())) throw new IllegalArgumentException("Only RestAuthenticationToken is supported"); RestAuthenticationToken authToken = (RestAuthenticationToken) authentication; if (authToken.getToken() != null) { UserDetails userDetails = tokenService.findUserByToken(authToken.getToken()); userDetailsChecker.check(userDetails); authToken = new RestAuthenticationToken( userDetails, userDetails.getPassword(), userDetails.getAuthorities(), authToken.getToken()); } return authToken; } TokenAuthenticationProvider(
      TokenService tokenService, UserDetailsChecker userDetailsChecker); }
TokenAuthenticationProvider implements AuthenticationProvider { @Override @RunAsSystem public Authentication authenticate(Authentication authentication) { if (!supports(authentication.getClass())) throw new IllegalArgumentException("Only RestAuthenticationToken is supported"); RestAuthenticationToken authToken = (RestAuthenticationToken) authentication; if (authToken.getToken() != null) { UserDetails userDetails = tokenService.findUserByToken(authToken.getToken()); userDetailsChecker.check(userDetails); authToken = new RestAuthenticationToken( userDetails, userDetails.getPassword(), userDetails.getAuthorities(), authToken.getToken()); } return authToken; } TokenAuthenticationProvider(
      TokenService tokenService, UserDetailsChecker userDetailsChecker); @Override @RunAsSystem Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication); }
TokenAuthenticationProvider implements AuthenticationProvider { @Override @RunAsSystem public Authentication authenticate(Authentication authentication) { if (!supports(authentication.getClass())) throw new IllegalArgumentException("Only RestAuthenticationToken is supported"); RestAuthenticationToken authToken = (RestAuthenticationToken) authentication; if (authToken.getToken() != null) { UserDetails userDetails = tokenService.findUserByToken(authToken.getToken()); userDetailsChecker.check(userDetails); authToken = new RestAuthenticationToken( userDetails, userDetails.getPassword(), userDetails.getAuthorities(), authToken.getToken()); } return authToken; } TokenAuthenticationProvider(
      TokenService tokenService, UserDetailsChecker userDetailsChecker); @Override @RunAsSystem Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication);  }