blob: 7e28b44f20faa0488241ce23bac493b5db8243d3 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.api;
import com.yahoo.athenz.auth.token.RoleToken;
import com.yahoo.vespa.athenz.utils.AthenzIdentities;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
/**
* Represents an Athenz ZToken (role token)
*
* @author bjorncs
*/
public class ZToken {
private final RoleToken token;
public ZToken(String rawToken) {
this.token = new RoleToken(rawToken);
}
public String getRawToken() {
return token.getSignedToken();
}
public AthenzIdentity getIdentity() {
return AthenzIdentities.from(token.getPrincipal());
}
public AthenzDomain getDomain() {
return new AthenzDomain(token.getDomain());
}
public List<AthenzRole> getRoles() {
String domain = token.getDomain();
return token.getRoles().stream()
.map(roleName -> new AthenzRole(domain, roleName))
.toList();}
public Instant getExpiryTime () {
return Instant.ofEpochSecond(token.getExpiryTime());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ZToken zToken = (ZToken) o;
return Objects.equals(getRawToken(), zToken.getRawToken());
}
@Override
public int hashCode() {
return Objects.hash(getRawToken());
}
}
|