Search in sources :

Example 11 with BucketACE

use of com.emc.storageos.model.object.BucketACE in project coprhd-controller by CoprHD.

the class ECSObjectStorageDevice method persistDefaultBucketACEInDb.

private void persistDefaultBucketACEInDb(String bucketOwner, Bucket bucket, ObjectDeviceInputOutput args) {
    _log.info("Persisting bucket owner as default ACE", bucketOwner);
    BucketACLUpdateParams param = new BucketACLUpdateParams();
    BucketACL acl = new BucketACL();
    BucketACE defaultAce = new BucketACE();
    String full_control = "full_control";
    List<BucketACE> aclToAdd = Lists.newArrayList();
    String[] userDomain = bucketOwner.split("@");
    if (userDomain.length > 1) {
        defaultAce.setUser(userDomain[0]);
        defaultAce.setDomain(userDomain[1]);
    } else {
        defaultAce.setUser(bucketOwner);
    }
    defaultAce.setPermissions(full_control);
    aclToAdd.add(defaultAce);
    acl.setBucketACL(aclToAdd);
    param.setAclToAdd(acl);
    updateBucketACLInDB(param, args, bucket);
}
Also used : BucketACLUpdateParams(com.emc.storageos.model.object.BucketACLUpdateParams) ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL) ECSBucketACL(com.emc.storageos.ecs.api.ECSBucketACL) BucketACL(com.emc.storageos.model.object.BucketACL) BucketACE(com.emc.storageos.model.object.BucketACE)

Example 12 with BucketACE

use of com.emc.storageos.model.object.BucketACE in project coprhd-controller by CoprHD.

the class ObjectBuckets method deleteAcl.

/**
 * This method called When user selects ACLs and hit delete button.
 *
 * @param aclURL
 *            URL of the file system share.
 * @param ids
 *            ids of the selected ACL
 */
@FlashException(value = "buckets")
public static void deleteAcl(String bucketId, @As(",") String[] ids) {
    BucketACL aclsToDelete = new BucketACL();
    List<BucketACE> bucketAcl = Lists.newArrayList();
    if (ids != null && ids.length > 0) {
        for (String id : ids) {
            String type = BucketACLForm.extractTypeFromId(id);
            String name = BucketACLForm.extractNameFromId(id);
            String domain = BucketACLForm.extractDomainFromId(id);
            BucketACE ace = new BucketACE();
            if (GROUP.equalsIgnoreCase(type)) {
                ace.setGroup(name);
            } else if (CUSTOMGROUP.equalsIgnoreCase(type)) {
                ace.setCustomGroup(name);
            } else {
                ace.setUser(name);
            }
            if (domain != null && !"".equals(domain) && !"null".equals(domain)) {
                ace.setDomain(domain);
            }
            bucketAcl.add(ace);
        }
        aclsToDelete.setBucketACL(bucketAcl);
        ObjectBucketACLUpdateParams input = new ObjectBucketACLUpdateParams();
        input.setAclToDelete(aclsToDelete);
        ViPRCoreClient client = BourneUtil.getViprClient();
        client.objectBuckets().updateBucketACL(uri(bucketId), input);
    }
    flash.success(MessagesUtils.get(DELETED));
    listBucketACL(bucketId);
}
Also used : BucketACL(com.emc.storageos.model.object.BucketACL) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) ObjectBucketACLUpdateParams(com.emc.storageos.model.object.ObjectBucketACLUpdateParams) BucketACE(com.emc.storageos.model.object.BucketACE) FlashException(controllers.util.FlashException)

Example 13 with BucketACE

use of com.emc.storageos.model.object.BucketACE in project coprhd-controller by CoprHD.

the class ObjectBuckets method saveBucketAce.

