use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBService method getPendingDomainRoleMembers.
DomainRoleMembership getPendingDomainRoleMembers(final String principal, final String domainName) {
DomainRoleMembership domainRoleMembership = new DomainRoleMembership();
List<DomainRoleMembers> domainRoleMembersList = new ArrayList<>();
boolean emptyDomainName = StringUtil.isEmpty(domainName);
try (ObjectStoreConnection con = store.getConnection(true, false)) {
if (principal != null) {
Map<String, List<DomainRoleMember>> domainRoleMembersMap = con.getPendingDomainRoleMembersByPrincipal(principal);
if (domainRoleMembersMap != null) {
for (String domain : domainRoleMembersMap.keySet()) {
if (emptyDomainName || domain.equals(domainName) || "*".equals(domainName)) {
domainRoleMembersList.add(getDomainRoleMembers(domain, domainRoleMembersMap));
}
}
domainRoleMembership.setDomainRoleMembersList(domainRoleMembersList);
}
} else if (!emptyDomainName) {
Map<String, List<DomainRoleMember>> domainRoleMembersMap = con.getPendingDomainRoleMembersByDomain(domainName);
if (domainRoleMembersMap != null) {
for (String domain : domainRoleMembersMap.keySet()) {
domainRoleMembersList.add(getDomainRoleMembers(domain, domainRoleMembersMap));
}
domainRoleMembership.setDomainRoleMembersList(domainRoleMembersList);
}
}
}
return domainRoleMembership;
}
use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBService method listDomainTemplates.
DomainTemplateList listDomainTemplates(String domainName) {
try (ObjectStoreConnection con = store.getConnection(true, false)) {
DomainTemplateList domainTemplateList = new DomainTemplateList();
domainTemplateList.setTemplateNames(con.listDomainTemplates(domainName));
return domainTemplateList;
}
}
use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBService method getGroupMembership.
GroupMembership getGroupMembership(final String domainName, final String groupName, final String principal, long expiryTimestamp, boolean pending) {
try (ObjectStoreConnection con = store.getConnection(true, false)) {
GroupMembership membership = con.getGroupMember(domainName, groupName, principal, expiryTimestamp, pending);
Timestamp expiration = membership.getExpiration();
if (expiration != null && expiration.millis() < System.currentTimeMillis()) {
membership.setIsMember(false);
}
return membership;
}
}
use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBService method executeDeleteAssertionConditions.
public void executeDeleteAssertionConditions(ResourceContext ctx, String domainName, String policyName, Long assertionId, String auditRef, String caller) {
for (int retryCount = defaultRetryCount; ; retryCount--) {
try (ObjectStoreConnection con = store.getConnection(true, true)) {
// first verify that auditing requirements are met
checkDomainAuditEnabled(con, domainName, auditRef, caller, getPrincipalName(ctx), AUDIT_TYPE_POLICY);
// fetch the assertion for our audit log
List<AssertionCondition> assertionConditions = con.getAssertionConditions(assertionId);
if (assertionConditions == null) {
throw ZMSUtils.notFoundError(String.format("%s: unable to read assertion conditions for policy=%s assertionId=%d", caller, policyName, assertionId), caller);
}
if (!con.deleteAssertionConditions(assertionId)) {
throw ZMSUtils.notFoundError(String.format("%s: unable to delete assertion conditions for policy=%s assertionId=%d", caller, policyName, assertionId), caller);
}
// update our policy and domain time-stamps, and invalidate local cache entry
con.updatePolicyModTimestamp(domainName, policyName, null);
con.updateDomainModTimestamp(domainName);
cacheStore.invalidate(domainName);
// audit log the request
StringBuilder auditDetails = new StringBuilder(ZMSConsts.STRING_BLDR_SIZE_DEFAULT);
auditDetails.append("{\"policy\": \"").append(policyName).append("\", \"assertionId\": ").append(assertionId).append(", ");
auditLogAssertionConditions(auditDetails, assertionConditions, "deleted-assertion-conditions");
auditDetails.append("}");
auditLogRequest(ctx, domainName, auditRef, caller, ZMSConsts.HTTP_DELETE, policyName, auditDetails.toString());
// add domain change event
addDomainChangeMessage(ctx, domainName, policyName, DomainChangeMessage.ObjectType.POLICY);
return;
} catch (ResourceException ex) {
if (!shouldRetryOperation(ex, retryCount)) {
throw ex;
}
}
}
}
use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBService method executeDeleteGroup.
void executeDeleteGroup(ResourceContext ctx, final String domainName, final String groupName, final String auditRef) {
for (int retryCount = defaultRetryCount; ; retryCount--) {
try (ObjectStoreConnection con = store.getConnection(false, true)) {
// first verify that auditing requirements are met
checkDomainAuditEnabled(con, domainName, auditRef, ctx.getApiName(), getPrincipalName(ctx), AUDIT_TYPE_GROUP);
if (!con.deleteGroup(domainName, groupName)) {
con.rollbackChanges();
throw ZMSUtils.notFoundError("unable to delete group: " + groupName, ctx.getApiName());
}
// update our domain time-stamp and save changes
saveChanges(con, domainName);
// audit log the request
auditLogRequest(ctx, domainName, auditRef, ctx.getApiName(), ZMSConsts.HTTP_DELETE, groupName, null);
// add domain change event
addDomainChangeMessage(ctx, domainName, groupName, DomainChangeMessage.ObjectType.GROUP);
return;
} catch (ResourceException ex) {
if (!shouldRetryOperation(ex, retryCount)) {
throw ex;
}
}
}
}
Aggregations