Search in sources :

Example 1 with DataPutBucketAcl

use of com.pspace.ifs.ksan.gw.data.DataPutBucketAcl in project ksan by infinistor.

the class PutBucketAcl method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_PUT_BUCKET_ACL_START);
    String bucket = s3Parameter.getBucketName();
    initBucketInfo(bucket);
    S3Bucket s3Bucket = new S3Bucket();
    s3Bucket.setCors(getBucketInfo().getCors());
    s3Bucket.setAccess(getBucketInfo().getAccess());
    s3Parameter.setBucket(s3Bucket);
    GWUtils.checkCors(s3Parameter);
    if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
        throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE_ACP);
    DataPutBucketAcl dataPutBucketAcl = new DataPutBucketAcl(s3Parameter);
    dataPutBucketAcl.extract();
    AccessControlPolicy preAccessControlPolicy = null;
    try {
        XmlMapper xmlMapper = new XmlMapper();
        preAccessControlPolicy = xmlMapper.readValue(getBucketInfo().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);
    }
    accessControlPolicy = new AccessControlPolicy();
    accessControlPolicy.aclList = new AccessControlList();
    accessControlPolicy.aclList.grants = new ArrayList<Grant>();
    accessControlPolicy.owner = new Owner();
    accessControlPolicy.owner.id = String.valueOf(s3Parameter.getUser().getUserId());
    accessControlPolicy.owner.displayName = s3Parameter.getUser().getUserName();
    String xml = GWUtils.makeAclXml(accessControlPolicy, preAccessControlPolicy, dataPutBucketAcl.hasAclKeyword(), dataPutBucketAcl.getAclXml(), dataPutBucketAcl.getAcl(), getBucketInfo(), String.valueOf(s3Parameter.getUser().getUserId()), s3Parameter.getUser().getUserName(), dataPutBucketAcl.getGrantRead(), dataPutBucketAcl.getGrantWrite(), dataPutBucketAcl.getGrantFullControl(), dataPutBucketAcl.getGrantReadAcp(), dataPutBucketAcl.getGrantWriteAcp(), s3Parameter);
    logger.debug(GWConstants.LOG_ACL, xml);
    updateBucketAcl(bucket, xml);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : AccessControlList(com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList) DataPutBucketAcl(com.pspace.ifs.ksan.gw.data.DataPutBucketAcl) Grant(com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant) AccessControlPolicy(com.pspace.ifs.ksan.gw.format.AccessControlPolicy) Owner(com.pspace.ifs.ksan.gw.format.AccessControlPolicy.Owner) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 DataPutBucketAcl (com.pspace.ifs.ksan.gw.data.DataPutBucketAcl)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 AccessControlPolicy (com.pspace.ifs.ksan.gw.format.AccessControlPolicy)1 AccessControlList (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList)1 Grant (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant)1 Owner (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.Owner)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1