@Test public void test_generateApiToken() { User user = new User(); user.setUsername(USERNAME); String token = serviceToTest.generateApiToken(user); Jws<Claims> jws = Jwts.parser() .setSigningKey(propertiesManager.getProperty(Properties.SIGNING_KEY)) .parseClaimsJws(token); Claims claims = jws.getBody(); Assert.assertEquals(USERNAME, claims.getSubject()); Assert.assertNotNull(claims.getExpiration()); Assert.assertFalse(claims.getExpiration().before(new Date())); }
@Override public String generateApiToken(User user) { String compactJws = Jwts.builder() .setSubject(user.getUsername()) .setExpiration(new Date((new Date()).getTime() + timeTillExpiration)) .signWith(SignatureAlgorithm.HS512, propertiesManager.getProperty(Properties.SIGNING_KEY)) .compact(); return compactJws; }
TokenService implements ITokenService { @Override public String generateApiToken(User user) { String compactJws = Jwts.builder() .setSubject(user.getUsername()) .setExpiration(new Date((new Date()).getTime() + timeTillExpiration)) .signWith(SignatureAlgorithm.HS512, propertiesManager.getProperty(Properties.SIGNING_KEY)) .compact(); return compactJws; } }
TokenService implements ITokenService { @Override public String generateApiToken(User user) { String compactJws = Jwts.builder() .setSubject(user.getUsername()) .setExpiration(new Date((new Date()).getTime() + timeTillExpiration)) .signWith(SignatureAlgorithm.HS512, propertiesManager.getProperty(Properties.SIGNING_KEY)) .compact(); return compactJws; }  }
TokenService implements ITokenService { @Override public String generateApiToken(User user) { String compactJws = Jwts.builder() .setSubject(user.getUsername()) .setExpiration(new Date((new Date()).getTime() + timeTillExpiration)) .signWith(SignatureAlgorithm.HS512, propertiesManager.getProperty(Properties.SIGNING_KEY)) .compact(); return compactJws; }  @Override String generateApiToken(User user); @Override IApiTokenContents getApiTokenContents(String token); @Override IAppToken generateAppToken(IRegisteredApp app); @Override IAppToken getAppTokenContents(String token); }
TokenService implements ITokenService { @Override public String generateApiToken(User user) { String compactJws = Jwts.builder() .setSubject(user.getUsername()) .setExpiration(new Date((new Date()).getTime() + timeTillExpiration)) .signWith(SignatureAlgorithm.HS512, propertiesManager.getProperty(Properties.SIGNING_KEY)) .compact(); return compactJws; }  @Override String generateApiToken(User user); @Override IApiTokenContents getApiTokenContents(String token); @Override IAppToken generateAppToken(IRegisteredApp app); @Override IAppToken getAppTokenContents(String token);  }