Search in sources :

Example 26 with Metadata

use of com.pspace.ifs.ksan.objmanager.Metadata 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 27 with Metadata

use of com.pspace.ifs.ksan.objmanager.Metadata in project ksan by infinistor.

the class DeleteObjects method deleteObject.

public void deleteObject(S3Parameter s3Parameter, String object, String versionId, XMLStreamWriter xml, boolean quiet) throws GWException {
    String bucket = s3Parameter.getBucketName();
    String versioningStatus = getBucketInfo().getVersioning();
    Metadata objMeta = null;
    try {
        if (Strings.isNullOrEmpty(versionId)) {
            objMeta = open(bucket, object);
            versionId = objMeta.getVersionId();
        } else {
            objMeta = open(bucket, object, versionId);
        }
    } catch (GWException e) {
        logger.debug(GWConstants.LOG_DELETE_OBJECTS_QUIET_VALUE, quiet);
        if (!quiet) {
            try {
                xml.writeStartElement(GWConstants.DELETE_RESULT_DELETED);
                writeSimpleElement(xml, GWConstants.DELETE_RESULT_KEY, object);
                writeSimpleElement(xml, GWConstants.VERSIONID, versionId);
                xml.writeEndElement();
                logger.debug(GWConstants.LOG_DELETE_OBJECTS_ERROR, object, versionId, e.getError().getErrorCode(), e.getError().getMessage());
                return;
            } catch (XMLStreamException e1) {
                PrintStack.logging(logger, e1);
                throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
            }
        }
    }
    boolean isLastVersion = objMeta.getLastVersion();
    String deleteMarker = objMeta.getDeleteMarker();
    logger.debug(GWConstants.LOG_DELETE_OBJECT_INFO, versionId, isLastVersion, deleteMarker);
    S3ObjectOperation objectOperation = new S3ObjectOperation(objMeta, null, s3Parameter, versionId, null);
    try {
        if (versioningStatus.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED)) {
            // Bucket Versioning Enabled
            logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_ENABLED);
            if (GWConstants.VERSIONING_DISABLE_TAIL.equals(versionId)) {
                // request versionId is null
                if (deleteMarker != null && deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_MARK)) {
                    remove(bucket, object, versionId);
                    if (!quiet) {
                        xml.writeStartElement(GWConstants.DELETE_RESULT_DELETED);
                        writeSimpleElement(xml, GWConstants.DELETE_RESULT_KEY, object);
                        xml.writeEndElement();
                    }
                } else {
                    try {
                        S3Metadata s3Metadata = new S3Metadata();
                        s3Metadata.setName(object);
                        s3Metadata.setOwnerId(String.valueOf(s3Parameter.getUser().getUserId()));
                        s3Metadata.setOwnerName(s3Parameter.getUser().getUserName());
                        s3Metadata.setDeleteMarker(GWConstants.OBJECT_TYPE_MARK);
                        s3Metadata.setVersionId(versionId);
                        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);
                        xml.writeStartElement(GWConstants.DELETE_RESULT_DELETED);
                        writeSimpleElement(xml, GWConstants.DELETE_RESULT_KEY, object);
                        writeSimpleElement(xml, GWConstants.XML_DELETE_MARKER, GWConstants.XML_TRUE);
                        writeSimpleElement(xml, GWConstants.DELETE_RESULT_DELETE_MARKER_VERSION_ID, versionId);
                        xml.writeEndElement();
                    } catch (GWException | JsonProcessingException e) {
                        PrintStack.logging(logger, e);
                        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
                    }
                }
            } else {
                // request with versionId
                if (isLastVersion) {
                    // request with versionId and same currentVid
                    if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_MARK)) {
                        remove(bucket, object);
                    } else if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_FILE)) {
                        remove(bucket, object, versionId);
                        objectOperation.deleteObject();
                    }
                } else {
                    // request with versionId not currentVid
                    remove(bucket, object, versionId);
                    objectOperation.deleteObject();
                }
                if (!quiet) {
                    xml.writeStartElement(GWConstants.DELETE_RESULT_DELETED);
                    writeSimpleElement(xml, GWConstants.DELETE_RESULT_KEY, object);
                    writeSimpleElement(xml, GWConstants.VERSIONID, versionId);
                    xml.writeEndElement();
                }
            }
        } else if (versioningStatus.equalsIgnoreCase(GWConstants.VERSIONING_SUSPENDED)) {
            // Bucket Versioning Suspended
            logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_SUSPENDED);
            if (GWConstants.VERSIONING_DISABLE_TAIL.equals(versionId)) {
                if (isLastVersion) {
                    if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_MARK)) {
                        remove(bucket, object, versionId);
                    } else {
                        try {
                            S3Metadata s3Metadata = new S3Metadata();
                            s3Metadata.setName(object);
                            s3Metadata.setOwnerId(String.valueOf(s3Parameter.getUser().getUserId()));
                            s3Metadata.setOwnerName(s3Parameter.getUser().getUserName());
                            s3Metadata.setDeleteMarker(GWConstants.OBJECT_TYPE_MARK);
                            s3Metadata.setVersionId(versionId);
                            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);
                            // }
                            if (result != 0) {
                                logger.error(GWConstants.LOG_DELETE_OBJECT_FAILED_MARKER, bucket, object);
                            }
                            logger.debug(GWConstants.LOG_PUT_DELETE_MARKER);
                        } catch (GWException | JsonProcessingException e) {
                            PrintStack.logging(logger, e);
                            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
                        }
                    }
                }
            } else {
                // request with versionId
                remove(bucket, object, versionId);
                objectOperation.deleteObject();
            }
            if (!quiet) {
                xml.writeStartElement(GWConstants.DELETE_RESULT_DELETED);
                writeSimpleElement(xml, GWConstants.DELETE_RESULT_KEY, object);
                writeSimpleElement(xml, GWConstants.XML_DELETE_MARKER, GWConstants.STRING_TRUE);
                writeSimpleElement(xml, GWConstants.DELETE_RESULT_DELETE_MARKER_VERSION_ID, GWConstants.VERSIONING_DISABLE_TAIL);
                xml.writeEndElement();
            }
        } else {
            // Bucket Versioning Disabled
            logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_DISABLED);
            remove(bucket, object);
            objectOperation.deleteObject();
            if (!quiet) {
                xml.writeStartElement(GWConstants.DELETE_RESULT_DELETED);
                writeSimpleElement(xml, GWConstants.DELETE_RESULT_KEY, object);
                xml.writeEndElement();
            }
        }
    } catch (GWException e) {
        try {
            if (!quiet) {
                xml.writeStartElement(GWConstants.STRING_ERROR);
                writeSimpleElement(xml, GWConstants.DELETE_RESULT_KEY, object);
                writeSimpleElement(xml, GWConstants.VERSIONID, versionId);
                writeSimpleElement(xml, GWConstants.CODE, e.getError().getErrorCode());
                writeSimpleElement(xml, GWConstants.MESSAGE, e.getError().getMessage());
                xml.writeEndElement();
            }
        } catch (XMLStreamException e1) {
            throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
        }
    } catch (XMLStreamException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
    }
}
Also used : S3ObjectOperation(com.pspace.ifs.ksan.gw.object.S3ObjectOperation) XMLStreamException(javax.xml.stream.XMLStreamException) 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) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 28 with Metadata

