Search in sources :

Example 56 with ObjectStoreConnection

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;
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection)

Example 57 with ObjectStoreConnection

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;
    }
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection)

Example 58 with ObjectStoreConnection

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;
    }
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Timestamp(com.yahoo.rdl.Timestamp)

Example 59 with ObjectStoreConnection

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;
            }
        }
    }
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection)

Example 60 with ObjectStoreConnection

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;
            }
        }
    }
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection)

Aggregations

ObjectStoreConnection (com.yahoo.athenz.zms.store.ObjectStoreConnection)173 Test (org.testng.annotations.Test)96 ObjectStore (com.yahoo.athenz.zms.store.ObjectStore)38 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)34 Authority (com.yahoo.athenz.auth.Authority)23 Timestamp (com.yahoo.rdl.Timestamp)17 ArrayList (java.util.ArrayList)16 MemberDueDays (com.yahoo.athenz.zms.config.MemberDueDays)11 Principal (com.yahoo.athenz.auth.Principal)7 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)7 EmbeddedMysql (com.wix.mysql.EmbeddedMysql)5 FilePrivateKeyStore (com.yahoo.athenz.auth.impl.FilePrivateKeyStore)5 Crypto (com.yahoo.athenz.auth.util.Crypto)5 AuditReferenceValidator (com.yahoo.athenz.common.server.audit.AuditReferenceValidator)5 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)5 ResourceUtils (com.yahoo.athenz.common.server.util.ResourceUtils)5 DataCache (com.yahoo.athenz.zms.DBService.DataCache)5 MockAuditReferenceValidatorImpl (com.yahoo.athenz.zms.audit.MockAuditReferenceValidatorImpl)5 JDBCConnection (com.yahoo.athenz.zms.store.impl.jdbc.JDBCConnection)5 ZMSUtils (com.yahoo.athenz.zms.utils.ZMSUtils)5