@FlashException(keep = true, referrer = { "editBucketAce" })
public static void saveBucketAce(BucketACLForm bucketACL) {
    String name = params.get("name");
    String type = params.get("type");
    String domain = params.get("domain");
    String bucketId = params.get("bucketId");
    Set<String> permissions = bucketACL.permissions;
    String strPer = "";
    for (String permission : permissions) {
        strPer = strPer + permission + "|";
    }
    if (strPer.length() > 0) {
        strPer = strPer.substring(0, strPer.length() - 1);
    }
    List<BucketACE> acl = Lists.newArrayList();
    BucketACE ace = new BucketACE();
    BucketACL aclToModify = new BucketACL();
    if (GROUP.equalsIgnoreCase(type)) {
        ace.setGroup(name);
    } else if (CUSTOMGROUP.equalsIgnoreCase(type)) {
        ace.setCustomGroup(name);
    } else {
        ace.setUser(name);
    }
    ace.setPermissions(strPer);
    if (domain != null && !domain.isEmpty()) {
        ace.setDomain(domain);
    }
    acl.add(ace);
    aclToModify.setBucketACL(acl);
    ObjectBucketACLUpdateParams updateParam = new ObjectBucketACLUpdateParams();
    updateParam.setAclToModify(aclToModify);
    ViPRCoreClient client = BourneUtil.getViprClient();
    client.objectBuckets().updateBucketACL(uri(bucketId), updateParam);
    listBucketACL(bucketId);
}
Also used : BucketACL(com.emc.storageos.model.object.BucketACL) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) ObjectBucketACLUpdateParams(com.emc.storageos.model.object.ObjectBucketACLUpdateParams) BucketACE(com.emc.storageos.model.object.BucketACE) FlashException(controllers.util.FlashException)

Example 14 with BucketACE

use of com.emc.storageos.model.object.BucketACE in project coprhd-controller by CoprHD.

the class BucketACLUtility method verifyAddBucketACL.

private void verifyAddBucketACL(List<BucketACE> bucketACEList) {
    if (bucketACEList == null) {
        return;
    }
    _log.info("Number of bucket ACE(s) to add {} ", 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;
        }
        validatePermissions(ace);
        if (!ace.canProceedToNextStep()) {
            break;
        }
        // Verify with existing ACL
        ObjectBucketACL dbBucketAcl = getExistingACL(ace);
        // If same acl exists, don't allow to add again.
        if (dbBucketAcl != null) {
            _log.error("Duplicate ACL in add request. User/group/customgroup in ACL for bucket already exists: {}", dbBucketAcl);
            ace.cancelNextStep(BucketACLOperationErrorType.ACL_EXISTS);
            break;
        } else // If not found proceed for further verifications.
        {
            if (ace.canProceedToNextStep()) {
                _log.info("No existing ACL found in DB {}", ace);
            }
        }
    }
}
Also used : BucketACE(com.emc.storageos.model.object.BucketACE) ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL)

Example 15 with BucketACE

use of com.emc.storageos.model.object.BucketACE in project coprhd-controller by CoprHD.

the class BucketACLUtility method reportAddErrors.

