@Test public void testGetUsernameNoSubject() { Date d = generateValidDate(); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertNull(jwtService.getUsername(compactJws, SECRET)); }
public String getUsername(String token, String secret) { if(StringUtils.hasText(token) && StringUtils.hasText(secret)) { try { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); return Jwts.parser().setSigningKey(secret2).parseClaimsJws(token).getBody().getSubject(); } catch (JwtException e) { LOGGER.error(e.getMessage()); } } return null; }
JwtService { public String getUsername(String token, String secret) { if(StringUtils.hasText(token) && StringUtils.hasText(secret)) { try { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); return Jwts.parser().setSigningKey(secret2).parseClaimsJws(token).getBody().getSubject(); } catch (JwtException e) { LOGGER.error(e.getMessage()); } } return null; } }
JwtService { public String getUsername(String token, String secret) { if(StringUtils.hasText(token) && StringUtils.hasText(secret)) { try { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); return Jwts.parser().setSigningKey(secret2).parseClaimsJws(token).getBody().getSubject(); } catch (JwtException e) { LOGGER.error(e.getMessage()); } } return null; }  }
JwtService { public String getUsername(String token, String secret) { if(StringUtils.hasText(token) && StringUtils.hasText(secret)) { try { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); return Jwts.parser().setSigningKey(secret2).parseClaimsJws(token).getBody().getSubject(); } catch (JwtException e) { LOGGER.error(e.getMessage()); } } return null; }  String createToken(String username, String secret, Date expireAt); boolean isValid(String token, String secret); String getUsername(String token, String secret); }
JwtService { public String getUsername(String token, String secret) { if(StringUtils.hasText(token) && StringUtils.hasText(secret)) { try { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); return Jwts.parser().setSigningKey(secret2).parseClaimsJws(token).getBody().getSubject(); } catch (JwtException e) { LOGGER.error(e.getMessage()); } } return null; }  String createToken(String username, String secret, Date expireAt); boolean isValid(String token, String secret); String getUsername(String token, String secret);  }