Search in sources :

Example 76 with Authority

use of com.yahoo.athenz.auth.Authority in project athenz by yahoo.

the class ZMSClient method addCredentials.

/**
 * Sets or overrides the current principal identity set in the client.
 * @param identity Principal identity for authenticating requests
 * @return self ZMSClient object
 */
public ZMSClient addCredentials(Principal identity) {
    if (identity == null || identity.getAuthority() == null) {
        throw new IllegalArgumentException("Principal must be valid object with authority field");
    }
    if (principal != null) {
        client.addCredentials(principal.getAuthority().getHeader(), null);
    }
    // now we're going to update our principal and set credentials
    principal = identity;
    principalCheckDone = false;
    final Authority authority = principal.getAuthority();
    if (authority != null) {
        client.addCredentials(authority.getHeader(), principal.getCredentials());
        // final check if the authority does not support authorization
        // by the zms server then it's most likely a user authority and
        // we need to get a principal token
        principalCheckDone = authority.allowAuthorization();
    }
    return this;
}
Also used : Authority(com.yahoo.athenz.auth.Authority) PrincipalAuthority(com.yahoo.athenz.auth.impl.PrincipalAuthority)

Example 77 with Authority

use of com.yahoo.athenz.auth.Authority in project athenz by yahoo.

the class ZMSAuthorizerTest method createPrincipal.

private Principal createPrincipal(String userName) {
    Authority authority = new com.yahoo.athenz.auth.impl.PrincipalAuthority();
    Principal p = SimplePrincipal.create("user", userName, "v=U1;d=user;n=" + userName + ";s=signature", 0, authority);
    return p;
}
Also used : Authority(com.yahoo.athenz.auth.Authority) Principal(com.yahoo.athenz.auth.Principal) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal)

Example 78 with Authority

use of com.yahoo.athenz.auth.Authority in project athenz by yahoo.

the class SimpleServiceIdentityProviderTest method testConstructorWithAuthority.

@Test
public void testConstructorWithAuthority() {
    PrivateKey key = Crypto.loadPrivateKey(servicePrivateKeyStringK1);
    Authority authority = new PrincipalAuthority();
    SimpleServiceIdentityProvider provider = new SimpleServiceIdentityProvider(authority, "coretech", "athenz", key, "1", 3600);
    assertEquals(provider.getAuthority(), authority);
    SimpleServiceIdentityProvider provider2 = new SimpleServiceIdentityProvider("coretech", "athenz", key, "1", 3600);
    assertNotEquals(provider2.getAuthority(), authority);
    provider2.setAuthority(authority);
    assertEquals(provider2.getAuthority(), authority);
}
Also used : PrivateKey(java.security.PrivateKey) Authority(com.yahoo.athenz.auth.Authority) SimpleServiceIdentityProvider(com.yahoo.athenz.auth.impl.SimpleServiceIdentityProvider) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Authority (com.yahoo.athenz.auth.Authority)78 Principal (com.yahoo.athenz.auth.Principal)66 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)61 PrincipalAuthority (com.yahoo.athenz.auth.impl.PrincipalAuthority)49 Test (org.testng.annotations.Test)18 IOException (java.io.IOException)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 WebApplicationException (javax.ws.rs.WebApplicationException)9 CertificateAuthority (com.yahoo.athenz.auth.impl.CertificateAuthority)7 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)7 ArrayList (java.util.ArrayList)5 UserAuthority (com.yahoo.athenz.auth.impl.UserAuthority)4 AuthorityList (com.yahoo.athenz.common.server.rest.Http.AuthorityList)4 File (java.io.File)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)3 Struct (com.yahoo.rdl.Struct)3 X509Certificate (java.security.cert.X509Certificate)3 Authorizer (com.yahoo.athenz.auth.Authorizer)2 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2