use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.
the class XacmlClientTest method testIllegalStateException.
@Test(expected = IllegalStateException.class)
public void testIllegalStateException() throws Exception {
LOGGER.debug("\n\n\n##### testExecption");
File policyDir = folder.newFolder("tempDir");
// Perform Test
XacmlClient pdp = new XacmlClient(policyDir.getCanonicalPath(), null, mock(SecurityLogger.class));
File srcFile = new File(projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
FileUtils.copyFileToDirectory(srcFile, policyDir);
RequestType xacmlRequestType = new RequestType();
xacmlRequestType.setCombinedDecision(false);
xacmlRequestType.setReturnPolicyIdList(false);
AttributesType actionAttributes = new AttributesType();
actionAttributes.setCategory(ACTION_CATEGORY);
AttributeType actionAttribute = new AttributeType();
actionAttribute.setAttributeId(ACTION_ID);
actionAttribute.setIncludeInResult(false);
AttributeValueType actionValue = new AttributeValueType();
actionValue.setDataType(STRING_DATA_TYPE);
actionValue.getContent().add(QUERY_ACTION);
actionAttribute.getAttributeValue().add(actionValue);
actionAttributes.getAttribute().add(actionAttribute);
AttributesType subjectAttributes = new AttributesType();
subjectAttributes.setCategory(SUBJECT_CATEGORY);
AttributeType subjectAttribute = new AttributeType();
subjectAttribute.setAttributeId(SUBJECT_ID);
subjectAttribute.setIncludeInResult(false);
AttributeValueType subjectValue = new AttributeValueType();
subjectValue.setDataType(STRING_DATA_TYPE);
subjectValue.getContent().add(TEST_USER_1);
subjectAttribute.getAttributeValue().add(subjectValue);
subjectAttributes.getAttribute().add(subjectAttribute);
AttributeType roleAttribute = new AttributeType();
roleAttribute.setAttributeId(ROLE_CLAIM);
roleAttribute.setIncludeInResult(false);
AttributeValueType roleValue = new AttributeValueType();
roleValue.setDataType(STRING_DATA_TYPE);
roleValue.getContent().add(ROLE);
roleAttribute.getAttributeValue().add(roleValue);
subjectAttributes.getAttribute().add(roleAttribute);
AttributesType categoryAttributes = new AttributesType();
categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
AttributeType citizenshipAttribute = new AttributeType();
citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
citizenshipAttribute.setIncludeInResult(false);
AttributeValueType citizenshipValue = new AttributeValueType();
citizenshipValue.setDataType(STRING_DATA_TYPE);
citizenshipValue.getContent().add(US_COUNTRY);
citizenshipAttribute.getAttributeValue().add(citizenshipValue);
categoryAttributes.getAttribute().add(citizenshipAttribute);
xacmlRequestType.getAttributes().add(actionAttributes);
xacmlRequestType.getAttributes().add(subjectAttributes);
xacmlRequestType.getAttributes().add(categoryAttributes);
// Perform Test
pdp.evaluate(xacmlRequestType);
}
use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.
the class XacmlClientTest method testEvaluateroleuseractionquerycitizenshipCA.
@Test
public void testEvaluateroleuseractionquerycitizenshipCA() throws Exception {
LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_CA");
final String country = "CA";
testSetup();
RequestType xacmlRequestType = new RequestType();
xacmlRequestType.setCombinedDecision(false);
xacmlRequestType.setReturnPolicyIdList(false);
AttributesType actionAttributes = new AttributesType();
actionAttributes.setCategory(ACTION_CATEGORY);
AttributeType actionAttribute = new AttributeType();
actionAttribute.setAttributeId(ACTION_ID);
actionAttribute.setIncludeInResult(false);
AttributeValueType actionValue = new AttributeValueType();
actionValue.setDataType(STRING_DATA_TYPE);
actionValue.getContent().add(QUERY_ACTION);
actionAttribute.getAttributeValue().add(actionValue);
actionAttributes.getAttribute().add(actionAttribute);
AttributesType subjectAttributes = new AttributesType();
subjectAttributes.setCategory(SUBJECT_CATEGORY);
AttributeType subjectAttribute = new AttributeType();
subjectAttribute.setAttributeId(SUBJECT_ID);
subjectAttribute.setIncludeInResult(false);
AttributeValueType subjectValue = new AttributeValueType();
subjectValue.setDataType(STRING_DATA_TYPE);
subjectValue.getContent().add(TEST_USER_2);
subjectAttribute.getAttributeValue().add(subjectValue);
subjectAttributes.getAttribute().add(subjectAttribute);
AttributeType roleAttribute = new AttributeType();
roleAttribute.setAttributeId(ROLE_CLAIM);
roleAttribute.setIncludeInResult(false);
AttributeValueType roleValue = new AttributeValueType();
roleValue.setDataType(STRING_DATA_TYPE);
roleValue.getContent().add(ROLE);
roleAttribute.getAttributeValue().add(roleValue);
subjectAttributes.getAttribute().add(roleAttribute);
AttributesType categoryAttributes = new AttributesType();
categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
AttributeType citizenshipAttribute = new AttributeType();
citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
citizenshipAttribute.setIncludeInResult(false);
AttributeValueType citizenshipValue = new AttributeValueType();
citizenshipValue.setDataType(STRING_DATA_TYPE);
citizenshipValue.getContent().add(country);
citizenshipAttribute.getAttributeValue().add(citizenshipValue);
categoryAttributes.getAttribute().add(citizenshipAttribute);
xacmlRequestType.getAttributes().add(actionAttributes);
xacmlRequestType.getAttributes().add(subjectAttributes);
xacmlRequestType.getAttributes().add(categoryAttributes);
XacmlClient pdp = new XacmlClient(tempDir.getCanonicalPath(), new XmlParser(), mock(SecurityLogger.class));
// Perform Test
ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
// Verify
JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
Marshaller marshaller = jaxbContext.createMarshaller();
ObjectFactory objectFactory = new ObjectFactory();
Writer writer = new StringWriter();
marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.DENY);
}
use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.
the class XacmlClientTest method testEvaluateroleuseractionquerycitizenshipUS.
@Test
public void testEvaluateroleuseractionquerycitizenshipUS() throws Exception {
LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_US");
// Setup
File destDir = folder.newFolder(TEMP_DIR_NAME);
LOGGER.debug("Making directory: {}", destDir.getPath());
if (destDir.mkdir()) {
File srcFile = new File(projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
FileUtils.copyFileToDirectory(srcFile, destDir);
RequestType xacmlRequestType = new RequestType();
xacmlRequestType.setCombinedDecision(false);
xacmlRequestType.setReturnPolicyIdList(false);
AttributesType actionAttributes = new AttributesType();
actionAttributes.setCategory(ACTION_CATEGORY);
AttributeType actionAttribute = new AttributeType();
actionAttribute.setAttributeId(ACTION_ID);
actionAttribute.setIncludeInResult(false);
AttributeValueType actionValue = new AttributeValueType();
actionValue.setDataType(STRING_DATA_TYPE);
actionValue.getContent().add(QUERY_ACTION);
actionAttribute.getAttributeValue().add(actionValue);
actionAttributes.getAttribute().add(actionAttribute);
AttributesType subjectAttributes = new AttributesType();
subjectAttributes.setCategory(SUBJECT_CATEGORY);
AttributeType subjectAttribute = new AttributeType();
subjectAttribute.setAttributeId(SUBJECT_ID);
subjectAttribute.setIncludeInResult(false);
AttributeValueType subjectValue = new AttributeValueType();
subjectValue.setDataType(STRING_DATA_TYPE);
subjectValue.getContent().add(TEST_USER_1);
subjectAttribute.getAttributeValue().add(subjectValue);
subjectAttributes.getAttribute().add(subjectAttribute);
AttributeType roleAttribute = new AttributeType();
roleAttribute.setAttributeId(ROLE_CLAIM);
roleAttribute.setIncludeInResult(false);
AttributeValueType roleValue = new AttributeValueType();
roleValue.setDataType(STRING_DATA_TYPE);
roleValue.getContent().add(ROLE);
roleAttribute.getAttributeValue().add(roleValue);
subjectAttributes.getAttribute().add(roleAttribute);
AttributesType categoryAttributes = new AttributesType();
categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
AttributeType citizenshipAttribute = new AttributeType();
citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
citizenshipAttribute.setIncludeInResult(false);
AttributeValueType citizenshipValue = new AttributeValueType();
citizenshipValue.setDataType(STRING_DATA_TYPE);
citizenshipValue.getContent().add(US_COUNTRY);
citizenshipAttribute.getAttributeValue().add(citizenshipValue);
categoryAttributes.getAttribute().add(citizenshipAttribute);
xacmlRequestType.getAttributes().add(actionAttributes);
xacmlRequestType.getAttributes().add(subjectAttributes);
xacmlRequestType.getAttributes().add(categoryAttributes);
XacmlClient pdp = new XacmlClient(destDir.getCanonicalPath(), new XmlParser(), mock(SecurityLogger.class));
// Perform Test
ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
// Verify
JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
Marshaller marshaller = jaxbContext.createMarshaller();
ObjectFactory objectFactory = new ObjectFactory();
Writer writer = new StringWriter();
marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);
// Cleanup
LOGGER.debug("Deleting directory: {}", destDir);
FileUtils.deleteDirectory(destDir);
} else {
LOGGER.debug("Could not create directory: {}", destDir);
}
}
use of com.helger.peppol.wsclient2.RequestType in project ddf by codice.
the class XacmlPdp method isPermitted.
public boolean isPermitted(String primaryPrincipal, AuthorizationInfo info, KeyValueCollectionPermission curPermission) {
boolean curResponse;
LOGGER.debug("Checking if {} has access for action {}", primaryPrincipal, curPermission.getAction());
if (CollectionUtils.isEmpty(info.getObjectPermissions()) && CollectionUtils.isEmpty(info.getStringPermissions()) && CollectionUtils.isEmpty(info.getRoles()) && !CollectionUtils.isEmpty(curPermission.getKeyValuePermissionList())) {
securityLogger.audit(String.format(AUDIT_MSG_FORMAT, "short-circuit denied", primaryPrincipal, curPermission.getAction()));
return false;
}
if ((!CollectionUtils.isEmpty(info.getObjectPermissions()) || !CollectionUtils.isEmpty(info.getStringPermissions()) || !CollectionUtils.isEmpty(info.getRoles())) && CollectionUtils.isEmpty(curPermission.getKeyValuePermissionList())) {
securityLogger.audit(String.format(AUDIT_MSG_FORMAT, "short-circuit permitted", primaryPrincipal, curPermission.getAction()));
return true;
}
LOGGER.debug("Received authZ info, creating XACML request.");
RequestType curRequest = createXACMLRequest(primaryPrincipal, info, curPermission);
LOGGER.debug("Created XACML request, calling PDP.");
curResponse = isPermitted(curRequest);
if (curResponse) {
securityLogger.audit(String.format(AUDIT_MSG_FORMAT, "permitted", primaryPrincipal, curPermission.getAction()));
} else {
securityLogger.audit(String.format(AUDIT_MSG_FORMAT, "denied", primaryPrincipal, curPermission.getAction()));
}
return curResponse;
}
use of com.helger.peppol.wsclient2.RequestType in project mod-oai-pmh by folio-org.
the class Request method isResumptionTokenParsableAndValid.
/**
* Restores original request encoded in resumptionToken.
* The resumptionToken is exclusive param, so the request cannot be restored if some other params are provided
* in the request along with the resumptionToken.
*
* @return true if the request was restored, false otherwise.
*/
public boolean isResumptionTokenParsableAndValid() {
try {
String resumptionToken = new String(Base64.getUrlDecoder().decode(oaiRequest.getResumptionToken()), StandardCharsets.UTF_8);
Map<String, String> params = URLEncodedUtils.parse(resumptionToken, UTF_8, PARAMETER_SEPARATOR).stream().collect(toMap(NameValuePair::getName, NameValuePair::getValue));
restoredOaiRequest = new RequestType();
restoredOaiRequest.setMetadataPrefix(params.get(METADATA_PREFIX_PARAM));
restoredOaiRequest.setFrom(params.get(FROM_PARAM));
restoredOaiRequest.setUntil(params.get(UNTIL_PARAM));
restoredOaiRequest.setSet(params.get(SET_PARAM));
this.offset = Integer.parseInt(params.get(OFFSET_PARAM));
final String value = params.get(TOTAL_RECORDS_PARAM);
this.totalRecords = value == null ? 0 : Integer.parseInt(value);
this.nextRecordId = params.get(NEXT_RECORD_ID_PARAM);
this.requestId = params.get(REQUEST_ID_PARAM);
if (Objects.nonNull(params.get(NEXT_INSTANCE_PK_VALUE))) {
this.nextInstancePkValue = Integer.parseInt(params.get(NEXT_INSTANCE_PK_VALUE));
}
} catch (Exception e) {
return false;
}
return true;
}
Aggregations