Search in sources :

Example 46 with S3Bucket

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

the class DeleteObject method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_DELETE_OBJECT_START);
    String bucket = s3Parameter.getBucketName();
    initBucketInfo(bucket);
    String object = s3Parameter.getObjectName();
    logger.debug(GWConstants.LOG_DELETE_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);
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE);
    DataDeleteObject dataDeleteObject = new DataDeleteObject(s3Parameter);
    dataDeleteObject.extract();
    S3Metadata s3Metadata = new S3Metadata();
    s3Metadata.setName(object);
    s3Metadata.setOwnerId(String.valueOf(s3Parameter.getUser().getUserId()));
    s3Metadata.setOwnerName(s3Parameter.getUser().getUserName());
    String versionId = dataDeleteObject.getVersionId();
    boolean isLastVersion = true;
    String deleteMarker = null;
    String versioningStatus = null;
    versioningStatus = getBucketVersioning(bucket);
    Metadata objMeta = null;
    try {
        if (Strings.isNullOrEmpty(versionId)) {
            objMeta = open(bucket, object);
        } else {
            objMeta = open(bucket, object, versionId);
        }
    } catch (GWException e) {
        if (e.getError().equals(GWErrorCode.NO_SUCH_KEY) && Strings.isNullOrEmpty(versionId) && versioningStatus.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED)) {
            objMeta = createLocal(bucket, object);
            putDeleteMarker(bucket, object, s3Metadata, objMeta);
        }
        s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, versionId);
        s3Parameter.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
        return;
    }
    S3ObjectOperation objectOperation = new S3ObjectOperation(objMeta, s3Metadata, s3Parameter, versionId, null);
    isLastVersion = objMeta.getLastVersion();
    deleteMarker = objMeta.getDeleteMarker();
    logger.debug(GWConstants.LOG_DELETE_OBJECT_INFO, versionId, isLastVersion, deleteMarker);
    logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING, versioningStatus);
    if (Strings.isNullOrEmpty(versioningStatus)) {
        logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_DISABLED);
        remove(bucket, object);
        objectOperation.deleteObject();
    } else {
        if (versioningStatus.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED)) {
            // Bucket Versioning Enabled
            logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_ENABLED);
            if (Strings.isNullOrEmpty(versionId)) {
                // request versionId is null
                if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_MARK)) {
                    remove(bucket, object, GWConstants.VERSIONING_DISABLE_TAIL);
                } else {
                    // put delete marker
                    putDeleteMarker(bucket, object, s3Metadata, objMeta);
                }
            } else {
                // request with versionId
                if (isLastVersion) {
                    remove(bucket, object, versionId);
                    if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_FILE)) {
                        objectOperation.deleteObject();
                    }
                } else {
                    // request with versionId not currentVid
                    remove(bucket, object, versionId);
                    objectOperation.deleteObject();
                }
            }
        } else if (versioningStatus.equalsIgnoreCase(GWConstants.VERSIONING_SUSPENDED)) {
            // Bucket Versioning Suspended
            logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_SUSPENDED);
            if (Strings.isNullOrEmpty(versionId)) {
                if (isLastVersion) {
                    if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_MARK)) {
                        remove(bucket, object, GWConstants.OBJECT_TYPE_MARK);
                    } else {
                        // put delete marker
                        putDeleteMarker(bucket, object, s3Metadata, objMeta);
                    }
                }
            } else {
                // request with versionId
                remove(bucket, object, versionId);
                objectOperation.deleteObject();
            }
        } else {
            logger.error(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_WRONG, versioningStatus);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, versionId);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Also used : S3ObjectOperation(com.pspace.ifs.ksan.gw.object.S3ObjectOperation) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) DataDeleteObject(com.pspace.ifs.ksan.gw.data.DataDeleteObject) 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)

Example 47 with S3Bucket

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

the class DeleteObjectTagging method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_DELETE_OBJECT_TAGGING_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);
    }
    DataDeleteObjectTagging dataDeleteObjectTagging = new DataDeleteObjectTagging(s3Parameter);
    dataDeleteObjectTagging.extract();
    String versionId = dataDeleteObjectTagging.getVersionId();
    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));
    checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE);
    objMeta.setTag("");
    updateObjectTagging(objMeta);
    s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, dataDeleteObjectTagging.getVersionId());
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) DataDeleteObjectTagging(com.pspace.ifs.ksan.gw.data.DataDeleteObjectTagging) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Example 48 with S3Bucket

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

the class GetObjectAcl method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_OBJECT_ACL_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);
    }
    DataGetObjectAcl dataGetObjectAcl = new DataGetObjectAcl(s3Parameter);
    dataGetObjectAcl.extract();
    String versionId = dataGetObjectAcl.getVersionId();
    Metadata objMeta = null;
    if (Strings.isNullOrEmpty(versionId)) {
        objMeta = open(bucket, object);
    } else {
        objMeta = open(bucket, object, versionId);
    }
    logger.debug(GWConstants.LOG_OBJECT_META, objMeta.toString());
    objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
    checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ_ACP);
    String aclInfo = objMeta.getAcl();
    if (!aclInfo.contains(GWConstants.XML_VERSION)) {
        aclInfo = GWConstants.XML_VERSION_FULL_STANDALONE + aclInfo;
    }
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY, GWConstants.ACCESS_CONTROL_POLICY_XMLNS);
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY_ID, "");
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY_DISPLAY_NAME, "");
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY_EMAIL_ADDRESS, "");
    aclInfo = aclInfo.replace(GWConstants.ACCESS_CONTROL_POLICY_URI, "");
    logger.debug(GWConstants.LOG_ACL, aclInfo);
    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) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) DataGetObjectAcl(com.pspace.ifs.ksan.gw.data.DataGetObjectAcl) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Example 49 with S3Bucket

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

the class GetObjectLockConfiguration method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_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_READ_ACP);
    String objectLock = getBucketInfo().getObjectLock();
    logger.debug(GWConstants.LOG_OBJECT_LOCK, objectLock);
    if (Strings.isNullOrEmpty(objectLock)) {
        throw new GWException(GWErrorCode.OBJECT_LOCK_CONFIGURATION_NOT_FOUND_ERROR, s3Parameter);
    }
    try {
        ObjectLockConfiguration configuration = new XmlMapper().readValue(objectLock, ObjectLockConfiguration.class);
        if (!GWConstants.STATUS_ENABLED.equals(configuration.objectLockEnabled)) {
            throw new GWException(GWErrorCode.OBJECT_LOCK_CONFIGURATION_NOT_FOUND_ERROR, s3Parameter);
        }
        if (!Strings.isNullOrEmpty(objectLock)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(objectLock.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) ObjectLockConfiguration(com.pspace.ifs.ksan.gw.format.ObjectLockConfiguration) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 50 with S3Bucket

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

the class GetPublicAccessBlock method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_PUBLIC_ACCESS_BLOCK_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);
    }
    String access = getBucketInfo().getAccess();
    logger.debug(GWConstants.LOG_ACCESS, access);
    if (Strings.isNullOrEmpty(access)) {
        throw new GWException(GWErrorCode.NO_SUCH_PUBLICACCESSBLOCK_CONFIGURATION, s3Parameter);
    }
    try {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        s3Parameter.getResponse().getOutputStream().write(access.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