Search in sources :

Example 31 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class PutBucketTagging method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_PUT_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_WRITE_ACP);
    DataPutBucketTagging dataPutBucketTagging = new DataPutBucketTagging(s3Parameter);
    dataPutBucketTagging.extract();
    String taggingXml = dataPutBucketTagging.getTaggingXml();
    logger.debug(GWConstants.LOG_PUT_BUCKET_TAGGING, taggingXml);
    try {
        Tagging tagging = new XmlMapper().readValue(taggingXml, Tagging.class);
        // 중복 지우기 item이 10개 미만이기 때문에 for loop가 빠름
        if (tagging != null) {
            if (tagging.tagset != null && tagging.tagset.tags != null) {
                for (Tag t : tagging.tagset.tags) {
                    // key, value 길이 체크
                    if (t.key.length() > 128) {
                        throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
                    }
                    if (t.value.length() > 256) {
                        throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
                    }
                }
            }
            if (tagging.tagset != null && tagging.tagset.tags != null) {
                if (tagging.tagset.tags.size() > 10) {
                    throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
                }
            }
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    updateBucketTagging(bucket, taggingXml);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) DataPutBucketTagging(com.pspace.ifs.ksan.gw.data.DataPutBucketTagging) Tagging(com.pspace.ifs.ksan.gw.format.Tagging) DataPutBucketTagging(com.pspace.ifs.ksan.gw.data.DataPutBucketTagging) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Tag(com.pspace.ifs.ksan.gw.format.Tagging.TagSet.Tag) IOException(java.io.IOException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 32 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class PutBucketVersioning method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_PUT_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_WRITE_ACP);
    DataPutBucketVersioning dataPutBucketVersioning = new DataPutBucketVersioning(s3Parameter);
    dataPutBucketVersioning.extract();
    String versionXml = dataPutBucketVersioning.getVersioningXml();
    if (!Strings.isNullOrEmpty(versionXml)) {
        Versioning versioning = new Versioning();
        try {
            versioning = new XmlMapper().readValue(versionXml, Versioning.class);
        } catch (JsonProcessingException e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
        if (versioning.status != null && !versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED) && !versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_SUSPENDED)) {
            throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
        }
        if (!Strings.isNullOrEmpty(getBucketInfo().getObjectLock())) {
            if (!versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED)) {
                throw new GWException(GWErrorCode.INVALID_BUCKET_STATE, s3Parameter);
            }
        }
        if (!Strings.isNullOrEmpty(versioning.status)) {
            putBucketVersioning(bucket, versioning.status);
        }
    }
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : DataPutBucketVersioning(com.pspace.ifs.ksan.gw.data.DataPutBucketVersioning) Versioning(com.pspace.ifs.ksan.gw.format.Versioning) DataPutBucketVersioning(com.pspace.ifs.ksan.gw.data.DataPutBucketVersioning) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 33 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class PutObjectAcl method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_PUT_OBJECT_ACL_START);
    String bucket = s3Parameter.getBucketName();
    String object = s3Parameter.getObjectName();
    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);
    }
    DataPutObjectAcl dataPutObjectAcl = new DataPutObjectAcl(s3Parameter);
    dataPutObjectAcl.extract();
    String versionId = dataPutObjectAcl.getVersionId();
    Metadata objMeta = null;
    if (Strings.isNullOrEmpty(versionId)) {
        objMeta = open(bucket, object);
    } else {
        objMeta = open(bucket, object, versionId);
    }
    objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
    checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE_ACP);
    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, null, dataPutObjectAcl.hasAclKeyword(), dataPutObjectAcl.getAclXml(), dataPutObjectAcl.getAcl(), getBucketInfo(), String.valueOf(s3Parameter.getUser().getUserId()), s3Parameter.getUser().getUserName(), dataPutObjectAcl.getGrantRead(), dataPutObjectAcl.getGrantWrite(), dataPutObjectAcl.getGrantFullControl(), dataPutObjectAcl.getGrantReadAcp(), dataPutObjectAcl.getGrantWriteAcp(), s3Parameter);
    logger.debug(GWConstants.LOG_ACL, xml);
    objMeta.setAcl(xml);
    updateObjectAcl(objMeta);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : AccessControlList(com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList) 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) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) DataPutObjectAcl(com.pspace.ifs.ksan.gw.data.DataPutObjectAcl) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Example 34 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class PutObjectTagging method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_PUT_OBJECT_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);
    }
    checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE);
    String object = s3Parameter.getObjectName();
    DataPutObjectTagging dataPutObjectTagging = new DataPutObjectTagging(s3Parameter);
    dataPutObjectTagging.extract();
    String taggingCount = GWConstants.TAGGING_INIT;
    String taggingXml = dataPutObjectTagging.getTaggingXml();
    try {
        Tagging tagging = new XmlMapper().readValue(taggingXml, Tagging.class);
        // 중복 지우기 item이 10개 미만이기 때문에 for loop가 빠름
        if (tagging != null) {
            if (tagging.tagset != null && tagging.tagset.tags != null) {
                for (Tag t : tagging.tagset.tags) {
                    // key, value 길이 체크
                    if (t.key.length() > GWConstants.TAG_KEY_MAX) {
                        throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
                    }
                    if (t.value.length() > GWConstants.TAG_VALUE_MAX) {
                        throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
                    }
                }
            }
            if (tagging.tagset != null && tagging.tagset.tags != null) {
                if (tagging.tagset.tags.size() > GWConstants.TAG_MAX_SIZE) {
                    throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
                }
                taggingCount = String.valueOf(tagging.tagset.tags.size());
            }
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    String versionId = dataPutObjectTagging.getVersionId();
    Metadata objMeta = null;
    if (Strings.isNullOrEmpty(versionId)) {
        objMeta = open(bucket, object);
    } else {
        objMeta = open(bucket, object, versionId);
    }
    S3Metadata s3Metadata = null;
    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);
    }
    s3Metadata.setTaggingCount(taggingCount);
    ObjectMapper jsonMapper = new ObjectMapper();
    String jsonMeta = "";
    try {
        jsonMeta = jsonMapper.writeValueAsString(s3Metadata);
    } catch (JsonProcessingException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    objMeta.setMeta(jsonMeta);
    objMeta.setTag(taggingXml);
    updateObjectTagging(objMeta);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) Tagging(com.pspace.ifs.ksan.gw.format.Tagging) DataPutObjectTagging(com.pspace.ifs.ksan.gw.data.DataPutObjectTagging) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) DataPutObjectTagging(com.pspace.ifs.ksan.gw.data.DataPutObjectTagging) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Tag(com.pspace.ifs.ksan.gw.format.Tagging.TagSet.Tag) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 35 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class S3Request method updateBucketPolicy.

protected void updateBucketPolicy(String bucket, String policy) throws GWException {
    try {
        setObjManager();
        objManager.updateBucketPolicy(bucket, policy);
    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
}
Also used : GWException(com.pspace.ifs.ksan.gw.exception.GWException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) XMLStreamException(javax.xml.stream.XMLStreamException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

GWException (com.pspace.ifs.ksan.gw.exception.GWException)130 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)61 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)58 XMLStreamException (javax.xml.stream.XMLStreamException)48 IOException (java.io.IOException)46 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)45 ResourceNotFoundException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)43 ResourceAlreadyExistException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException)32 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)23 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)23 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)15 AccessControlPolicy (com.pspace.ifs.ksan.gw.format.AccessControlPolicy)14 Writer (java.io.Writer)13 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 Grant (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant)10 S3ObjectOperation (com.pspace.ifs.ksan.gw.object.S3ObjectOperation)10 Date (java.util.Date)8