use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class ListParts method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_LIST_PARTS_START);
String bucket = s3Parameter.getBucketName();
if (!isExistBucket(bucket)) {
logger.error(GWConstants.LOG_BUCKET_IS_NOT_EXIST, bucket);
throw new GWException(GWErrorCode.NO_SUCH_BUCKET, s3Parameter);
}
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);
DataListParts dataListParts = new DataListParts(s3Parameter);
dataListParts.extract();
String maxParts = dataListParts.getMaxParts();
String partNumberMarker = dataListParts.getPartNumberMarker();
String uploadId = dataListParts.getUploadId();
int maxPartsValue = GWConstants.MAX_PART_VALUE;
if (!Strings.isNullOrEmpty(maxParts)) {
if (Integer.valueOf(maxParts) < 0) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
maxPartsValue = Integer.valueOf(maxParts);
}
ResultParts resultPart = null;
ObjMultipart objMultipart = null;
Multipart multipart = null;
try {
objMultipart = new ObjMultipart(bucket);
multipart = objMultipart.getMultipart(uploadId);
if (multipart == null) {
logger.error(GWConstants.LOG_UPLOAD_NOT_FOUND, uploadId);
throw new GWException(GWErrorCode.NO_SUCH_UPLOAD, s3Parameter);
}
// check acl use multipart acl
resultPart = objMultipart.getParts(uploadId, partNumberMarker, maxPartsValue);
} catch (UnknownHostException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
} catch (Exception e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
}
String meta = multipart.getMeta();
ObjectMapper jsonMapper = new ObjectMapper();
S3Metadata s3Metadata;
try {
s3Metadata = jsonMapper.readValue(meta, S3Metadata.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);
}
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
s3Parameter.getResponse().setCharacterEncoding(GWConstants.CHARSET_UTF_8);
try (Writer writer = s3Parameter.getResponse().getWriter()) {
s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement(GWConstants.LIST_PARTS_RESULT);
xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
writeSimpleElement(xmlStreamWriter, GWConstants.BUCKET, bucket);
writeSimpleElement(xmlStreamWriter, GWConstants.KEY, s3Parameter.getObjectName());
writeSimpleElement(xmlStreamWriter, GWConstants.XML_UPLOADID, uploadId);
writeInitiatorStanza(xmlStreamWriter);
writeOwnerInfini(xmlStreamWriter, s3Metadata.getOwnerId(), s3Metadata.getOwnerName());
writeSimpleElement(xmlStreamWriter, GWConstants.STORAGE_CLASS, GWConstants.AWS_TIER_STANTARD);
if (resultPart.isTruncated()) {
writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_TRUE);
writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_PART_NUMBER, String.valueOf(resultPart.getPartNumberMarker()));
} else {
writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_FALSE);
}
for (Iterator<Map.Entry<Integer, Part>> it = resultPart.getListPart().entrySet().iterator(); it.hasNext(); ) {
Map.Entry<Integer, Part> entry = it.next();
xmlStreamWriter.writeStartElement(GWConstants.PART);
writeSimpleElement(xmlStreamWriter, GWConstants.PARTNUMBER, String.valueOf(entry.getValue().getPartNumber()));
writeSimpleElement(xmlStreamWriter, GWConstants.LAST_MODIFIED, formatDate(entry.getValue().getLastModified()));
writeSimpleElement(xmlStreamWriter, GWConstants.ETAG, entry.getValue().getPartETag());
writeSimpleElement(xmlStreamWriter, GWConstants.XML_SIZE, String.valueOf(entry.getValue().getPartSize()));
xmlStreamWriter.writeEndElement();
logger.debug(GWConstants.LOG_LIST_PARTS_PART_NUMBER, entry.getValue().getPartNumber());
logger.debug(GWConstants.LOG_LIST_PARTS_LAST_MODIFIED, formatDate(entry.getValue().getLastModified()));
logger.debug(GWConstants.LOG_LIST_PARTS_ETAG, entry.getValue().getPartETag());
logger.debug(GWConstants.LOG_LIST_PARTS_SIZE, String.valueOf(entry.getValue().getPartSize()));
}
xmlStreamWriter.writeEndElement();
xmlStreamWriter.flush();
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
} catch (XMLStreamException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
}
use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class PutBucketCors method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_BUCKET_CORS_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);
DataPutBucketCors bucketCors = new DataPutBucketCors(s3Parameter);
bucketCors.extract();
String corsInfo = bucketCors.getCorsXml();
updateBucketCors(bucket, corsInfo);
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class PutBucketReplication method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_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);
if (!GWConstants.VERSIONING_ENABLED.equalsIgnoreCase(getBucketVersioning(bucket))) {
throw new GWException(GWErrorCode.INVALID_REPLICATION_REQUEST, s3Parameter);
}
DataPutBucketReplication dataPutBucketReplication = new DataPutBucketReplication(s3Parameter);
dataPutBucketReplication.extract();
String replicationXml = dataPutBucketReplication.getReplicationXml();
checkBucketReplication(replicationXml);
updateBucketReplication(bucket, replicationXml);
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class PutBucketTagging method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_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);
}
checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE_ACP);
DataPutBucketTagging dataPutBucketTagging = new DataPutBucketTagging(s3Parameter);
dataPutBucketTagging.extract();
String taggingXml = dataPutBucketTagging.getTaggingXml();
logger.debug(GWConstants.LOG_PUT_BUCKET_TAGGING, taggingXml);
try {
Tagging tagging = new XmlMapper().readValue(taggingXml, Tagging.class);
// 중복 지우기 item이 10개 미만이기 때문에 for loop가 빠름
if (tagging != null) {
if (tagging.tagset != null && tagging.tagset.tags != null) {
for (Tag t : tagging.tagset.tags) {
// key, value 길이 체크
if (t.key.length() > 128) {
throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
}
if (t.value.length() > 256) {
throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
}
}
}
if (tagging.tagset != null && tagging.tagset.tags != null) {
if (tagging.tagset.tags.size() > 10) {
throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
}
}
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
updateBucketTagging(bucket, taggingXml);
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class PutBucketVersioning method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_BUCKET_VERSIONING_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);
DataPutBucketVersioning dataPutBucketVersioning = new DataPutBucketVersioning(s3Parameter);
dataPutBucketVersioning.extract();
String versionXml = dataPutBucketVersioning.getVersioningXml();
if (!Strings.isNullOrEmpty(versionXml)) {
Versioning versioning = new Versioning();
try {
versioning = new XmlMapper().readValue(versionXml, Versioning.class);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
if (versioning.status != null && !versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED) && !versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_SUSPENDED)) {
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
if (!Strings.isNullOrEmpty(getBucketInfo().getObjectLock())) {
if (!versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED)) {
throw new GWException(GWErrorCode.INVALID_BUCKET_STATE, s3Parameter);
}
}
if (!Strings.isNullOrEmpty(versioning.status)) {
putBucketVersioning(bucket, versioning.status);
}
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Aggregations