diff options
author | Anton Tananaev <anton@traccar.org> | 2022-08-02 20:40:29 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-08-02 20:40:29 -0700 |
commit | 62e4876406de1951705e76f85c1e099c36d48a87 (patch) | |
tree | ad577555851a03a2758fdfef26ede770a691bcf9 /src/main/java/org/traccar/api/signature | |
parent | ab6970135850655313e257cf44fb68c67e9f1e80 (diff) | |
download | trackermap-server-62e4876406de1951705e76f85c1e099c36d48a87.tar.gz trackermap-server-62e4876406de1951705e76f85c1e099c36d48a87.tar.bz2 trackermap-server-62e4876406de1951705e76f85c1e099c36d48a87.zip |
New tokens for password reset
Diffstat (limited to 'src/main/java/org/traccar/api/signature')
-rw-r--r-- | src/main/java/org/traccar/api/signature/TokenManager.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/api/signature/TokenManager.java b/src/main/java/org/traccar/api/signature/TokenManager.java index 3f39d5380..a51234a95 100644 --- a/src/main/java/org/traccar/api/signature/TokenManager.java +++ b/src/main/java/org/traccar/api/signature/TokenManager.java @@ -24,9 +24,12 @@ import javax.inject.Inject; import java.io.IOException; import java.security.GeneralSecurityException; import java.util.Date; +import java.util.concurrent.TimeUnit; public class TokenManager { + private static final int DEFAULT_EXPIRATION_DAYS = 7; + private final ObjectMapper objectMapper; private final CryptoManager cryptoManager; @@ -47,7 +50,11 @@ public class TokenManager { long userId, Date expiration) throws IOException, GeneralSecurityException, StorageException { Data data = new Data(); data.userId = userId; - data.expiration = expiration; + if (expiration != null) { + data.expiration = expiration; + } else { + data.expiration = new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(DEFAULT_EXPIRATION_DAYS)); + } byte[] encoded = objectMapper.writeValueAsBytes(data); return Base64.encodeBase64URLSafeString(cryptoManager.sign(encoded)); } |