use of com.pspace.ifs.ksan.gw.data.DataHeadObject 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);
}
Aggregations