use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class HeadBucket method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_HEAD_BUCKET_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);
}
checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
DataHeadBucket dataHeadBucket = new DataHeadBucket(s3Parameter);
dataHeadBucket.extract();
String expectedBucketOwner = dataHeadBucket.getExpectedBucketOwner();
if (!Strings.isNullOrEmpty(expectedBucketOwner)) {
if (!isBucketOwner(expectedBucketOwner)) {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
}
if (isGrant(String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ)) {
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
} else {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
}
use of com.pspace.ifs.ksan.gw.identity.S3Bucket 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);
}
use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class GetBucketAcl method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_BUCKET_ACL_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);
}
DataGetObjectAcl dataGetObjectAcl = new DataGetObjectAcl(s3Parameter);
dataGetObjectAcl.extract();
String aclInfo = getBucketInfo().getAcl();
logger.debug(GWConstants.LOG_ACL, aclInfo);
if (!aclInfo.contains(GWConstants.XML_VERSION)) {
aclInfo = GWConstants.XML_VERSION_FULL_STANDALONE + aclInfo;
}
checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ_ACP);
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);
}
use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class GetBucketEncryption method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_BUCKET_ENCRYPTION_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 encryption = getBucketInfo().getEncryption();
logger.debug(GWConstants.LOG_GET_BUCKET_ENCRYPTION, encryption);
if (Strings.isNullOrEmpty(encryption)) {
throw new GWException(GWErrorCode.NO_SUCH_ENCRYPTION_CONFIGURATION, s3Parameter);
}
try {
if (!Strings.isNullOrEmpty(encryption)) {
s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
s3Parameter.getResponse().getOutputStream().write(encryption.getBytes());
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class GetBucketLifecycleConfiguration method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_BUCKET_LIFECYCLE_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 lifecycle = getBucketInfo().getLifecycle();
logger.debug(GWConstants.LOG_GET_BUCKET_LIFECYCLE, lifecycle);
if (Strings.isNullOrEmpty(lifecycle)) {
throw new GWException(GWErrorCode.NO_SUCH_LIFECYCLE_CONFIGURATION, s3Parameter);
}
try {
if (!Strings.isNullOrEmpty(lifecycle)) {
s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
s3Parameter.getResponse().getOutputStream().write(lifecycle.getBytes());
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Aggregations