@Test(expected = Exception.class) public void authenticateWithMalformedAccessToken() { when(jwtTool.getAccessTokenKey()).thenReturn("123123123"); Authentication authentication = new UsernamePasswordAuthenticationToken( "Malformed" + ".eyJzdWIiOiJ0ZXN0QGdtYWlsLmNvbSIsImF1dGhvcml0aWVzIjpbIlJPTEVfVVNFUiJdLCJpYXQiOjE1Nz" + "U4Mzk3OTMsImV4cCI6MTU3NTg0MDY5M30" + ".DYna1ycZd7eaUBrXKGzYvEMwcybe7l5YiliOR-LfyRw", null ); jwtAuthenticationProvider.authenticate(authentication); }
@Override public Authentication authenticate(Authentication authentication) { String email = Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .getSubject(); @SuppressWarnings({"unchecked, rawtype"}) List<String> authorities = (List<String>) Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .get(AUTHORITIES); return new UsernamePasswordAuthenticationToken( email, "", authorities.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()) ); }
JwtAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { String email = Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .getSubject(); @SuppressWarnings({"unchecked, rawtype"}) List<String> authorities = (List<String>) Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .get(AUTHORITIES); return new UsernamePasswordAuthenticationToken( email, "", authorities.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()) ); } }
JwtAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { String email = Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .getSubject(); @SuppressWarnings({"unchecked, rawtype"}) List<String> authorities = (List<String>) Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .get(AUTHORITIES); return new UsernamePasswordAuthenticationToken( email, "", authorities.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()) ); } JwtAuthenticationProvider(JwtTool jwtTool); }
JwtAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { String email = Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .getSubject(); @SuppressWarnings({"unchecked, rawtype"}) List<String> authorities = (List<String>) Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .get(AUTHORITIES); return new UsernamePasswordAuthenticationToken( email, "", authorities.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()) ); } JwtAuthenticationProvider(JwtTool jwtTool); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication); }
JwtAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { String email = Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .getSubject(); @SuppressWarnings({"unchecked, rawtype"}) List<String> authorities = (List<String>) Jwts.parser() .setSigningKey(jwtTool.getAccessTokenKey()) .parseClaimsJws(authentication.getName()) .getBody() .get(AUTHORITIES); return new UsernamePasswordAuthenticationToken( email, "", authorities.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()) ); } JwtAuthenticationProvider(JwtTool jwtTool); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication);  }