blob: 4cb3a4b54516349ae7b3f61e1f2feeae4db83113 (
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
62
63
64
65
66
67
68
69
70
71
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.api;
import java.util.Objects;
/**
* @author tokle
*/
public class AthenzRole {
private static final String ROLE_RESOURCE_PREFIX = "role.";
private final AthenzDomain domain;
private final String roleName;
public AthenzRole(AthenzDomain domain, String roleName) {
this.domain = domain;
this.roleName = roleName;
}
public AthenzRole(String domain, String roleName) {
this.domain = new AthenzDomain(domain);
this.roleName = roleName;
}
public static AthenzRole fromResourceNameString(String string) {
return fromResourceName(AthenzResourceName.fromString(string));
}
public static AthenzRole fromResourceName(AthenzResourceName resourceName) {
String entityName = resourceName.getEntityName();
if (!entityName.startsWith(ROLE_RESOURCE_PREFIX)) {
throw new IllegalArgumentException("Not a valid role: " + resourceName.toResourceNameString());
}
String roleName = entityName.substring(ROLE_RESOURCE_PREFIX.length());
return new AthenzRole(resourceName.getDomain(), roleName);
}
public AthenzDomain domain() {
return domain;
}
public String roleName() {
return roleName;
}
public String toResourceNameString() { return toResourceName().toResourceNameString(); }
public AthenzResourceName toResourceName() { return new AthenzResourceName(domain, ROLE_RESOURCE_PREFIX + roleName); }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AthenzRole that = (AthenzRole) o;
return Objects.equals(domain, that.domain) &&
Objects.equals(roleName, that.roleName);
}
@Override
public int hashCode() {
return Objects.hash(domain, roleName);
}
@Override
public String toString() {
return "AthenzRole{" +
"domain=" + domain +
", roleName='" + roleName + '\'' +
'}';
}
}
|