feat(java): add jwt token lifetime from config

This commit is contained in:
sshakndr
2025-01-30 14:58:08 +07:00
committed by Sergey Linnik
parent 635d70d8f4
commit 7ea4545657
3 changed files with 9 additions and 0 deletions

View File

@ -47,6 +47,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -543,6 +544,7 @@ public final class DocumentManager {
for (String key : payloadClaims.keySet()) { // run through all the keys from the payload
jwt.addClaim(key, payloadClaims.get(key)); // and write each claim to the jwt
}
jwt.setExpiration(ZonedDateTime.now().plusMinutes(getTokenExpiration()));
return JWT.getEncoder().encode(jwt, signer); // sign and encode the JWT to a JSON string representation
} catch (Exception e) {
return "";
@ -579,6 +581,11 @@ public final class DocumentManager {
return ConfigManager.getProperty("files.docservice.secret");
}
// get token expiration time in minutes from the config parameters
public static Integer getTokenExpiration() {
return Integer.parseInt(ConfigManager.getProperty("files.docservice.token-expiration"));
}
// get config request jwt
public static String getTokenUseForRequest() {
return ConfigManager.getProperty("files.docservice.token-use-for-request");

View File

@ -19,5 +19,6 @@ files.docservice.languages=en:English|sq-AL:Albanian (Albania)|ar:Arabic|hy:Arme
files.docservice.secret=
files.docservice.header=Authorization
files.docservice.token-use-for-request=TRUE
files.docservice.token-expiration=5
files.docservice.verify-peer-off=TRUE