// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.athenz;

import com.yahoo.vespa.hosted.controller.api.identifiers.AthenzDomain;

import java.security.Principal;
import java.util.Objects;

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

    private final AthenzIdentity athenzIdentity;
    private final NToken nToken;

    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 NToken getNToken() {
        return 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);
    }
}

@@ -308,16 +308,43 @@
 Objects;
+%0Aimport java.util.Optional;
 %0A%0A/**%0A *
@@ -500,16 +500,119 @@
 Token;%0A%0A
+    public AthenzPrincipal(AthenzIdentity athenzIdentity) %7B%0A        this(athenzIdentity, null);%0A    %7D%0A%0A
     publ
@@ -1063,22 +1063,32 @@
  public 
+Optional%3C
 NToken
+%3E
  getNTok
@@ -1109,22 +1109,43 @@
  return 
+Optional.ofNullable(
 nToken
+)
 ;%0A    %7D%0A

Make NToken optional in AthenzPrincipal