Search in sources :

Example 96 with GWException

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

the class DeleteBucketPolicy method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_DELETE_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);
    }
    updateBucketPolicy(bucket, "");
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Example 97 with GWException

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

the class DeleteBucketTagging method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_DELETE_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);
    }
    updateBucketTagging(bucket, "");
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Example 98 with GWException

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

the class DeleteBucketWebsite method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_DELETE_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);
    }
    updateBucketWeb(bucket, "");
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Example 99 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException 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 100 with GWException

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

the class DeleteObject method putDeleteMarker.

private void putDeleteMarker(String bucket, String object, S3Metadata s3Metadata, Metadata objMeta) throws GWException {
    try {
        String versionId = String.valueOf(System.nanoTime());
        s3Metadata.setDeleteMarker(GWConstants.OBJECT_TYPE_MARK);
        s3Metadata.setLastModified(new Date());
        s3Metadata.setContentLength(0L);
        s3Metadata.setTier(GWConstants.AWS_TIER_STANTARD);
        ObjectMapper jsonMapper = new ObjectMapper();
        String jsonmeta = "";
        jsonmeta = jsonMapper.writeValueAsString(s3Metadata);
        int result;
        objMeta.set("", "", jsonmeta, "", 0L);
        objMeta.setVersionId(versionId, GWConstants.OBJECT_TYPE_MARK, true);
        result = insertObject(bucket, object, objMeta);
        logger.debug(GWConstants.LOG_PUT_DELETE_MARKER);
        s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_DELETE_MARKER, GWConstants.XML_TRUE);
        s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, versionId);
    } catch (GWException | JsonProcessingException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
}
Also used : GWException(com.pspace.ifs.ksan.gw.exception.GWException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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