diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2018-06-19 14:15:38 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2018-06-20 13:15:11 +0200 |
commit | 990369df1dd4adb0183998238dd13e0a9d79ff0e (patch) | |
tree | 065ee2ef1903c4d3c873b3c2374ee1f9a2511bbe /vespa-athenz/src | |
parent | 59b82da9c6fb37328a2ed1f7a7f485972537a9a7 (diff) |
Parse role token and add getter for identity
Diffstat (limited to 'vespa-athenz/src')
-rw-r--r-- | vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/ZToken.java | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/ZToken.java b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/ZToken.java index ae520e66429..36c06132532 100644 --- a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/ZToken.java +++ b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/ZToken.java @@ -1,7 +1,14 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2018 Yahoo Holdings. 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.util.List; import java.util.Objects; +import java.util.stream.Collectors; + +import static java.util.stream.Collectors.toList; /** * Represents an Athenz ZToken (role token) @@ -10,27 +17,38 @@ import java.util.Objects; */ public class ZToken { - private final String rawToken; + private final RoleToken token; public ZToken(String rawToken) { - this.rawToken = rawToken; + this.token = new RoleToken(rawToken); } public String getRawToken() { - return rawToken; + return token.getSignedToken(); + } + + public AthenzIdentity getIdentity() { + return AthenzIdentities.from(token.getPrincipal()); } + public List<AthenzRole> getRoles() { + String domain = token.getDomain(); + return token.getRoles().stream() + .map(roleName -> new AthenzRole(domain, roleName)) + .collect(toList());} + @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(rawToken, zToken.rawToken); + return Objects.equals(getRawToken(), zToken.getRawToken()); } @Override public int hashCode() { - return Objects.hash(rawToken); + return Objects.hash(getRawToken()); } + } |