mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 17:56:17 +01:00
set 10 hours for token max age
This commit is contained in:
@@ -39,6 +39,8 @@ import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -83,14 +85,18 @@ public final class BearerTokenGenerator
|
||||
checkNotNull(user, "user is required");
|
||||
|
||||
SecureKey key = keyResolver.getSecureKey(user.getName());
|
||||
|
||||
// TODO add expiration date
|
||||
|
||||
Date now = new Date();
|
||||
// TODO: should be configurable
|
||||
long expiration = TimeUnit.MILLISECONDS.convert(10, TimeUnit.HOURS);
|
||||
|
||||
//J-
|
||||
return Jwts.builder()
|
||||
.setSubject(user.getName())
|
||||
.setId(keyGenerator.createKey())
|
||||
.signWith(SignatureAlgorithm.HS256, key.getBytes())
|
||||
.setIssuedAt(now)
|
||||
.setExpiration(new Date(now.getTime() + expiration))
|
||||
.compact();
|
||||
//J+
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user