use of com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant in project ksan by infinistor.
the class S3Request method isGrant.
protected boolean isGrant(String id, String s3grant) throws GWException {
if (dstBucket == null) {
return false;
}
XmlMapper xmlMapper = new XmlMapper();
try {
accessControlPolicy = xmlMapper.readValue(dstBucket.getAcl(), AccessControlPolicy.class);
} catch (JsonMappingException e) {
logger.error(e.getMessage());
new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
} catch (JsonProcessingException e) {
logger.error(e.getMessage());
new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
}
logger.info(GWConstants.LOG_REQUEST_CHECK_ACL_ID_GRANT, id, s3grant);
logger.info(GWConstants.LOG_REQUEST_BUCKET_ACL, dstBucket.getAcl());
logger.info(GWConstants.LOG_REQUEST_BUCKET_OWNER_ID, accessControlPolicy.owner.id);
if (accessControlPolicy.owner.id.compareTo(id) == 0) {
// owner has full-grant
return true;
}
switch(s3grant) {
case GWConstants.GRANT_READ:
for (Grant grant : accessControlPolicy.aclList.grants) {
if (grant.permission.compareTo(GWConstants.GRANT_FULL_CONTROL) == 0) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
} else if (grant.permission.compareTo(GWConstants.GRANT_READ) == 0) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
}
}
break;
case GWConstants.GRANT_WRITE:
for (Grant grant : accessControlPolicy.aclList.grants) {
if (grant.permission.compareTo(GWConstants.GRANT_FULL_CONTROL) == 0) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
} else if (grant.permission.compareTo(GWConstants.GRANT_WRITE) == 0) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
}
}
break;
case GWConstants.GRANT_READ_ACP:
for (Grant grant : accessControlPolicy.aclList.grants) {
if (grant.permission.compareTo(GWConstants.GRANT_FULL_CONTROL) == 0) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
} else if (grant.permission.compareTo(GWConstants.GRANT_READ_ACP) == 0) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
}
}
break;
case GWConstants.GRANT_WRITE_ACP:
for (Grant grant : accessControlPolicy.aclList.grants) {
if (grant.permission.compareTo(GWConstants.GRANT_FULL_CONTROL) == 0) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
} else if (grant.permission.compareTo(GWConstants.GRANT_WRITE_ACP) == 0) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
}
}
break;
case GWConstants.GRANT_FULL_CONTROL:
for (Grant grant : accessControlPolicy.aclList.grants) {
if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
return true;
}
} else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
if (grant.grantee.id.compareTo(id) == 0) {
return true;
}
}
}
break;
default:
logger.error(GWConstants.LOG_REQUEST_GRANT_NOT_DEFINED, s3grant);
new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
}
return false;
}
Aggregations