use of com.pspace.ifs.ksan.gw.identity.S3Bucket in project ksan by infinistor.
the class GetBucketPolicyStatus method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_BUCKET_POLICY_STATUS_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);
}
String policy = getBucketInfo().getPolicy();
logger.debug(GWConstants.LOG_GET_BUCKET_POLICY, policy);
if (Strings.isNullOrEmpty(policy)) {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
try (Writer writer = s3Parameter.getResponse().getWriter()) {
XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement(GWConstants.POLICY_STATUS);
if (GWUtils.isPublicPolicyBucket(policy, s3Parameter)) {
writeSimpleElement(xmlStreamWriter, GWConstants.POLICY_IS_PUBLIC, GWConstants.STRING_TRUE);
} else {
writeSimpleElement(xmlStreamWriter, GWConstants.POLICY_IS_PUBLIC, GWConstants.STRING_FALSE);
}
xmlStreamWriter.writeEndElement();
xmlStreamWriter.flush();
} catch (IOException | XMLStreamException 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 GetBucketReplication method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_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_READ_ACP);
String replication = getBucketInfo().getReplication();
logger.debug(GWConstants.LOG_GET_BUCKET_REPLICATION, replication);
if (Strings.isNullOrEmpty(replication)) {
throw new GWException(GWErrorCode.NO_SUCH_REPLICATION_CONFIGURATION, s3Parameter);
}
try {
if (!Strings.isNullOrEmpty(replication)) {
s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
s3Parameter.getResponse().getOutputStream().write(replication.getBytes());
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Aggregations