Search in sources :

Example 1 with DataPutBucketObjectLock

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

the class PutObjectLockConfiguration method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_PUT_BUCKET_OBJECT_LOCK_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);
    DataPutBucketObjectLock dataPutBucketObjectLock = new DataPutBucketObjectLock(s3Parameter);
    dataPutBucketObjectLock.extract();
    String ObjectLockXml = dataPutBucketObjectLock.getObjectLockXml();
    if (Strings.isNullOrEmpty(getBucketInfo().getObjectLock())) {
        throw new GWException(GWErrorCode.INVALID_BUCKET_STATE, s3Parameter);
    }
    if (Strings.isNullOrEmpty(ObjectLockXml)) {
        throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
    }
    logger.info(GWConstants.LOG_PUT_BUCKET_OBJECT_LOCK, getBucketInfo().getObjectLock());
    try {
        ObjectLockConfiguration oc = new XmlMapper().readValue(getBucketInfo().getObjectLock(), ObjectLockConfiguration.class);
        if (!oc.objectLockEnabled.equals(GWConstants.STATUS_ENABLED)) {
            throw new GWException(GWErrorCode.INVALID_BUCKET_STATE, s3Parameter);
        }
        oc = new XmlMapper().readValue(ObjectLockXml, ObjectLockConfiguration.class);
        if (!oc.objectLockEnabled.equals(GWConstants.STATUS_ENABLED)) {
            throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
        }
        if (!Strings.isNullOrEmpty(oc.rules.defaultRetention.days) && !Strings.isNullOrEmpty(oc.rules.defaultRetention.years)) {
            throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
        }
        if (!Strings.isNullOrEmpty(oc.rules.defaultRetention.days)) {
            try {
                if (Integer.parseInt(oc.rules.defaultRetention.days) <= 0) {
                    throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
                }
            } catch (NumberFormatException e) {
                throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
            }
        }
        if (!Strings.isNullOrEmpty(oc.rules.defaultRetention.years)) {
            try {
                if (Integer.parseInt(oc.rules.defaultRetention.years) <= 0) {
                    throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
                }
            } catch (NumberFormatException e) {
                throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
            }
        }
        if (!Strings.isNullOrEmpty(oc.rules.defaultRetention.mode)) {
            if (!oc.rules.defaultRetention.mode.equals(GWConstants.GOVERNANCE) && !oc.rules.defaultRetention.mode.equals(GWConstants.COMPLIANCE)) {
                throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
            }
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    updateBucketObjectLock(bucket, ObjectLockXml);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) ObjectLockConfiguration(com.pspace.ifs.ksan.gw.format.ObjectLockConfiguration) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException) DataPutBucketObjectLock(com.pspace.ifs.ksan.gw.data.DataPutBucketObjectLock) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 DataPutBucketObjectLock (com.pspace.ifs.ksan.gw.data.DataPutBucketObjectLock)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 ObjectLockConfiguration (com.pspace.ifs.ksan.gw.format.ObjectLockConfiguration)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1 IOException (java.io.IOException)1