Search in sources :

Example 51 with S3Bucket

use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.

the class HeadBucket method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_HEAD_BUCKET_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);
    }
    checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    DataHeadBucket dataHeadBucket = new DataHeadBucket(s3Parameter);
    dataHeadBucket.extract();
    String expectedBucketOwner = dataHeadBucket.getExpectedBucketOwner();
    if (!Strings.isNullOrEmpty(expectedBucketOwner)) {
        if (!isBucketOwner(expectedBucketOwner)) {
            throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
        }
    }
    if (isGrant(String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ)) {
        s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
    } else {
        throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
    }
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) DataHeadBucket(com.pspace.ifs.ksan.gw.data.DataHeadBucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Example 52 with S3Bucket

use of com.pspace.ifs.ksan.gw.identity.S3Bucket 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)

Example 53 with S3Bucket

use of com.pspace.ifs.ksan.gw.identity.S3Bucket 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)

Example 54 with S3Bucket

use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.

the class GetBucketEncryption method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_ENCRYPTION_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_READ_ACP);
    String encryption = getBucketInfo().getEncryption();
    logger.debug(GWConstants.LOG_GET_BUCKET_ENCRYPTION, encryption);
    if (Strings.isNullOrEmpty(encryption)) {
        throw new GWException(GWErrorCode.NO_SUCH_ENCRYPTION_CONFIGURATION, s3Parameter);
    }
    try {
        if (!Strings.isNullOrEmpty(encryption)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(encryption.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) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Example 55 with S3Bucket

use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.

the class GetBucketLifecycleConfiguration method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_LIFECYCLE_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_READ_ACP);
    String lifecycle = getBucketInfo().getLifecycle();
    logger.debug(GWConstants.LOG_GET_BUCKET_LIFECYCLE, lifecycle);
    if (Strings.isNullOrEmpty(lifecycle)) {
        throw new GWException(GWErrorCode.NO_SUCH_LIFECYCLE_CONFIGURATION, s3Parameter);
    }
    try {
        if (!Strings.isNullOrEmpty(lifecycle)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(lifecycle.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) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Aggregations

GWException (com.pspace.ifs.ksan.gw.exception.GWException)57 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)57 IOException (java.io.IOException)31 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)17 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)16 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)14 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)14 XMLStreamException (javax.xml.stream.XMLStreamException)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Writer (java.io.Writer)12 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)12 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)10 S3ObjectOperation (com.pspace.ifs.ksan.gw.object.S3ObjectOperation)9 ObjMultipart (com.pspace.ifs.ksan.objmanager.ObjMultipart)7 S3Object (com.pspace.ifs.ksan.gw.object.S3Object)6 UnknownHostException (java.net.UnknownHostException)6 AccessControlPolicy (com.pspace.ifs.ksan.gw.format.AccessControlPolicy)5 AccessControlList (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList)5 Grant (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant)5 Owner (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.Owner)5