@Test public void testUsernameCanBeExtractedFromTokenClaims() { when(claims.getSubject()).thenReturn(USERNAME); assertThat(jwtUtils.getUsernameFromTokenClaims(claims)).isEqualTo(USERNAME); verify(claims, times(1)).getSubject(); }
public String getUsernameFromTokenClaims(Claims claims) { try { final String username = claims.getSubject(); if (username == null) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return username; } catch (Exception e) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg, e); } }
JwtUtils { public String getUsernameFromTokenClaims(Claims claims) { try { final String username = claims.getSubject(); if (username == null) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return username; } catch (Exception e) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg, e); } } }
JwtUtils { public String getUsernameFromTokenClaims(Claims claims) { try { final String username = claims.getSubject(); if (username == null) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return username; } catch (Exception e) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg, e); } }  }
JwtUtils { public String getUsernameFromTokenClaims(Claims claims) { try { final String username = claims.getSubject(); if (username == null) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return username; } catch (Exception e) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg, e); } }  Claims validateTokenAndGetClaims(String token); String createToken(JwtUser userDetails); boolean canTokenBeRefreshed(Claims claims, Date lastPasswordReset); String refreshToken(String token); String getUsernameFromTokenClaims(Claims claims); List<GrantedAuthority> getRolesFromTokenClaims(Claims claims); }
JwtUtils { public String getUsernameFromTokenClaims(Claims claims) { try { final String username = claims.getSubject(); if (username == null) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg); } return username; } catch (Exception e) { final String errorMsg = "Failed to extract username claim from token!"; LOG.error(errorMsg); throw new JwtAuthenticationException(errorMsg, e); } }  Claims validateTokenAndGetClaims(String token); String createToken(JwtUser userDetails); boolean canTokenBeRefreshed(Claims claims, Date lastPasswordReset); String refreshToken(String token); String getUsernameFromTokenClaims(Claims claims); List<GrantedAuthority> getRolesFromTokenClaims(Claims claims);  }