private void reportAddErrors(BucketACLUpdateParams param) {
    String opName = BucketACLOperationType.ADD.name();
    // Report Add ACL Errors
    BucketACL bucketAcl = param.getAclToAdd();
    if (bucketAcl == null || bucketAcl.getBucketACL().isEmpty()) {
        return;
    }
    List<BucketACE> bucketACEList = bucketAcl.getBucketACL();
    for (BucketACE bucketACE : bucketACEList) {
        if (!bucketACE.canProceedToNextStep()) {
            BucketACLOperationErrorType error = bucketACE.getErrorType();
            switch(error) {
                case INVALID_PERMISSIONS:
                    {
                        if (bucketACE.getPermissions() != null) {
                            throw APIException.badRequests.invalidPermissionForBucketACL(bucketACE.getPermissions());
                        } else {
                            throw APIException.badRequests.missingValueInACE(opName, REQUEST_PARAM_PERMISSIONS);
                        }
                    }
                case USER_AND_GROUP_AND_CUSTOMGROUP_PROVIDED:
                    {
                        throw APIException.badRequests.userGroupAndCustomGroupInACLFound(bucketACE.getUser(), bucketACE.getGroup(), bucketACE.getCustomGroup());
                    }
                case USER_AND_GROUP_PROVIDED:
                    {
                        throw APIException.badRequests.userGroupAndCustomGroupInACLFound(bucketACE.getUser(), bucketACE.getGroup(), null);
                    }
                case USER_AND_CUSTOMGROUP_PROVIDED:
                    {
                        throw APIException.badRequests.userGroupAndCustomGroupInACLFound(bucketACE.getUser(), null, bucketACE.getCustomGroup());
                    }
                case GROUP_AND_CUSTOMGROUP_PROVIDED:
                    {
                        throw APIException.badRequests.userGroupAndCustomGroupInACLFound(null, bucketACE.getGroup(), bucketACE.getCustomGroup());
                    }
                case USER_OR_GROUP_OR_CUSTOMGROUP_NOT_PROVIDED:
                    {
                        throw APIException.badRequests.missingUserOrGroupOrCustomGroupInACE(opName);
                    }
                case MULTIPLE_ACES_WITH_SAME_USER_OR_GROUP_CUSTOMGROUP:
                    {
                        String userOrGroupOrCustomgroup = bucketACE.getUser();
                        if (userOrGroupOrCustomgroup == null) {
                            userOrGroupOrCustomgroup = bucketACE.getGroup() != null ? bucketACE.getGroup() : bucketACE.getCustomGroup();
                        }
                        throw APIException.badRequests.multipleACLsWithUserOrGroupOrCustomGroupFound(opName, userOrGroupOrCustomgroup);
                    }
                case MULTIPLE_DOMAINS_FOUND:
                    {
                        String domain1 = bucketACE.getDomain();
                        String userOrGroupOrCustomgroup = bucketACE.getUser();
                        if (userOrGroupOrCustomgroup == null) {
                            userOrGroupOrCustomgroup = bucketACE.getGroup() != null ? bucketACE.getGroup() : bucketACE.getCustomGroup();
                        }
                        String domain2 = userOrGroupOrCustomgroup.substring(0, userOrGroupOrCustomgroup.indexOf("\\"));
                        throw APIException.badRequests.multipleDomainsFound(opName, domain1, domain2);
                    }
                case ACL_EXISTS:
                    {
                        throw APIException.badRequests.bucketACLAlreadyExists(opName, bucketACE.toString());
                    }
                // case ACL_NOT_FOUND:
                default:
                    break;
            }
        }
    }
}
Also used : BucketACLOperationErrorType(com.emc.storageos.model.object.BucketACLUpdateParams.BucketACLOperationErrorType) ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL) BucketACL(com.emc.storageos.model.object.BucketACL) BucketACE(com.emc.storageos.model.object.BucketACE)

Aggregations

BucketACE (com.emc.storageos.model.object.BucketACE)19 ObjectBucketACL (com.emc.storageos.db.client.model.ObjectBucketACL)11 BucketACL (com.emc.storageos.model.object.BucketACL)10 ECSBucketACL (com.emc.storageos.ecs.api.ECSBucketACL)3 ECSException (com.emc.storageos.ecs.api.ECSException)3 BucketACLOperationErrorType (com.emc.storageos.model.object.BucketACLUpdateParams.BucketACLOperationErrorType)3 ObjectBucketACLUpdateParams (com.emc.storageos.model.object.ObjectBucketACLUpdateParams)3 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)3 ArrayList (java.util.ArrayList)3 ECSApi (com.emc.storageos.ecs.api.ECSApi)2 BucketACLUpdateParams (com.emc.storageos.model.object.BucketACLUpdateParams)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 ControllerException (com.emc.storageos.volumecontroller.ControllerException)2 Gson (com.google.gson.Gson)2 FlashException (controllers.util.FlashException)2 MapBucket (com.emc.storageos.api.mapper.functions.MapBucket)1 BucketACLUtility (com.emc.storageos.api.service.impl.resource.utils.BucketACLUtility)1 Bucket (com.emc.storageos.db.client.model.Bucket)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 URISyntaxException (java.net.URISyntaxException)1