Search in sources :

Example 6 with BucketACL

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

the class ObjectBuckets method createObjectBucketACLUpdateParams.

private static ObjectBucketACLUpdateParams createObjectBucketACLUpdateParams(String formData) {
    String[] uiAcls = formData.split(",");
    List<BucketACE> aces = Lists.newArrayList();
    for (String uiAce : uiAcls) {
        String[] uiData = uiAce.split("~~~");
        String uiType = uiData[0];
        String uiName = uiData[1];
        String uiDomain = uiData[2];
        String uiPermissions = uiData[3];
        BucketACE bucketAce = new BucketACE();
        if (uiDomain != null && !uiDomain.isEmpty() && !"null".equals(uiDomain)) {
            bucketAce.setDomain(uiDomain);
        }
        if (GROUP.equalsIgnoreCase(uiType.trim())) {
            bucketAce.setGroup(uiName.trim());
        } else if (CUSTOMGROUP.equalsIgnoreCase(uiType.trim())) {
            bucketAce.setCustomGroup(uiName.trim());
        } else {
            bucketAce.setUser(uiName.trim());
        }
        if (uiPermissions != null && !"".equals(uiPermissions) && !"null".equals(uiPermissions)) {
            bucketAce.setPermissions(uiPermissions);
        }
        aces.add(bucketAce);
    }
    BucketACL aclToAdd = new BucketACL();
    aclToAdd.setBucketACL(aces);
    ObjectBucketACLUpdateParams input = new ObjectBucketACLUpdateParams();
    input.setAclToAdd(aclToAdd);
    return input;
}
Also used : BucketACL(com.emc.storageos.model.object.BucketACL) ObjectBucketACLUpdateParams(com.emc.storageos.model.object.ObjectBucketACLUpdateParams) BucketACE(com.emc.storageos.model.object.BucketACE)

Example 7 with BucketACL

use of com.emc.storageos.model.object.BucketACL 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 8 with BucketACL

use of com.emc.storageos.model.object.BucketACL 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 9 with BucketACL

use of com.emc.storageos.model.object.BucketACL 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 10 with BucketACL

use of com.emc.storageos.model.object.BucketACL 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

BucketACL (com.emc.storageos.model.object.BucketACL)13 BucketACE (com.emc.storageos.model.object.BucketACE)10 ObjectBucketACL (com.emc.storageos.db.client.model.ObjectBucketACL)7 ObjectBucketACLUpdateParams (com.emc.storageos.model.object.ObjectBucketACLUpdateParams)4 ECSBucketACL (com.emc.storageos.ecs.api.ECSBucketACL)3 BucketACLUpdateParams (com.emc.storageos.model.object.BucketACLUpdateParams)3 BucketACLOperationErrorType (com.emc.storageos.model.object.BucketACLUpdateParams.BucketACLOperationErrorType)3 ECSApi (com.emc.storageos.ecs.api.ECSApi)2 ECSException (com.emc.storageos.ecs.api.ECSException)2 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)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 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1