@Test public void testCreateTokenSuccess() { Date d = generateValidDate(); String s = jwtService.createToken(USERNAME, SECRET, d); String secret2 = new String(Base64.encodeBase64(SECRET.getBytes())); String compactJws = Jwts.builder() .setSubject(USERNAME) .signWith(SignatureAlgorithm.HS512, secret2) .setExpiration(d) .compact(); assertEquals(compactJws, s); }
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);  }