use of com.pspace.ifs.ksan.gw.format.AccessControlPolicyJson in project ksan by infinistor.
the class GWUtils method makeOriginalXml.
public static String makeOriginalXml(String xml, S3Parameter s3Parameter) throws GWException {
logger.debug(GWConstants.LOG_UTILS_SOURCE_ACL, xml);
if (Strings.isNullOrEmpty(xml)) {
return "";
}
ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
AccessControlPolicyJson actualObj;
try {
actualObj = objectMapper.readValue(xml, AccessControlPolicyJson.class);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
AccessControlPolicy accessControlPolicy = new AccessControlPolicy();
accessControlPolicy.owner = new AccessControlPolicy.Owner();
if (actualObj.ow != null) {
if (!Strings.isNullOrEmpty(actualObj.ow.id)) {
accessControlPolicy.owner.id = actualObj.ow.id;
}
if (!Strings.isNullOrEmpty(actualObj.ow.dN)) {
accessControlPolicy.owner.displayName = actualObj.ow.dN;
}
}
if (actualObj.acs != null) {
accessControlPolicy.aclList = new AccessControlPolicy.AccessControlList();
if (actualObj.acs.gt != null) {
accessControlPolicy.aclList.grants = new ArrayList<AccessControlPolicy.AccessControlList.Grant>();
for (AccessControlPolicyJson.ACS.Gt gt : actualObj.acs.gt) {
AccessControlPolicy.AccessControlList.Grant grant = new AccessControlPolicy.AccessControlList.Grant();
if (!Strings.isNullOrEmpty(gt.perm)) {
if (gt.perm.equals(GWConstants.GRANT_AB_FC)) {
grant.permission = GWConstants.GRANT_FULL_CONTROL;
} else if (gt.perm.equals(GWConstants.GRANT_AB_W)) {
grant.permission = GWConstants.GRANT_WRITE;
} else if (gt.perm.equals(GWConstants.GRANT_AB_R)) {
grant.permission = GWConstants.GRANT_READ;
} else if (gt.perm.equals(GWConstants.GRANT_AB_RA)) {
grant.permission = GWConstants.GRANT_READ_ACP;
} else if (gt.perm.equals(GWConstants.GRANT_AB_WA)) {
grant.permission = GWConstants.GRANT_WRITE_ACP;
}
}
if (gt.gte != null) {
AccessControlPolicy.AccessControlList.Grant.Grantee grantee = new AccessControlPolicy.AccessControlList.Grant.Grantee();
if (!Strings.isNullOrEmpty(gt.gte.id)) {
grantee.id = gt.gte.id;
}
if (!Strings.isNullOrEmpty(gt.gte.ddN)) {
grantee.displayName = gt.gte.ddN;
}
if (!Strings.isNullOrEmpty(gt.gte.eA)) {
grantee.emailAddress = gt.gte.eA;
}
if (!Strings.isNullOrEmpty(gt.gte.type)) {
if (gt.gte.type.equals(GWConstants.GRANT_AB_CU)) {
grantee.type = GWConstants.CANONICAL_USER;
} else if (gt.gte.type.equals(GWConstants.GRANT_AB_G)) {
grantee.type = GWConstants.GROUP;
}
}
if (!Strings.isNullOrEmpty(gt.gte.uri)) {
if (gt.gte.uri.equals(GWConstants.GRANT_AB_PU)) {
grantee.uri = GWConstants.AWS_GRANT_URI_ALL_USERS;
} else if (gt.gte.uri.equals(GWConstants.GRANT_AB_AU)) {
grantee.uri = GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS;
}
}
grant.grantee = grantee;
}
accessControlPolicy.aclList.grants.add(grant);
}
}
}
String aclXml = "";
XmlMapper xmlMapper = new XmlMapper();
try {
xmlMapper.setSerializationInclusion(Include.NON_EMPTY);
aclXml = xmlMapper.writeValueAsString(accessControlPolicy).replaceAll(GWConstants.WSTXNS, GWConstants.XSI);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
aclXml = aclXml.replace(GWConstants.ACCESS_CONTROL_POLICY, GWConstants.ACCESS_CONTROL_POLICY_XMLNS);
if (!aclXml.contains(GWConstants.XML_VERSION)) {
aclXml = GWConstants.XML_VERSION_FULL_STANDALONE + aclXml;
}
return aclXml;
}
Aggregations