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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations