use of io.jsonwebtoken.JwtBuilder in project sonarqube by SonarSource.
the class JwtSerializer method encode.
String encode(JwtSession jwtSession) {
checkIsStarted();
long now = system2.now();
JwtBuilder jwtBuilder = Jwts.builder().setId(uuidFactory.create()).setSubject(jwtSession.getUserLogin()).setIssuedAt(new Date(now)).setExpiration(new Date(now + jwtSession.getExpirationTimeInSeconds() * 1000)).signWith(SIGNATURE_ALGORITHM, secretKey);
for (Map.Entry<String, Object> entry : jwtSession.getProperties().entrySet()) {
jwtBuilder.claim(entry.getKey(), entry.getValue());
}
return jwtBuilder.compact();
}
use of io.jsonwebtoken.JwtBuilder in project sonarqube by SonarSource.
the class JwtSerializer method refresh.
String refresh(Claims token, int expirationTimeInSeconds) {
checkIsStarted();
long now = system2.now();
JwtBuilder jwtBuilder = Jwts.builder();
for (Map.Entry<String, Object> entry : token.entrySet()) {
jwtBuilder.claim(entry.getKey(), entry.getValue());
}
jwtBuilder.setExpiration(new Date(now + expirationTimeInSeconds * 1000)).signWith(SIGNATURE_ALGORITHM, secretKey);
return jwtBuilder.compact();
}
use of io.jsonwebtoken.JwtBuilder in project nymph by Onnt.
the class NymCode method encode.
/**
* 创建 jwt
* @param id
* @param subject
* @param ttlMillis
* @return
* @throws Exception
*/
public String encode(String id, String subject) {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
SecretKey key = generalKey();
JwtBuilder builder = Jwts.builder().setId(id).setIssuedAt(now).setSubject(subject).signWith(signatureAlgorithm, key);
long ttlMillis = new Date().getTime();
if (ttlMillis >= 0) {
long expMillis = nowMillis + ttlMillis;
Date exp = new Date(expMillis);
builder.setExpiration(exp);
}
return builder.compact();
}
Aggregations