Search in sources :

Example 1 with Policy

use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.

the class FileConnection method insertAssertion.

@Override
public boolean insertAssertion(String domainName, String policyName, Assertion assertion) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "insertAssertion");
    }
    Policy policy = getPolicyObject(domainStruct, policyName);
    if (policy == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "policy not found", "insertAssertion");
    }
    List<Assertion> assertions = policy.getAssertions();
    if (assertions == null) {
        assertions = new ArrayList<>();
        policy.setAssertions(assertions);
    }
    assertions.add(assertion);
    assertion.setId(System.nanoTime());
    putDomainStruct(domainName, domainStruct);
    return true;
}
Also used : Policy(com.yahoo.athenz.zms.Policy) Assertion(com.yahoo.athenz.zms.Assertion)

Example 2 with Policy

use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.

the class FileConnection method listAssertions.

@Override
public List<Assertion> listAssertions(String domainName, String policyName) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "listAssertions");
    }
    Policy policy = getPolicyObject(domainStruct, policyName);
    if (policy == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "policy not found", "listAssertions");
    }
    return policy.getAssertions();
}
Also used : Policy(com.yahoo.athenz.zms.Policy)

Example 3 with Policy

use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.

the class FileConnection method updatePolicy.

@Override
public boolean updatePolicy(String domainName, Policy policy) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "updatePolicy");
    }
    if (domainStruct.getPolicies() == null) {
        domainStruct.setPolicies(new HashMap<String, Policy>());
    }
    HashMap<String, Policy> policies = domainStruct.getPolicies();
    String policyName = extractPolicyName(domainName, policy.getName());
    // here we only need to update the main attrs and not
    // the assertions
    List<Assertion> assertions = policy.getAssertions();
    Policy originalPolicy = getPolicyObject(domainStruct, policyName);
    if (originalPolicy != null) {
        policy.setAssertions(originalPolicy.getAssertions());
    } else {
        policy.setAssertions(null);
    }
    policy.setModified(Timestamp.fromCurrentTime());
    policies.put(policyName, policy);
    putDomainStruct(domainName, domainStruct);
    policy.setAssertions(assertions);
    return true;
}
Also used : Policy(com.yahoo.athenz.zms.Policy) Assertion(com.yahoo.athenz.zms.Assertion)

Example 4 with Policy

use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.

the class FileConnection method listPolicies.

@Override
public List<String> listPolicies(String domainName, String assertionRoleName) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "listPolicies");
    }
    ArrayList<String> list = new ArrayList<>();
    if (assertionRoleName == null) {
        HashMap<String, Policy> policies = domainStruct.getPolicies();
        if (policies != null) {
            list.addAll(policies.keySet());
        }
    } else {
        List<Assertion> assertions = null;
        HashMap<String, Policy> policies = domainStruct.getPolicies();
        for (Policy policy : policies.values()) {
            assertions = policy.getAssertions();
            if (assertions == null) {
                continue;
            }
            for (Assertion assertion : assertions) {
                if (assertionRoleName.compareToIgnoreCase(assertion.getRole()) == 0) {
                    list.add(policy.getName());
                    break;
                }
            }
        }
    }
    Collections.sort(list);
    return list;
}
Also used : Policy(com.yahoo.athenz.zms.Policy) ArrayList(java.util.ArrayList) Assertion(com.yahoo.athenz.zms.Assertion)

Example 5 with Policy

use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.

the class FileConnection method getAssertion.

@Override
public Assertion getAssertion(String domainName, String policyName, Long assertionId) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "getAssertion");
    }
    Policy policy = getPolicyObject(domainStruct, policyName);
    if (policy == null) {
        return null;
    }
    List<Assertion> assertions = policy.getAssertions();
    if (assertions == null) {
        return null;
    }
    for (Assertion assertion : assertions) {
        if (assertion.getId().equals(assertionId)) {
            return assertion;
        }
    }
    return null;
}
Also used : Policy(com.yahoo.athenz.zms.Policy) Assertion(com.yahoo.athenz.zms.Assertion)

Aggregations

Policy (com.yahoo.athenz.zms.Policy)61 Assertion (com.yahoo.athenz.zms.Assertion)36 Test (org.testng.annotations.Test)34 com.yahoo.athenz.zms (com.yahoo.athenz.zms)25 DataCache (com.yahoo.athenz.zts.cache.DataCache)12 Principal (com.yahoo.athenz.auth.Principal)8 Role (com.yahoo.athenz.zms.Role)8 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)7 Domain (com.yahoo.athenz.zms.Domain)6 RoleMember (com.yahoo.athenz.zms.RoleMember)6 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)5 ResourceException (com.yahoo.athenz.zms.ResourceException)4 Struct (com.yahoo.rdl.Struct)4 SQLException (java.sql.SQLException)4 Authority (com.yahoo.athenz.auth.Authority)3 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)3 ArrayList (java.util.ArrayList)3 AuthzDetailsEntity (com.yahoo.athenz.common.config.AuthzDetailsEntity)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2