Search in sources :

Example 11 with S3Bucket

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

the class GetBucketPolicy method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_POLICY_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 policy = getBucketInfo().getPolicy();
    logger.debug(GWConstants.LOG_GET_BUCKET_POLICY, policy);
    if (Strings.isNullOrEmpty(policy)) {
        throw new GWException(GWErrorCode.NO_SUCH_POLICY_CONFIGURATION, s3Parameter);
    }
    try {
        if (!Strings.isNullOrEmpty(policy)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(policy.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 12 with S3Bucket

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

the class GetBucketTagging method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_TAGGING_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 tag = getBucketInfo().getTagging();
    logger.debug(GWConstants.LOG_TAGGING, tag);
    if (Strings.isNullOrEmpty(tag)) {
        throw new GWException(GWErrorCode.NO_SUCH_TAG_SET_ERROR, s3Parameter);
    }
    try {
        if (!Strings.isNullOrEmpty(tag)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(tag.getBytes());
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Example 13 with S3Bucket

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

the class GetBucketVersioning method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_VERSIONING_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 versioningStatus = getBucketInfo().getVersioning();
    logger.debug(GWConstants.LOG_GET_BUCKET_VERSIONING, bucket, versioningStatus);
    String xml = null;
    if (Strings.isNullOrEmpty(versioningStatus)) {
        xml = GWConstants.VERSION_CONFIGURATION_XMLNS_DISABLE;
    } else {
        if (GWConstants.VERSIONING_ENABLED.equals(versioningStatus)) {
            xml = GWConstants.VERSION_CONFIGURATION_XMLNS_ENABLED;
        } else if (GWConstants.VERSIONING_SUSPENDED.equals(versioningStatus)) {
            xml = GWConstants.VERSION_CONFIGURATION_XMLNS_SUSPENDED;
        } else {
            logger.error(GWConstants.LOG_GET_BUCKET_VERSIONING_WRONG, versioningStatus);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    logger.debug(GWConstants.LOG_GET_BUCKET_VERSIONING_XML, xml);
    try {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        s3Parameter.getResponse().getOutputStream().write(xml.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 14 with S3Bucket

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

the class GetBucketWebsite method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_WEBSITE_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 web = getBucketInfo().getWeb();
    logger.debug(GWConstants.LOG_GET_BUCKET_WEBSITE, web);
    if (Strings.isNullOrEmpty(web)) {
        throw new GWException(GWErrorCode.NO_SUCH_WEBSITE_CONFIGURATION, s3Parameter);
    }
    try {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        s3Parameter.getResponse().getOutputStream().write(web.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 15 with S3Bucket

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

the class GetObject method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_OBJECT_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);
    }
    DataGetObject dataGetObject = new DataGetObject(s3Parameter);
    dataGetObject.extract();
    String versionId = dataGetObject.getVersionId();
    String range = dataGetObject.getRange();
    String ifMatch = dataGetObject.getIfMatch();
    String ifNoneMatch = dataGetObject.getIfNoneMatch();
    String ifModifiedSince = dataGetObject.getIfModifiedSince();
    String ifUnmodifiedSince = dataGetObject.getIfUnmodifiedSince();
    String versioningStatus = getBucketVersioning(bucket);
    Metadata objMeta = null;
    if (Strings.isNullOrEmpty(versionId)) {
        objMeta = open(bucket, object);
        versionId = objMeta.getVersionId();
    } else {
        objMeta = open(bucket, object, versionId);
    }
    logger.debug(GWConstants.LOG_OBJECT_META, objMeta.toString());
    objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
    checkGrantObject(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    S3Metadata s3Metadata = null;
    // meta info
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        logger.debug(GWConstants.LOG_META, objMeta.getMeta());
        s3Metadata = objectMapper.readValue(objMeta.getMeta(), S3Metadata.class);
    } catch (JsonProcessingException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    // check customer-key
    if (!Strings.isNullOrEmpty(s3Metadata.getCustomerKey())) {
        if (!Strings.isNullOrEmpty(dataGetObject.getServerSideEncryptionCustomerKey())) {
            if (!s3Metadata.getCustomerKey().equals(dataGetObject.getServerSideEncryptionCustomerKey())) {
                logger.warn(GWConstants.LOG_GET_OBJECT_CUSTOMER_KEY_NO_MATCH);
                throw new GWException(GWErrorCode.KEY_DOES_NOT_MATCH, s3Parameter);
            }
        } else {
            logger.warn(GWConstants.ENCRYPTION_CUSTOMER_KEY_IS_NULL);
            throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
        }
    }
    // Check match
    if (!Strings.isNullOrEmpty(ifMatch)) {
        logger.debug(GWConstants.LOG_GET_OBJECT_IF_MATCH_ETAG, s3Metadata.getETag(), ifMatch.replace(GWConstants.DOUBLE_QUOTE, ""));
        if (!s3Metadata.getETag().equals(ifMatch.replace(GWConstants.DOUBLE_QUOTE, ""))) {
            logger.error(GWConstants.LOG_GET_OBJECT_ETAG_DIFFERENT);
            throw new GWException(GWErrorCode.PRECONDITION_FAILED, s3Parameter);
        }
    }
    if (!Strings.isNullOrEmpty(ifNoneMatch)) {
        logger.debug(GWConstants.LOG_GET_OBJECT_IF_NONE_MATCH_ETAG, s3Metadata.getETag(), ifNoneMatch.replace(GWConstants.DOUBLE_QUOTE, ""));
        if (s3Metadata.getETag().equals(ifNoneMatch.replace(GWConstants.DOUBLE_QUOTE, ""))) {
            logger.error(GWConstants.LOG_GET_OBJECT_ETAG_SAME);
            throw new GWException(GWErrorCode.DOES_NOT_MATCH, String.format(GWConstants.LOG_ETAG_IS_MISMATCH), s3Parameter);
        }
    }
    if (!Strings.isNullOrEmpty(ifModifiedSince)) {
        Date modifiedSince = new Date(ifModifiedSince);
        if (s3Metadata.getLastModified().before(modifiedSince)) {
            throw new GWException(GWErrorCode.DOES_NOT_MATCH, String.format(GWConstants.LOG_MATCH_BEFORE, s3Metadata.getLastModified(), modifiedSince), s3Parameter);
        }
    }
    if (!Strings.isNullOrEmpty(ifUnmodifiedSince)) {
        Date unmodifiedSince = new Date(ifUnmodifiedSince);
        if (s3Metadata.getLastModified().after(unmodifiedSince)) {
            throw new GWException(GWErrorCode.PRECONDITION_FAILED, String.format(GWConstants.LOG_MATCH_AFTER, s3Metadata.getLastModified(), unmodifiedSince), s3Parameter);
        }
    }
    ResultRange resultRange = new ResultRange(range, s3Metadata, s3Parameter);
    addMetadataToResponse(s3Parameter.getResponse(), s3Metadata, resultRange.getContentLengthHeaders(), resultRange.getStreamSize());
    S3ObjectOperation objectOperation = new S3ObjectOperation(objMeta, s3Metadata, s3Parameter, versionId, null);
    try {
        objectOperation.getObject(resultRange.getS3Range());
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    s3Parameter.getResponse().setStatus(resultRange.getStatus());
}
Also used : S3ObjectOperation(com.pspace.ifs.ksan.gw.object.S3ObjectOperation) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) ResultRange(com.pspace.ifs.ksan.gw.object.ResultRange) DataGetObject(com.pspace.ifs.ksan.gw.data.DataGetObject) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

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