diff options
Diffstat (limited to 'src/main/java/com/juick/KeystoreManager.java')
-rw-r--r-- | src/main/java/com/juick/KeystoreManager.java | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/com/juick/KeystoreManager.java b/src/main/java/com/juick/KeystoreManager.java index d8355941..952cb72c 100644 --- a/src/main/java/com/juick/KeystoreManager.java +++ b/src/main/java/com/juick/KeystoreManager.java @@ -17,7 +17,9 @@ package com.juick; +import com.juick.model.User; import com.juick.www.api.activity.model.objects.Actor; +import io.jsonwebtoken.Jwts; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; @@ -30,6 +32,9 @@ import java.io.InputStream; import java.security.*; import java.security.cert.Certificate; import java.security.cert.CertificateException; +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.Date; public class KeystoreManager { private static final Logger logger = LoggerFactory.getLogger("ActivityPub"); @@ -51,7 +56,7 @@ public class KeystoreManager { } } - private KeyPair getKeyPair() { + public KeyPair getKeyPair() { java.security.Key privateKey; try { privateKey = ks.getKey("1", keystorePassword.toCharArray()); @@ -77,4 +82,11 @@ public class KeystoreManager { String pubkeyPem = person.getPublicKey().getPublicKeyPem(); return Keys.decode(pubkeyPem.getBytes()).getKey(); } + public String generateToken(User user) { + return Jwts.builder() + .setSubject(user.getName()) + .setIssuedAt(Date.from(ZonedDateTime.now().toInstant())) + .signWith(getPrivateKey()) + .compact(); + } } |