Search in sources :

Example 1 with DataHeadObject

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

the class HeadObject method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_HEAD_OBJECT_START);
    String bucket = s3Parameter.getBucketName();
    initBucketInfo(bucket);
    String object = s3Parameter.getObjectName();
    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);
    }
    DataHeadObject dataHeadObject = new DataHeadObject(s3Parameter);
    dataHeadObject.extract();
    String versionId = dataHeadObject.getVersionId();
    String expectedBucketOwner = dataHeadObject.getExpectedBucketOwner();
    if (!Strings.isNullOrEmpty(expectedBucketOwner)) {
        if (!isBucketOwner(expectedBucketOwner)) {
            throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
        }
    }
    Metadata objMeta = null;
    if (Strings.isNullOrEmpty(versionId)) {
        objMeta = open(bucket, object);
        versionId = objMeta.getVersionId();
    } else {
        objMeta = open(bucket, object, versionId);
    }
    objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
    checkGrantObject(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    // meta info
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        logger.debug(GWConstants.LOG_META, objMeta.getMeta());
        S3Metadata s3Metadata = objectMapper.readValue(objMeta.getMeta(), S3Metadata.class);
        // check customer-key
        if (!Strings.isNullOrEmpty(s3Metadata.getCustomerKey())) {
            if (!Strings.isNullOrEmpty(dataHeadObject.getServerSideEncryptionCustomerKey())) {
                if (!s3Metadata.getCustomerKey().equals(dataHeadObject.getServerSideEncryptionCustomerKey())) {
                    logger.warn(GWConstants.ENCRYPTION_CUSTOMER_KEY_IS_INVALID);
                    throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
                }
            } else {
                logger.warn(GWConstants.ENCRYPTION_CUSTOMER_KEY_IS_NULL);
                throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
            }
        }
        s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, s3Metadata.getVersionId());
        GWUtils.addMetadataToResponse(s3Parameter.getRequest(), s3Parameter.getResponse(), s3Metadata, null, null);
    } catch (JsonProcessingException 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) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) DataHeadObject(com.pspace.ifs.ksan.gw.data.DataHeadObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DataHeadObject (com.pspace.ifs.ksan.gw.data.DataHeadObject)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)1 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)1