use of xeu.bridge_connector.v1.ResponseType in project ddf by codice.
the class XacmlClientTest method testWrapperpoliciesdirectorypolicyadded.
@Test
public void testWrapperpoliciesdirectorypolicyadded() throws Exception {
LOGGER.debug("\n\n\n##### testXACMLWrapper_policies_directory_policy_added");
File policyDir = folder.newFolder("tempDir");
XacmlClient.defaultPollingIntervalInSeconds = 1;
// Perform Test
XacmlClient pdp = new XacmlClient(policyDir.getCanonicalPath(), new XmlParser());
File srcFile = new File(projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
FileUtils.copyFileToDirectory(srcFile, policyDir);
Thread.sleep(2000);
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
ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
// Verify - The policy was loaded to allow a permit decision
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);
FileUtils.deleteDirectory(policyDir);
}
use of xeu.bridge_connector.v1.ResponseType in project ddf by codice.
the class XacmlClient method unmarshal.
/**
* Unmarshalls the XACML response.
*
* @param xacmlResponse The XACML response with all namespaces and namespace prefixes added.
* @return The XACML response.
* @throws PdpException
*/
@SuppressWarnings("unchecked")
private ResponseType unmarshal(DOMResult xacmlResponse) throws PdpException {
List<String> ctxPath = ImmutableList.of(ResponseType.class.getPackage().getName());
if (null == parser) {
throw new IllegalStateException("XMLParser must be configured.");
}
ParserConfigurator configurator = parser.configureParser(ctxPath, XacmlClient.class.getClassLoader());
try {
JAXBElement<ResponseType> xacmlResponseTypeElement = parser.unmarshal(configurator, JAXBElement.class, xacmlResponse.getNode());
return xacmlResponseTypeElement.getValue();
} catch (ParserException e) {
String message = "Unable to unmarshal XACML response.";
LOGGER.info(message);
throw new PdpException(message, e);
}
}
use of xeu.bridge_connector.v1.ResponseType in project UVMS-Docker by UnionVMS.
the class FluxMessageReceiverBeanIT method postRequestTypeRequestSuccessTest.
/**
* Post request type request success test.
*
* @throws Exception the exception
*/
@Test
@Ignore
public void postRequestTypeRequestSuccessTest() throws Exception {
Asset testAsset = AssetTestHelper.createTestAsset();
MobileTerminalType mobileTerminalType = MobileTerminalTestHelper.createMobileTerminalType();
MobileTerminalTestHelper.assignMobileTerminal(testAsset, mobileTerminalType);
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
BridgeConnectorPortType bridgeConnectorPortType = createBridgeConnector();
RequestType requestType = new RequestType();
FLUXVesselPositionMessage fLUXVesselPositionMessage = new FLUXVesselPositionMessage();
VesselTransportMeansType vesselTransportMeansType = new VesselTransportMeansType();
IDType cfrId = new IDType();
cfrId.setSchemeID("CFR");
cfrId.setValue(testAsset.getCfr());
vesselTransportMeansType.getIDS().add(cfrId);
IDType ircsId = new IDType();
ircsId.setSchemeID("IRCS");
ircsId.setValue(testAsset.getIrcs());
vesselTransportMeansType.getIDS().add(ircsId);
// IDType extMarkingId = new IDType();
// extMarkingId.setSchemeID("EXT_MARKING");
// extMarkingId.setValue(testAsset.getExternalMarking());
// vesselTransportMeansType.getIDS().add(extMarkingId);
VesselCountryType vesselCountry = new VesselCountryType();
IDType countryId = new IDType();
countryId.setValue("SWE");
vesselCountry.setID(countryId);
vesselTransportMeansType.setRegistrationVesselCountry(vesselCountry);
VesselPositionEventType vesselPositionEventType = new VesselPositionEventType();
MeasureType measureType = new MeasureType();
measureType.setValue(new BigDecimal(282));
vesselPositionEventType.setCourseValueMeasure(measureType);
DateTimeType posDateTime = new DateTimeType();
posDateTime.setDateTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
vesselPositionEventType.setObtainedOccurrenceDateTime(posDateTime);
VesselGeographicalCoordinateType cordinates = new VesselGeographicalCoordinateType();
MeasureType longitude = new MeasureType();
longitude.setValue(new BigDecimal(21.5740000000));
cordinates.setLongitudeMeasure(longitude);
MeasureType latitude = new MeasureType();
latitude.setValue(new BigDecimal(59.6480000000));
cordinates.setLatitudeMeasure(latitude);
vesselPositionEventType.setSpecifiedVesselGeographicalCoordinate(cordinates);
MeasureType speedValue = new MeasureType();
speedValue.setValue(new BigDecimal(7.5));
vesselPositionEventType.setSpeedValueMeasure(speedValue);
CodeType typeCodeValue = new CodeType();
typeCodeValue.setValue("POS");
vesselPositionEventType.setTypeCode(typeCodeValue);
vesselTransportMeansType.getSpecifiedVesselPositionEvents().add(vesselPositionEventType);
fLUXVesselPositionMessage.setVesselTransportMeans(vesselTransportMeansType);
FLUXReportDocumentType fluxReportDocumentType = new FLUXReportDocumentType();
DateTimeType dateTimeType = new DateTimeType();
dateTimeType.setDateTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
fluxReportDocumentType.setCreationDateTime(dateTimeType);
FLUXPartyType fLUXPartyType = new FLUXPartyType();
fLUXPartyType.getIDS().add(countryId);
fluxReportDocumentType.setOwnerFLUXParty(fLUXPartyType);
TextType textType = new TextType();
fluxReportDocumentType.setPurpose(textType);
CodeType purposeCode = new CodeType();
purposeCode.setValue("9");
fluxReportDocumentType.setPurposeCode(purposeCode);
IDType idType = new IDType();
fluxReportDocumentType.setReferencedID(idType);
CodeType typeCode = new CodeType();
fluxReportDocumentType.setTypeCode(typeCode);
fLUXVesselPositionMessage.setFLUXReportDocument(fluxReportDocumentType);
requestType.setAny(createAnyElement(fLUXVesselPositionMessage));
requestType.setAD("SWE");
requestType.setAR(true);
requestType.setDF("df");
requestType.setON("on");
requestType.setTO(1234);
requestType.setTODT(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
ResponseType responseType = bridgeConnectorPortType.post(requestType);
assertNotNull(responseType);
assertEquals("OK", responseType.getStatus());
Thread.sleep(7500);
List<String> connectIds = new ArrayList<>();
connectIds.add(testAsset.getEventHistory().getEventId());
final HttpResponse response = Request.Post(getBaseUrl() + "movement/rest/movement/latest").setHeader("Content-Type", "application/json").setHeader("Authorization", getValidJwtToken()).bodyByteArray(writeValueAsString(connectIds).getBytes()).execute().returnResponse();
List dataList = checkSuccessResponseReturnType(response, List.class);
assertEquals("Expect one position in movement db", 1, dataList.size());
}
use of xeu.bridge_connector.v1.ResponseType in project ddf by codice.
the class XacmlPdp method isPermitted.
protected boolean isPermitted(RequestType xacmlRequest) {
boolean permitted;
ResponseType xacmlResponse;
try {
LOGGER.debug("Calling PDP to evaluate XACML request.");
xacmlResponse = pdp.evaluate(xacmlRequest);
LOGGER.debug("Received response from PDP.");
permitted = xacmlResponse != null && xacmlResponse.getResult().get(0).getDecision() == DecisionType.PERMIT;
LOGGER.debug("Permitted: {}", permitted);
} catch (PdpException e) {
LOGGER.debug(e.getMessage(), e);
permitted = false;
}
return permitted;
}
use of xeu.bridge_connector.v1.ResponseType 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());
// 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);
}
Aggregations