use of com.emc.storageos.model.object.BucketACE 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);
}
}
}
}
use of com.emc.storageos.model.object.BucketACE 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;
}
use of com.emc.storageos.model.object.BucketACE in project coprhd-controller by CoprHD.
the class BucketACLUtility method reportModifyErrors.
private void reportModifyErrors(BucketACLUpdateParams param) {
String opName = BucketACLOperationType.MODIFY.name();
// Report Add ACL Errors
BucketACL bucketACL = param.getAclToModify();
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 ACL_NOT_FOUND:
{
throw APIException.badRequests.bucketACLNotFound(opName, bucketACE.toString());
}
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:
default:
break;
}
}
}
}
use of com.emc.storageos.model.object.BucketACE in project coprhd-controller by CoprHD.
the class ECSObjectStorageDevice method doUpdateBucketACL.
@Override
public BiosCommandResult doUpdateBucketACL(StorageSystem storageObj, Bucket bucket, ObjectDeviceInputOutput objectArgs, BucketACLUpdateParams param, String taskId) throws ControllerException {
List<BucketACE> aclToAdd = objectArgs.getBucketAclToAdd();
List<BucketACE> aclToModify = objectArgs.getBucketAclToModify();
List<BucketACE> aclToDelete = objectArgs.getBucketAclToDelete();
// Get existing Acl for the Bucket
List<BucketACE> aclsToProcess = objectArgs.getExistingBucketAcl();
aclsToProcess.addAll(aclToAdd);
// Process ACLs to modify
for (BucketACE existingAce : aclsToProcess) {
String domainOfExistingAce = existingAce.getDomain();
if (domainOfExistingAce == null) {
domainOfExistingAce = "";
}
for (BucketACE aceToModify : aclToModify) {
String domainOfmodifiedAce = aceToModify.getDomain();
if (domainOfmodifiedAce == null) {
domainOfmodifiedAce = "";
}
if (aceToModify.getUser() != null && existingAce.getUser() != null) {
if (domainOfExistingAce.concat(existingAce.getUser()).equalsIgnoreCase(domainOfmodifiedAce.concat(aceToModify.getUser()))) {
existingAce.setPermissions(aceToModify.getPermissions());
}
}
if (aceToModify.getGroup() != null && existingAce.getGroup() != null) {
if (domainOfExistingAce.concat(existingAce.getGroup()).equalsIgnoreCase(domainOfmodifiedAce.concat(aceToModify.getGroup()))) {
existingAce.setPermissions(aceToModify.getPermissions());
}
}
if (aceToModify.getCustomGroup() != null && existingAce.getCustomGroup() != null) {
if (domainOfExistingAce.concat(existingAce.getCustomGroup()).equalsIgnoreCase(domainOfmodifiedAce.concat(aceToModify.getCustomGroup()))) {
existingAce.setPermissions(aceToModify.getPermissions());
}
}
}
}
// Process ACLs to delete
for (BucketACE aceToDelete : aclToDelete) {
String domainOfDeleteAce = aceToDelete.getDomain();
if (domainOfDeleteAce == null) {
domainOfDeleteAce = "";
}
for (Iterator<BucketACE> iterator = aclsToProcess.iterator(); iterator.hasNext(); ) {
BucketACE existingAcl = iterator.next();
String domainOfExistingAce = existingAcl.getDomain();
if (domainOfExistingAce == null) {
domainOfExistingAce = "";
}
if (aceToDelete.getUser() != null && existingAcl.getUser() != null) {
if (domainOfDeleteAce.concat(aceToDelete.getUser()).equalsIgnoreCase(domainOfExistingAce.concat(existingAcl.getUser()))) {
iterator.remove();
}
}
if (aceToDelete.getGroup() != null && existingAcl.getGroup() != null) {
if (domainOfDeleteAce.concat(aceToDelete.getGroup()).equalsIgnoreCase(domainOfExistingAce.concat(existingAcl.getGroup()))) {
iterator.remove();
}
}
if (aceToDelete.getCustomGroup() != null && existingAcl.getCustomGroup() != null) {
if (domainOfDeleteAce.concat(aceToDelete.getCustomGroup()).equalsIgnoreCase(domainOfExistingAce.concat(existingAcl.getCustomGroup()))) {
iterator.remove();
}
}
}
}
ECSApi objectAPI = getAPI(storageObj);
try {
String payload = toJsonString(objectArgs, aclsToProcess);
objectAPI.updateBucketACL(objectArgs.getName(), payload);
updateBucketACLInDB(param, objectArgs, bucket);
} catch (ECSException e) {
_log.error("ACL Update for Bucket : {} failed.", objectArgs.getName(), e);
completeTask(bucket.getId(), taskId, e);
return BiosCommandResult.createErrorResult(e);
}
completeTask(bucket.getId(), taskId, "Successfully updated Bucket ACL.");
return BiosCommandResult.createSuccessfulResult();
}
use of com.emc.storageos.model.object.BucketACE 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);
}
}
Aggregations