use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class PutBucketReplication method checkBucketReplication.
private void checkBucketReplication(String replicationXml) throws GWException {
XmlMapper xmlMapper = new XmlMapper();
ReplicationConfiguration rc;
try {
rc = xmlMapper.readValue(replicationXml, ReplicationConfiguration.class);
} catch (JsonMappingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
}
Map<String, String> id = new HashMap<String, String>();
if (rc.rules != null) {
logger.warn(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULES, rc.rules.toString());
for (Rule rl : rc.rules) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_ID, rl.id);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_PREFIX, rl.prefix);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_PRIORITY, rl.priority);
if (rl.id != null) {
if (rl.id.length() > 255) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
id.put(rl.id, rl.id);
} else {
// length is bounded by 7
byte[] array = new byte[7];
new Random().nextBytes(array);
String generatedString = new String(array, Charset.forName(GWConstants.CHARSET_UTF_8));
id.put(generatedString, generatedString);
}
if (rl.existingObjectReplication != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_EXISTING_OBJECT_REPLICATION, rl.existingObjectReplication);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_EXISTING_OBJECT_REPLICATION_STATUS, rl.existingObjectReplication.status);
}
if (rl.filter != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER, rl.filter);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND, rl.filter.and);
if (rl.filter.and != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_PREFIX, rl.filter.and.prefix);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG, rl.filter.and.tag);
if (rl.filter.and.tag != null) {
for (Tag r : rl.filter.and.tag) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG_KEY, r.key);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG_VALUE, r.value);
}
}
}
}
if (rl.sourceSelectionCriteria != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA, rl.sourceSelectionCriteria);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_REPLICA_MODIFICATIONS, rl.sourceSelectionCriteria.replicaModifications);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_REPLICA_MODIFICATIONS_STATUS, rl.sourceSelectionCriteria.replicaModifications.status);
if (rl.sourceSelectionCriteria.sseKmsEncryptedObjects != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_SSE_KMS_ENCRYPTED_OBJECTS, rl.sourceSelectionCriteria.sseKmsEncryptedObjects);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_SSE_KMS_ENCRYPTED_OBJECTS_STATUS, rl.sourceSelectionCriteria.sseKmsEncryptedObjects.status);
}
}
if (rl.deleteMarkerReplication != null && rl.deleteMarkerReplication.Status != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DELETE_MARKER_REPLICATION, rl.deleteMarkerReplication);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DELETE_MARKER_REPLICATION_STATUS, rl.deleteMarkerReplication.Status);
if (rl.deleteMarkerReplication.Status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.deleteMarkerReplication.Status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
if (rl.destination == null) {
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
} else {
if (rl.destination.bucket != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_BUCKET, rl.destination.bucket);
String[] arnPath = rl.destination.bucket.split(GWConstants.COLON, -1);
if (arnPath.length != 6) {
logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
if (Strings.isNullOrEmpty(arnPath[5])) {
logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
if (Strings.isNullOrEmpty(arnPath[3])) {
if (isExistBucket(arnPath[5])) {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
Bucket destBucket = getSomeBucket(arnPath[5]);
if (destBucket.getVersioning() != null) {
if (!GWConstants.STATUS_ENABLED.equalsIgnoreCase(destBucket.getVersioning())) {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
} else {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
}
} else {
logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
if (rl.destination.accessControlTranslation != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ACCESS_CONTROL_TRANSLATION, rl.destination.accessControlTranslation);
if (rl.destination.accessControlTranslation.owner != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ACCESS_CONTROL_TRANSLATION_OWNER, rl.destination.accessControlTranslation.owner);
}
if (rl.destination.encryptionConfiguration != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ENCRYPTION_CONFIGURATION, rl.destination.encryptionConfiguration);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ENCRYPTION_CONFIGURATION_REPLICAT_KMS_KEY_ID, rl.destination.encryptionConfiguration.replicaKmsKeyID);
}
if (rl.destination.metrics != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS, rl.destination.metrics);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_EVENT_THRESHOLD, rl.destination.metrics.eventThreshold);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_EVENT_THRESHOLD_MINUTES, rl.destination.metrics.eventThreshold.minutes);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_STATUS, rl.destination.metrics.status);
}
if (rl.destination.replicationTime != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME, rl.destination.replicationTime);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME_STATUS, rl.destination.replicationTime.status);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME_TIME, rl.destination.replicationTime.time);
}
}
if (rl.destination.storageClass != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_STORAGE_CLASS, rl.destination.storageClass);
logger.error(GWErrorCode.NOT_IMPLEMENTED.getMessage());
throw new GWException(GWErrorCode.NOT_IMPLEMENTED, s3Parameter);
}
}
if (rl.existingObjectReplication != null && rl.existingObjectReplication.status != null) {
if (rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
if (rl.existingObjectReplication != null && rl.existingObjectReplication.status != null) {
if (rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
if (rl.sourceSelectionCriteria != null) {
logger.error(GWErrorCode.NOT_IMPLEMENTED.getMessage());
throw new GWException(GWErrorCode.NOT_IMPLEMENTED, s3Parameter);
}
if (rl.status != null && rl.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
if (rc.rules.size() > id.size()) {
logger.error(GWErrorCode.INVALID_ARGUMENT.getMessage());
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
}
}
use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class PutBucketWebsite method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_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);
}
checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE_ACP);
DataPutBucketWebsite dataPutBucketWebsite = new DataPutBucketWebsite(s3Parameter);
dataPutBucketWebsite.extract();
String webXml = dataPutBucketWebsite.getWebsiteXml();
updateBucketWeb(bucket, webXml);
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class PutObject method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_OBJECT_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);
}
checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE);
DataPutObject dataPutObject = new DataPutObject(s3Parameter);
dataPutObject.extract();
S3Metadata s3Metadata = new S3Metadata();
String cacheControl = dataPutObject.getCacheControl();
String contentDisposition = dataPutObject.getContentDisposition();
String contentEncoding = dataPutObject.getContentEncoding();
String contentLanguage = dataPutObject.getContentLanguage();
String contentType = dataPutObject.getContentType();
String contentLengthString = dataPutObject.getContentLength();
String decodedContentLengthString = dataPutObject.getDecodedContentLength();
String contentMD5String = dataPutObject.getContentMD5();
String customerAlgorithm = dataPutObject.getServerSideEncryptionCustomerAlgorithm();
String customerKey = dataPutObject.getServerSideEncryptionCustomerKey();
String customerKeyMD5 = dataPutObject.getServerSideEncryptionCustomerKeyMD5();
String serversideEncryption = dataPutObject.getServerSideEncryption();
s3Metadata.setOwnerId(String.valueOf(s3Parameter.getUser().getUserId()));
s3Metadata.setOwnerName(s3Parameter.getUser().getUserName());
s3Metadata.setUserMetadataMap(dataPutObject.getUserMetadata());
if (!Strings.isNullOrEmpty(serversideEncryption)) {
if (!GWConstants.AES256.equalsIgnoreCase(serversideEncryption)) {
logger.error(GWErrorCode.NOT_IMPLEMENTED.getMessage() + GWConstants.SERVER_SIDE_OPTION);
throw new GWException(GWErrorCode.NOT_IMPLEMENTED, s3Parameter);
} else {
s3Metadata.setServersideEncryption(serversideEncryption);
}
}
if (!Strings.isNullOrEmpty(cacheControl)) {
s3Metadata.setCacheControl(cacheControl);
}
if (!Strings.isNullOrEmpty(contentDisposition)) {
s3Metadata.setContentDisposition(contentDisposition);
}
if (!Strings.isNullOrEmpty(contentEncoding)) {
s3Metadata.setContentEncoding(contentEncoding);
}
if (!Strings.isNullOrEmpty(contentLanguage)) {
s3Metadata.setContentLanguage(contentLanguage);
}
if (!Strings.isNullOrEmpty(contentType)) {
s3Metadata.setContentType(contentType);
}
if (!Strings.isNullOrEmpty(customerAlgorithm)) {
s3Metadata.setCustomerAlgorithm(customerAlgorithm);
}
if (!Strings.isNullOrEmpty(customerKey)) {
s3Metadata.setCustomerKey(customerKey);
}
if (!Strings.isNullOrEmpty(customerKeyMD5)) {
s3Metadata.setCustomerKeyMD5(customerKeyMD5);
}
if (!Strings.isNullOrEmpty(decodedContentLengthString)) {
contentLengthString = decodedContentLengthString;
}
HashCode contentMD5 = null;
if (!Strings.isNullOrEmpty(contentMD5String)) {
s3Metadata.setContentMD5(contentMD5String);
try {
contentMD5 = HashCode.fromBytes(BaseEncoding.base64().decode(contentMD5String));
} catch (IllegalArgumentException iae) {
PrintStack.logging(logger, iae);
throw new GWException(GWErrorCode.INVALID_DIGEST, iae, s3Parameter);
}
if (contentMD5.bits() != MD5.bits()) {
logger.error(GWErrorCode.INVALID_DIGEST.getMessage() + GWConstants.LOG_PUT_OBJECT_HASHCODE_ILLEGAL);
throw new GWException(GWErrorCode.INVALID_DIGEST, s3Parameter);
}
}
long contentLength;
if (Strings.isNullOrEmpty(contentLengthString)) {
logger.error(GWErrorCode.MISSING_CONTENT_LENGTH.getMessage());
throw new GWException(GWErrorCode.MISSING_CONTENT_LENGTH, s3Parameter);
} else {
try {
contentLength = Long.parseLong(contentLengthString);
s3Metadata.setContentLength(contentLength);
} catch (NumberFormatException nfe) {
PrintStack.logging(logger, nfe);
throw new GWException(GWErrorCode.INVALID_ARGUMENT, nfe, s3Parameter);
}
}
accessControlPolicy = new AccessControlPolicy();
accessControlPolicy.aclList = new AccessControlList();
accessControlPolicy.aclList.grants = new ArrayList<Grant>();
accessControlPolicy.owner = new Owner();
accessControlPolicy.owner.id = String.valueOf(s3Parameter.getUser().getUserId());
accessControlPolicy.owner.displayName = s3Parameter.getUser().getUserName();
String aclXml = GWUtils.makeAclXml(accessControlPolicy, null, dataPutObject.hasAclKeyword(), null, dataPutObject.getAcl(), getBucketInfo(), String.valueOf(s3Parameter.getUser().getUserId()), s3Parameter.getUser().getUserName(), dataPutObject.getGrantRead(), dataPutObject.getGrantWrite(), dataPutObject.getGrantFullControl(), dataPutObject.getGrantReadAcp(), dataPutObject.getGrantWriteAcp(), s3Parameter);
logger.debug(GWConstants.LOG_ACL, aclXml);
String bucketEncryption = getBucketInfo().getEncryption();
// check encryption
S3ServerSideEncryption encryption = new S3ServerSideEncryption(bucketEncryption, serversideEncryption, customerAlgorithm, customerKey, customerKeyMD5, s3Parameter);
encryption.build();
// Tagging information
String taggingCount = GWConstants.TAGGING_INIT;
String taggingxml = "";
Tagging tagging = new Tagging();
tagging.tagset = new TagSet();
if (!Strings.isNullOrEmpty(dataPutObject.getTagging())) {
String strtaggingInfo = dataPutObject.getTagging();
String[] strtagset = strtaggingInfo.split(GWConstants.AMPERSAND);
int starttag = 0;
for (String strtag : strtagset) {
if (starttag == 0)
tagging.tagset.tags = new ArrayList<Tag>();
starttag += 1;
Tag tag = new Tag();
String[] keyvalue = strtag.split(GWConstants.EQUAL);
if (keyvalue.length == GWConstants.TAG_KEY_SIZE) {
tag.key = keyvalue[GWConstants.TAG_KEY_INDEX];
tag.value = keyvalue[GWConstants.TAG_VALUE_INDEX];
} else {
tag.key = keyvalue[GWConstants.TAG_KEY_INDEX];
tag.value = "";
}
tagging.tagset.tags.add(tag);
}
try {
taggingxml = new XmlMapper().writeValueAsString(tagging);
} catch (JsonProcessingException e) {
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
if (tagging != null) {
if (tagging.tagset != null && tagging.tagset.tags != null) {
for (Tag t : tagging.tagset.tags) {
// key, value 길이 체크
if (t.key.length() > GWConstants.TAG_KEY_MAX) {
logger.error(GWConstants.LOG_PUT_OBJECT_TAGGING_KEY_LENGTH, t.key.length());
throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
}
if (t.value.length() > GWConstants.TAG_VALUE_MAX) {
logger.error(GWConstants.LOG_PUT_OBJECT_TAGGING_VALUE_LENGTH, t.value.length());
throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
}
}
}
if (tagging.tagset != null && tagging.tagset.tags != null) {
if (tagging.tagset.tags.size() > GWConstants.TAG_MAX_SIZE) {
logger.error(GWConstants.LOG_PUT_OBJECT_TAGGING_SIZE, tagging.tagset.tags.size());
throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
}
taggingCount = String.valueOf(tagging.tagset.tags.size());
}
}
}
if (!Strings.isNullOrEmpty(dataPutObject.getObjectLockMode())) {
try {
logger.debug(GWConstants.LOG_OBJECT_LOCK, getBucketInfo().getObjectLock());
ObjectLockConfiguration oc = new XmlMapper().readValue(getBucketInfo().getObjectLock(), ObjectLockConfiguration.class);
if (!oc.objectLockEnabled.equals(GWConstants.STATUS_ENABLED)) {
logger.error(GWConstants.LOG_PUT_OBJECT_LOCK_STATUS, oc.objectLockEnabled);
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
if (!dataPutObject.getObjectLockMode().equals(GWConstants.GOVERNANCE) && !dataPutObject.getObjectLockMode().equals(GWConstants.COMPLIANCE)) {
logger.error(GWConstants.LOG_PUT_OBJECT_LOCK_MODE, dataPutObject.getObjectLockMode());
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
s3Metadata.setLockMode(dataPutObject.getObjectLockMode());
}
if (!Strings.isNullOrEmpty(dataPutObject.getObjectLockRetainUntilDate())) {
if (!dataPutObject.getObjectLockMode().equals(GWConstants.GOVERNANCE) && !dataPutObject.getObjectLockMode().equals(GWConstants.COMPLIANCE)) {
logger.error(GWConstants.LOG_PUT_OBJECT_LOCK_MODE, dataPutObject.getObjectLockMode());
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
try {
ObjectLockConfiguration oc = new XmlMapper().readValue(getBucketInfo().getObjectLock(), ObjectLockConfiguration.class);
if (!oc.objectLockEnabled.equals(GWConstants.STATUS_ENABLED)) {
logger.error(GWConstants.LOG_PUT_OBJECT_LOCK_STATUS, oc.objectLockEnabled);
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Metadata.setLockExpires(dataPutObject.getObjectLockRetainUntilDate());
}
if (!Strings.isNullOrEmpty(dataPutObject.getObjectLockLegalHold())) {
try {
ObjectLockConfiguration oc = new XmlMapper().readValue(getBucketInfo().getObjectLock(), ObjectLockConfiguration.class);
if (!oc.objectLockEnabled.equals(GWConstants.STATUS_ENABLED)) {
logger.error(GWConstants.LOG_PUT_OBJECT_LOCK_STATUS, oc.objectLockEnabled);
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Metadata.setLegalHold(dataPutObject.getObjectLockLegalHold());
}
String versioningStatus = getBucketVersioning(bucket);
String versionId = null;
Metadata objMeta = null;
try {
// check exist object
objMeta = open(bucket, object);
if (GWConstants.VERSIONING_ENABLED.equalsIgnoreCase(versioningStatus)) {
versionId = String.valueOf(System.nanoTime());
} else {
versionId = GWConstants.VERSIONING_DISABLE_TAIL;
}
} catch (GWException e) {
logger.info(e.getMessage());
if (GWConfig.getReplicaCount() > 1) {
objMeta = create(bucket, object);
} else {
objMeta = createLocal(bucket, object);
}
if (GWConstants.VERSIONING_ENABLED.equalsIgnoreCase(versioningStatus)) {
versionId = String.valueOf(System.nanoTime());
} else {
versionId = GWConstants.VERSIONING_DISABLE_TAIL;
}
}
S3ObjectOperation objectOperation = new S3ObjectOperation(objMeta, s3Metadata, s3Parameter, versionId, encryption);
S3Object s3Object = objectOperation.putObject();
s3Metadata.setETag(s3Object.getEtag());
s3Metadata.setSize(s3Object.getFileSize());
s3Metadata.setContentLength(s3Object.getFileSize());
s3Metadata.setTier(GWConstants.AWS_TIER_STANTARD);
s3Metadata.setLastModified(s3Object.getLastModified());
s3Metadata.setDeleteMarker(s3Object.getDeleteMarker());
s3Metadata.setVersionId(s3Object.getVersionId());
s3Metadata.setTaggingCount(taggingCount);
if (encryption.isEnableSSEServer()) {
s3Metadata.setServersideEncryption(GWConstants.AES256);
}
s3Parameter.setFileSize(s3Object.getFileSize());
ObjectMapper jsonMapper = new ObjectMapper();
String jsonmeta = "";
try {
jsonmeta = jsonMapper.writeValueAsString(s3Metadata);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
logger.debug(GWConstants.LOG_PUT_OBJECT_PRIMARY_DISK_ID, objMeta.getPrimaryDisk().getId());
try {
int result;
objMeta.set(s3Object.getEtag(), taggingxml, jsonmeta, aclXml, s3Object.getFileSize());
objMeta.setVersionId(versionId, GWConstants.OBJECT_TYPE_FILE, true);
result = insertObject(bucket, object, objMeta);
logger.debug(GWConstants.LOG_PUT_OBJECT_INFO, bucket, object, s3Object.getFileSize(), s3Object.getEtag(), aclXml, versionId);
} catch (GWException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Parameter.getResponse().addHeader(HttpHeaders.ETAG, GWUtils.maybeQuoteETag(s3Object.getEtag()));
if (GWConstants.VERSIONING_ENABLED.equalsIgnoreCase(versioningStatus)) {
s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, s3Object.getVersionId());
logger.debug(GWConstants.LOG_PUT_OBJECT_VERSIONID, s3Object.getVersionId());
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class PutObjectLockConfiguration method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_BUCKET_OBJECT_LOCK_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_WRITE_ACP);
DataPutBucketObjectLock dataPutBucketObjectLock = new DataPutBucketObjectLock(s3Parameter);
dataPutBucketObjectLock.extract();
String ObjectLockXml = dataPutBucketObjectLock.getObjectLockXml();
if (Strings.isNullOrEmpty(getBucketInfo().getObjectLock())) {
throw new GWException(GWErrorCode.INVALID_BUCKET_STATE, s3Parameter);
}
if (Strings.isNullOrEmpty(ObjectLockXml)) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
logger.info(GWConstants.LOG_PUT_BUCKET_OBJECT_LOCK, getBucketInfo().getObjectLock());
try {
ObjectLockConfiguration oc = new XmlMapper().readValue(getBucketInfo().getObjectLock(), ObjectLockConfiguration.class);
if (!oc.objectLockEnabled.equals(GWConstants.STATUS_ENABLED)) {
throw new GWException(GWErrorCode.INVALID_BUCKET_STATE, s3Parameter);
}
oc = new XmlMapper().readValue(ObjectLockXml, ObjectLockConfiguration.class);
if (!oc.objectLockEnabled.equals(GWConstants.STATUS_ENABLED)) {
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
if (!Strings.isNullOrEmpty(oc.rules.defaultRetention.days) && !Strings.isNullOrEmpty(oc.rules.defaultRetention.years)) {
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
if (!Strings.isNullOrEmpty(oc.rules.defaultRetention.days)) {
try {
if (Integer.parseInt(oc.rules.defaultRetention.days) <= 0) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
} catch (NumberFormatException e) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
}
if (!Strings.isNullOrEmpty(oc.rules.defaultRetention.years)) {
try {
if (Integer.parseInt(oc.rules.defaultRetention.years) <= 0) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
} catch (NumberFormatException e) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
}
if (!Strings.isNullOrEmpty(oc.rules.defaultRetention.mode)) {
if (!oc.rules.defaultRetention.mode.equals(GWConstants.GOVERNANCE) && !oc.rules.defaultRetention.mode.equals(GWConstants.COMPLIANCE)) {
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
updateBucketObjectLock(bucket, ObjectLockXml);
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class S3Request method open.
protected Metadata open(String bucket, String object) throws GWException {
Metadata meta = null;
try {
setObjManager();
meta = objManager.open(bucket, object);
} catch (ResourceNotFoundException e) {
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 meta;
}
Aggregations