]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.util/src/org/argeo/util/naming/SharedSecret.java
Use latest release of Argeo Maven parent
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / naming / SharedSecret.java
1 package org.argeo.util.naming;
2
3 import java.time.Instant;
4 import java.time.ZoneOffset;
5 import java.time.ZonedDateTime;
6
7 public class SharedSecret extends AuthPassword {
8 public final static String X_SHARED_SECRET = "X-SharedSecret";
9 private final Instant expiry;
10
11 public SharedSecret(String authInfo, String authValue) {
12 super(authInfo, authValue);
13 expiry = null;
14 }
15
16 public SharedSecret(AuthPassword authPassword) {
17 super(authPassword);
18 String authInfo = getAuthInfo();
19 if (authInfo.length() == 16) {
20 expiry = NamingUtils.ldapDateToInstant(authInfo);
21 } else {
22 expiry = null;
23 }
24 }
25
26 public SharedSecret(ZonedDateTime expiryTimestamp, String value) {
27 super(NamingUtils.instantToLdapDate(expiryTimestamp), value);
28 expiry = expiryTimestamp.withZoneSameInstant(ZoneOffset.UTC).toInstant();
29 }
30
31 public SharedSecret(int hours, String value) {
32 this(ZonedDateTime.now().plusHours(hours), value);
33 }
34
35 @Override
36 protected String getExpectedAuthScheme() {
37 return X_SHARED_SECRET;
38 }
39
40 public boolean isExpired() {
41 if (expiry == null)
42 return false;
43 return expiry.isBefore(Instant.now());
44 }
45
46 }