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