Search in sources :

Example 1 with ObjectBucketACL

use of com.emc.storageos.db.client.model.ObjectBucketACL in project coprhd-controller by CoprHD.

the class BucketACLUtility method getExistingACL.

private ObjectBucketACL getExistingACL(BucketACE requestAcl) {
    ObjectBucketACL acl = null;
    String domainOfReqAce = requestAcl.getDomain();
    if (domainOfReqAce == null) {
        domainOfReqAce = "";
    }
    String userOrGroupOrCustomGroup = requestAcl.getUser();
    String type = "user";
    if (userOrGroupOrCustomGroup == null) {
        userOrGroupOrCustomGroup = requestAcl.getGroup() != null ? requestAcl.getGroup() : requestAcl.getCustomGroup();
        type = requestAcl.getGroup() != null ? "group" : "customgroup";
    }
    // Construct ACL Index
    StringBuffer aclIndex = new StringBuffer();
    aclIndex.append(this.bucketId).append(domainOfReqAce.toLowerCase()).append(userOrGroupOrCustomGroup.toLowerCase()).append(type);
    acl = this.queryACLByIndex(aclIndex.toString());
    return acl;
}
Also used : ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL)

Example 2 with ObjectBucketACL

use of com.emc.storageos.db.client.model.ObjectBucketACL in project coprhd-controller by CoprHD.

the class BucketACLUtility method verifyDeleteBucketACL.

private void verifyDeleteBucketACL(List<BucketACE> bucketACEList) {
    if (bucketACEList == null) {
        return;
    }
    _log.info("Number of bucket ACE(s) to delete {} ", bucketACEList.size());
    for (BucketACE ace : bucketACEList) {
        ace.proceedToNextStep();
        _log.info("Verifying ACL {}", ace.toString());
        // Are there same user or group found in other acls. If so, report
        // error
        verifyUserGroupCustomgroup(ace);
        if (!ace.canProceedToNextStep()) {
            break;
        }
        // Verify with existing ACL
        ObjectBucketACL dbBucketAcl = getExistingACL(ace);
        // If same acl exists, allow to modify
        if (dbBucketAcl != null) {
            _log.info("Existing ACL found in delete request: {}", dbBucketAcl);
            ace.proceedToNextStep();
        } else {
            // If not found, don't allow to proceed further
            if (ace.canProceedToNextStep()) {
                _log.error("No existing ACL found in DB to delete {}", ace);
                ace.cancelNextStep(BucketACLOperationErrorType.ACL_NOT_FOUND);
            }
        }
    }
}
Also used : BucketACE(com.emc.storageos.model.object.BucketACE) ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL)

Example 3 with ObjectBucketACL

use of com.emc.storageos.db.client.model.ObjectBucketACL in project coprhd-controller by CoprHD.

the class BucketACLUtility method queryExistingBucketACL.

public List<BucketACE> queryExistingBucketACL() {
    List<BucketACE> bucketACEList = new ArrayList<BucketACE>();
    List<ObjectBucketACL> dbBucketACL = queryDbBucketACL();
    if (dbBucketACL != null) {
        Iterator<ObjectBucketACL> dbAclIterator = dbBucketACL.iterator();
        while (dbAclIterator.hasNext()) {
            ObjectBucketACL dbBucketAce = dbAclIterator.next();
            if (bucketId.equals(dbBucketAce.getBucketId())) {
                BucketACE ace = new BucketACE();
                ace.setBucketName(dbBucketAce.getBucketName());
                ace.setDomain(dbBucketAce.getDomain());
                ace.setUser(dbBucketAce.getUser());
                ace.setGroup(dbBucketAce.getGroup());
                ace.setPermissions(dbBucketAce.getPermissions());
                ace.setCustomGroup(dbBucketAce.getCustomGroup());
                ace.setNamespace(dbBucketAce.getNamespace());
                bucketACEList.add(ace);
            }
        }
    }
    return bucketACEList;
}
Also used : ArrayList(java.util.ArrayList) BucketACE(com.emc.storageos.model.object.BucketACE) ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL)

Example 4 with ObjectBucketACL

use of com.emc.storageos.db.client.model.ObjectBucketACL in project coprhd-controller by CoprHD.

