Search in sources :

Example 1 with DataGetObjectAcl

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

the class GetObjectAcl method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_OBJECT_ACL_START);
    String bucket = s3Parameter.getBucketName();
    initBucketInfo(bucket);
    String object = s3Parameter.getObjectName();
    logger.debug(GWConstants.LOG_BUCKET_OBJECT, bucket, object);
    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);
    }
    DataGetObjectAcl dataGetObjectAcl = new DataGetObjectAcl(s3Parameter);
    dataGetObjectAcl.extract();
    String versionId = dataGetObjectAcl.getVersionId();
    Metadata objMeta = null;
    if (Strings.isNullOrEmpty(versionId)) {
        objMeta = open(bucket, object);
    } else {
        objMeta = open(bucket, object, versionId);
    }
    logger.debug(GWConstants.LOG_OBJECT_META, objMeta.toString());
    objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
    checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ_ACP);
    String aclInfo = objMeta.getAcl();
    if (!aclInfo.contains(GWConstants.XML_VERSION)) {
        aclInfo = GWConstants.XML_VERSION_FULL_STANDALONE + aclInfo;
    }
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY, GWConstants.ACCESS_CONTROL_POLICY_XMLNS);
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY_ID, "");
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY_DISPLAY_NAME, "");
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY_EMAIL_ADDRESS, "");
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY_URI, "");
    logger.debug(GWConstants.LOG_ACL, aclInfo);
    try {
        if (!Strings.isNullOrEmpty(aclInfo)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(aclInfo.getBytes());
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) DataGetObjectAcl(com.pspace.ifs.ksan.gw.data.DataGetObjectAcl) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Example 2 with DataGetObjectAcl

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

the class GetBucketAcl method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_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);
    }
    DataGetObjectAcl dataGetObjectAcl = new DataGetObjectAcl(s3Parameter);
    dataGetObjectAcl.extract();
    String aclInfo = getBucketInfo().getAcl();
    logger.debug(GWConstants.LOG_ACL, aclInfo);
    if (!aclInfo.contains(GWConstants.XML_VERSION)) {
        aclInfo = GWConstants.XML_VERSION_FULL_STANDALONE + aclInfo;
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ_ACP);
    try {
        if (!Strings.isNullOrEmpty(aclInfo)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(aclInfo.getBytes());
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) DataGetObjectAcl(com.pspace.ifs.ksan.gw.data.DataGetObjectAcl) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Aggregations

DataGetObjectAcl (com.pspace.ifs.ksan.gw.data.DataGetObjectAcl)2 GWException (com.pspace.ifs.ksan.gw.exception.GWException)2 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)2 IOException (java.io.IOException)2 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)1