@Test public void testCreateTokenEmptySecret() { assertNull(jwtService.createToken(USERNAME, null, generateValidDate())); assertNull(jwtService.createToken(USERNAME, "", generateValidDate())); assertNull(jwtService.createToken(USERNAME, " ", generateValidDate())); }
public String createToken(String username, String secret, Date expireAt) { if(StringUtils.hasText(username) && StringUtils.hasText(secret) && expireAt != null && expireAt.after(new Date()) ) { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); String compactJws = Jwts.builder() .setSubject(username) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(expireAt) .compact(); return compactJws; } return null; }
JwtService { public String createToken(String username, String secret, Date expireAt) { if(StringUtils.hasText(username) && StringUtils.hasText(secret) && expireAt != null && expireAt.after(new Date()) ) { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); String compactJws = Jwts.builder() .setSubject(username) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(expireAt) .compact(); return compactJws; } return null; } }
JwtService { public String createToken(String username, String secret, Date expireAt) { if(StringUtils.hasText(username) && StringUtils.hasText(secret) && expireAt != null && expireAt.after(new Date()) ) { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); String compactJws = Jwts.builder() .setSubject(username) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(expireAt) .compact(); return compactJws; } return null; }  }
JwtService { public String createToken(String username, String secret, Date expireAt) { if(StringUtils.hasText(username) && StringUtils.hasText(secret) && expireAt != null && expireAt.after(new Date()) ) { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); String compactJws = Jwts.builder() .setSubject(username) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(expireAt) .compact(); return compactJws; } 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 createToken(String username, String secret, Date expireAt) { if(StringUtils.hasText(username) && StringUtils.hasText(secret) && expireAt != null && expireAt.after(new Date()) ) { String secret2 = new String(Base64.encodeBase64(secret.getBytes())); String compactJws = Jwts.builder() .setSubject(username) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(expireAt) .compact(); return compactJws; } return null; }  String createToken(String username, String secret, Date expireAt); boolean isValid(String token, String secret); String getUsername(String token, String secret);  }