Search in sources :

Example 1 with Assertion

use of com.yahoo.athenz.zms.Assertion 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 Assertion

use of com.yahoo.athenz.zms.Assertion 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 3 with Assertion

use of com.yahoo.athenz.zms.Assertion 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 4 with Assertion

use of com.yahoo.athenz.zms.Assertion 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)

Example 5 with Assertion

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

the class FileConnection method deleteAssertion.

@Override
public boolean deleteAssertion(String domainName, String policyName, Long assertionId) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "deleteAssertion");
    }
    Policy policy = getPolicyObject(domainStruct, policyName);
    if (policy == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "policy not found", "insertAssertion");
    }
    List<Assertion> assertions = policy.getAssertions();
    boolean deleted = false;
    for (int i = 0; i < assertions.size(); i++) {
        if (assertions.get(i).getId().equals(assertionId)) {
            assertions.remove(i);
            deleted = true;
            break;
        }
    }
    putDomainStruct(domainName, domainStruct);
    return deleted;
}
Also used : Policy(com.yahoo.athenz.zms.Policy) Assertion(com.yahoo.athenz.zms.Assertion)

Aggregations

Assertion (com.yahoo.athenz.zms.Assertion)61 Test (org.testng.annotations.Test)38 ArrayList (java.util.ArrayList)29 Policy (com.yahoo.athenz.zms.Policy)23 Role (com.yahoo.athenz.zms.Role)19 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)16 RoleMember (com.yahoo.athenz.zms.RoleMember)11 DomainData (com.yahoo.athenz.zms.DomainData)10 HashMap (java.util.HashMap)9 SQLException (java.sql.SQLException)8 SignedDomain (com.yahoo.athenz.zms.SignedDomain)7 DataCache (com.yahoo.athenz.zts.cache.DataCache)7 Domain (com.yahoo.athenz.zms.Domain)5 ResourceAccessList (com.yahoo.athenz.zms.ResourceAccessList)5 ResourceAccess (com.yahoo.athenz.zms.ResourceAccess)4 ResourceException (com.yahoo.athenz.zms.ResourceException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)3 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)3