use of com.pspace.ifs.ksan.objmanager.Metadata 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 29 with Metadata

use of com.pspace.ifs.ksan.objmanager.Metadata in project ksan by infinistor.

the class HeadObject method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_HEAD_OBJECT_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);
    }
    DataHeadObject dataHeadObject = new DataHeadObject(s3Parameter);
    dataHeadObject.extract();
    String versionId = dataHeadObject.getVersionId();
    String expectedBucketOwner = dataHeadObject.getExpectedBucketOwner();
    if (!Strings.isNullOrEmpty(expectedBucketOwner)) {
        if (!isBucketOwner(expectedBucketOwner)) {
            throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
        }
    }
    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));
    checkGrantObject(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    // meta info
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        logger.debug(GWConstants.LOG_META, objMeta.getMeta());
        S3Metadata s3Metadata = objectMapper.readValue(objMeta.getMeta(), S3Metadata.class);
        // check customer-key
        if (!Strings.isNullOrEmpty(s3Metadata.getCustomerKey())) {
            if (!Strings.isNullOrEmpty(dataHeadObject.getServerSideEncryptionCustomerKey())) {
                if (!s3Metadata.getCustomerKey().equals(dataHeadObject.getServerSideEncryptionCustomerKey())) {
                    logger.warn(GWConstants.ENCRYPTION_CUSTOMER_KEY_IS_INVALID);
                    throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
                }
            } else {
                logger.warn(GWConstants.ENCRYPTION_CUSTOMER_KEY_IS_NULL);
                throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
            }
        }
        s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, s3Metadata.getVersionId());
        GWUtils.addMetadataToResponse(s3Parameter.getRequest(), s3Parameter.getResponse(), s3Metadata, null, null);
    } catch (JsonProcessingException 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) 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) DataHeadObject(com.pspace.ifs.ksan.gw.data.DataHeadObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 30 with Metadata

use of com.pspace.ifs.ksan.objmanager.Metadata in project ksan by infinistor.

the class S3Request method getObjectWithVersionId.

protected Metadata getObjectWithVersionId(String bucket, String object, String versionId) throws GWException {
    Metadata objMeta = null;
    try {
        setObjManager();
        objMeta = objManager.getObjectWithVersionId(bucket, object, versionId);
    } catch (ResourceNotFoundException e) {
        logger.info(GWConstants.LOG_REQUEST_NOT_FOUND_IN_DB, bucket, object);
        throw new GWException(GWErrorCode.NO_SUCH_KEY, s3Parameter);
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    return objMeta;
}
Also used : Metadata(com.pspace.ifs.ksan.objmanager.Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) 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

Metadata (com.pspace.ifs.ksan.objmanager.Metadata)31 GWException (com.pspace.ifs.ksan.gw.exception.GWException)23 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)17 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)17 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 ResourceNotFoundException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)12 XMLStreamException (javax.xml.stream.XMLStreamException)12 IOException (java.io.IOException)11 S3ObjectOperation (com.pspace.ifs.ksan.gw.object.S3ObjectOperation)10 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)6 S3Object (com.pspace.ifs.ksan.gw.object.S3Object)6 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)6 ResourceAlreadyExistException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException)5 ObjMultipart (com.pspace.ifs.ksan.objmanager.ObjMultipart)5 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)4 AccessControlPolicy (com.pspace.ifs.ksan.gw.format.AccessControlPolicy)4 AccessControlList (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList)4 Grant (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant)4 Owner (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.Owner)4