the class BucketACLUtility method queryDbBucketACL.

private List<ObjectBucketACL> queryDbBucketACL() {
    try {
        ContainmentConstraint containmentConstraint = null;
        _log.info("Querying DB for ACL of bucket {} ", this.bucketName);
        containmentConstraint = ContainmentConstraint.Factory.getBucketAclsConstraint(this.bucketId);
        List<ObjectBucketACL> dbBucketBucketAcl = CustomQueryUtility.queryActiveResourcesByConstraint(this.dbClient, ObjectBucketACL.class, containmentConstraint);
        return dbBucketBucketAcl;
    } catch (Exception e) {
        _log.error("Error while querying DB for ACL of a bucket {}", e);
    }
    return null;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL)

Example 5 with ObjectBucketACL

use of com.emc.storageos.db.client.model.ObjectBucketACL in project coprhd-controller by CoprHD.

the class ECSObjectStorageDevice method updateBucketACLInDB.

private void updateBucketACLInDB(BucketACLUpdateParams param, ObjectDeviceInputOutput args, Bucket bucket) {
    try {
        // Create new Acl
        if (param.getAclToAdd() != null) {
            List<BucketACE> aclToAdd = param.getAclToAdd().getBucketACL();
            if (aclToAdd != null && !aclToAdd.isEmpty()) {
                for (BucketACE ace : aclToAdd) {
                    ObjectBucketACL dbBucketAcl = new ObjectBucketACL();
                    dbBucketAcl.setId(URIUtil.createId(ObjectBucketACL.class));
                    copyToPersistBucketACL(ace, dbBucketAcl, args, bucket.getId());
                    _log.info("Storing new acl in DB: {}", dbBucketAcl);
                    _dbClient.createObject(dbBucketAcl);
                }
            }
        }
        // Modify existing Acl
        if (param.getAclToModify() != null) {
            List<BucketACE> aclToModify = param.getAclToModify().getBucketACL();
            if (aclToModify != null && !aclToModify.isEmpty()) {
                for (BucketACE ace : aclToModify) {
                    ObjectBucketACL dbBucketAcl = new ObjectBucketACL();
                    copyToPersistBucketACL(ace, dbBucketAcl, args, bucket.getId());
                    ObjectBucketACL dbBucketAclTemp = getExistingBucketAclFromDB(dbBucketAcl);
                    if (dbBucketAclTemp != null) {
                        dbBucketAcl.setId(dbBucketAclTemp.getId());
                        _log.info("Modifying acl in DB: {}", dbBucketAcl);
                        _dbClient.updateObject(dbBucketAcl);
                    }
                }
            }
        }
        // Delete existing Acl
        if (param.getAclToDelete() != null) {
            List<BucketACE> aclToDelete = param.getAclToDelete().getBucketACL();
            if (aclToDelete != null && !aclToDelete.isEmpty()) {
                for (BucketACE ace : aclToDelete) {
                    ObjectBucketACL dbBucketAcl = new ObjectBucketACL();
                    copyToPersistBucketACL(ace, dbBucketAcl, args, bucket.getId());
                    ObjectBucketACL dbBuckeAclTemp = getExistingBucketAclFromDB(dbBucketAcl);
                    if (dbBuckeAclTemp != null) {
                        dbBucketAcl.setId(dbBuckeAclTemp.getId());
                        dbBucketAcl.setInactive(true);
                        _log.info("Marking acl inactive in DB: {}", dbBucketAcl);
                        _dbClient.updateObject(dbBucketAcl);
                    }
                }
            }
        }
    } catch (Exception e) {
        _log.error("Error While executing CRUD Operations {}", e);
    }
}
Also used : BucketACE(com.emc.storageos.model.object.BucketACE) URISyntaxException(java.net.URISyntaxException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ECSException(com.emc.storageos.ecs.api.ECSException) ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL)

Aggregations

ObjectBucketACL (com.emc.storageos.db.client.model.ObjectBucketACL)13 BucketACE (com.emc.storageos.model.object.BucketACE)6 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)3 ECSException (com.emc.storageos.ecs.api.ECSException)3 ArrayList (java.util.ArrayList)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ECSApi (com.emc.storageos.ecs.api.ECSApi)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)1