Token.java
3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.PropertyIterator
* javax.jcr.RepositoryException
*/
package com.day.crx.security.token.impl.helper;
import java.util.Calendar;
import java.util.Map;
import java.util.TreeMap;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class Token {
private static final String PROP_EXPIRY = ".token.exp";
private static final String PROP_OAK_EXPIRY = "rep:token.exp";
private static final String PROP_PREFIX_MANDATORY = ".token";
private static final String PROP_PREFIX_RESERVED = "rep:token";
private final Node tokenNode;
private Calendar expiry;
Map<String, String> mandatory;
Map<String, String> info;
public Token(Node tokenNode) {
this.tokenNode = tokenNode;
}
public String getIdentifier() throws RepositoryException {
return this.tokenNode.getIdentifier();
}
public Calendar getExpiry() throws RepositoryException {
if (this.expiry == null) {
if (this.tokenNode.hasProperty(".token.exp")) {
this.expiry = this.tokenNode.getProperty(".token.exp").getDate();
} else if (this.tokenNode.hasProperty("rep:token.exp")) {
this.expiry = this.tokenNode.getProperty("rep:token.exp").getDate();
} else {
this.expiry = Calendar.getInstance();
this.expiry.setTimeInMillis(-1);
}
}
return this.expiry;
}
public boolean isExpired(long cutoffMillisUtc) throws RepositoryException {
return this.getExpiry().getTimeInMillis() < cutoffMillisUtc;
}
public Map<String, String> getMandatoryProperties() throws RepositoryException {
if (this.mandatory == null) {
this.readProperties();
}
return this.mandatory;
}
public Map<String, String> getInformationProperties() throws RepositoryException {
if (this.info == null) {
this.readProperties();
}
return this.info;
}
public void remove() throws RepositoryException {
this.tokenNode.remove();
}
private void readProperties() throws RepositoryException {
TreeMap<String, String> mandatory = new TreeMap<String, String>();
TreeMap<String, String> info = new TreeMap<String, String>();
PropertyIterator props = this.tokenNode.getProperties();
while (props.hasNext()) {
Property prop = props.nextProperty();
String name = prop.getName();
if (".token.exp".equals(name) || "rep:token.exp".equals(name)) {
if (this.expiry != null) continue;
this.expiry = prop.getDate();
continue;
}
if (name.startsWith(".token")) {
mandatory.put(name, prop.getString());
continue;
}
if (name.startsWith("rep:token")) continue;
info.put(name, prop.getString());
}
this.mandatory = mandatory;
this.info = info;
}
}