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;
}
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;
}
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);
}
Aggregations