// Copyright 2017 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 java.security.Principal;
import java.util.Objects;
import java.util.Optional;

/**
 * @author bjorncs
 */
public class AthenzPrincipal implements Principal {

    private final AthenzIdentity athenzIdentity;
    private final NToken nToken;

    public AthenzPrincipal(AthenzIdentity athenzIdentity) {
        this(athenzIdentity, null);
    }

    public AthenzPrincipal(AthenzIdentity athenzIdentity,
                           NToken nToken) {
        this.athenzIdentity = athenzIdentity;
        this.nToken = nToken;
    }

    public AthenzIdentity getIdentity() {
        return athenzIdentity;
    }

    @Override
    public String getName() {
        return athenzIdentity.getFullName();
    }

    public AthenzDomain getDomain() {
        return athenzIdentity.getDomain();
    }

    public Optional<NToken> getNToken() {
        return Optional.ofNullable(nToken);
    }

    @Override
    public String toString() {
        return "AthenzPrincipal{" +
                "athenzIdentity=" + athenzIdentity +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AthenzPrincipal principal = (AthenzPrincipal) o;
        return Objects.equals(athenzIdentity, principal.athenzIdentity);
    }

    @Override
    public int hashCode() {
        return Objects.hash(athenzIdentity);
    }
}

@@ -181,16 +181,39 @@
 ncipal;%0A
+import java.util.List;%0A
 import j
@@ -258,16 +258,64 @@
 ional;%0A%0A
+import static java.util.Collections.emptyList;%0A%0A
 /**%0A * @
@@ -467,16 +467,58 @@
  nToken;
+%0A    private final List%3CAthenzRole%3E roles;
 %0A%0A    pu
@@ -604,16 +604,29 @@
 ty, null
+, emptyList()
 );%0A    %7D
@@ -688,49 +688,302 @@
 ity,
-%0A          
+ NToken nToken) %7B%0A        this(athenzIdentity, nToken, emptyList());%0A
     
+%7D%0A%0A
     
-         NToken nToken
+public AthenzPrincipal(AthenzIdentity identity, List%3CAthenzRole%3E roles) %7B%0A        this(identity, null, roles);%0A    %7D%0A%0A    private AthenzPrincipal(AthenzIdentity athenzIdentity, NToken nToken, List%3CAthenzRole%3E roles
 ) %7B%0A
@@ -1054,24 +1054,52 @@
 n = nToken;%0A
+        this.roles = roles;%0A
     %7D%0A%0A    p
@@ -1442,32 +1442,102 @@
 nToken);%0A    %7D%0A%0A
+    public List%3CAthenzRole%3E getRoles() %7B%0A        return roles;%0A    %7D%0A%0A
     @Override%0A  

Add roles to AthenzPrincipal