mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
set 10 hours for token max age
This commit is contained in:
@@ -63,6 +63,8 @@ import sonia.scm.util.HttpUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -180,6 +182,9 @@ public class AuthenticationResource
|
||||
Cookie c = new Cookie("X-Bearer-Token", token);
|
||||
|
||||
c.setPath(request.getContextPath());
|
||||
|
||||
// TODO: should be configureable
|
||||
c.setMaxAge((int) TimeUnit.SECONDS.convert(10, TimeUnit.HOURS));
|
||||
c.setHttpOnly(true);
|
||||
response.addCookie(c);
|
||||
state = stateFactory.createState(subject);
|
||||
|
||||
@@ -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