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