use of org.codice.ddf.parser.xml.XmlParser 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(), mock(SecurityLogger.class));
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 org.codice.ddf.parser.xml.XmlParser in project ddf by codice.
the class TestRegistryStore method setup.
@Before
public void setup() throws Exception {
parser = new XmlParser();
marshaller = new MetacardMarshaller(new XmlParser());
context = mock(BundleContext.class);
provider = mock(Converter.class);
cswSourceConfiguration = new CswSourceConfiguration();
factory = mock(SecureCxfClientFactory.class);
transformer = mock(TransformerManager.class);
encryptionService = mock(EncryptionService.class);
configAdmin = mock(ConfigurationAdmin.class);
configuration = mock(Configuration.class);
subject = mock(Subject.class);
queryResults = new ArrayList<>();
registryStore = spy(new RegistryStoreImpl(context, cswSourceConfiguration, provider, factory, encryptionService) {
@Override
protected void validateOperation() {
}
@Override
public boolean isAvailable() {
return availability;
}
@Override
protected SourceResponse query(QueryRequest queryRequest, ElementSetType elementSetName, List<QName> elementNames, Csw csw) throws UnsupportedQueryException {
if (queryResults == null) {
throw new UnsupportedQueryException("Test - Bad Query");
}
return new SourceResponseImpl(queryRequest, queryResults);
}
@Override
protected CapabilitiesType getCapabilities() {
return mock(CapabilitiesType.class);
}
@Override
public void configureCswSource() {
}
;
@Override
protected Subject getSystemSubject() {
return subject;
}
@Override
BundleContext getBundleContext() {
return context;
}
});
registryStore.setFilterBuilder(filterBuilder);
registryStore.setFilterAdapter(filterAdapter);
registryStore.setConfigAdmin(configAdmin);
registryStore.setMetacardMarshaller(new MetacardMarshaller(parser));
registryStore.setSchemaTransformerManager(transformer);
registryStore.setAutoPush(true);
registryStore.setRegistryUrl("http://test.url:0101/example");
properties = new Hashtable<>();
properties.put(RegistryStoreImpl.ID, "registryId");
registryStore.setMetacardMarshaller(marshaller);
when(configAdmin.getConfiguration(any())).thenReturn(configuration);
when(configuration.getProperties()).thenReturn(properties);
}
use of org.codice.ddf.parser.xml.XmlParser in project ddf by codice.
the class RegistryReportBuilderTest method setup.
@Before
public void setup() {
parser = new XmlParser();
registryTransformer = spy(new RegistryTransformer());
registryTransformer.setParser(parser);
registryTransformer.setRegistryMetacardType(new RegistryObjectMetacardType());
configurator = parser.configureParser(Arrays.asList(RegistryObjectType.class.getPackage().getName(), EbrimConstants.OGC_FACTORY.getClass().getPackage().getName(), EbrimConstants.GML_FACTORY.getClass().getPackage().getName()), this.getClass().getClassLoader());
reportHelper = new RegistryReportBuilder();
reportHelper.setup();
}
use of org.codice.ddf.parser.xml.XmlParser in project ddf by codice.
the class FederationAdminTest method setup.
@Before
public void setup() throws Exception {
parser = new XmlParser();
configurator = parser.configureParser(Arrays.asList(RegistryObjectType.class.getPackage().getName(), EbrimConstants.OGC_FACTORY.getClass().getPackage().getName(), EbrimConstants.GML_FACTORY.getClass().getPackage().getName()), this.getClass().getClassLoader());
federationAdmin = new FederationAdmin(helper) {
@Override
public BundleContext getContext() {
return context;
}
};
federationAdmin.setFederationAdminService(federationAdminService);
federationAdmin.setRegistryTransformer(registryTransformer);
federationAdmin.setMetacardMarshaller(new MetacardMarshaller(parser));
federationAdmin.setSlotHelper(new SlotTypeHelper());
federationAdmin.setRegistryMapConverter(new RegistryPackageWebConverter());
federationAdmin.setRegistryTypeConverter(new RegistryPackageTypeConverter());
federationAdmin.setSourceConfigRefresh(sourceConfiguration);
mcard = new MetacardImpl(new RegistryObjectMetacardType());
mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "myId");
mcard.setAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, new ArrayList<>());
mcard.setId("someUUID");
when(queryResponse.getResults()).thenReturn(Collections.singletonList(new ResultImpl(mcard)));
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse);
catalogStoreMap.put("myDest", store);
}
use of org.codice.ddf.parser.xml.XmlParser in project ddf by codice.
the class SourceConfigurationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
parser = new XmlParser();
adminService = mock(FederationAdminService.class);
configAdmin = mock(ConfigurationAdmin.class);
metaTypeService = mock(MetaTypeService.class);
bundleContext = mock(BundleContext.class);
executorService = mock(ExecutorService.class);
sch = new SourceConfigurationHandler(adminService, executorService) {
@Override
protected BundleContext getBundleContext() {
return bundleContext;
}
};
sch.setMetacardMarshaller(new MetacardMarshaller(parser));
sch.setConfigurationAdmin(configAdmin);
sch.setMetaTypeService(metaTypeService);
sch.setSlotHelper(new SlotTypeHelper());
sch.setRegistryTypeHelper(new RegistryPackageTypeHelper());
sch.setActivateConfigurations(false);
sch.setPreserveActiveConfigurations(true);
sch.setUrlBindingName("urlBindingName");
sch.setBindingTypeFactoryPid(Collections.singletonList("CSW_2.0.2=Csw_Federated_Source"));
sch.setSourceActivationPriorityOrder(Collections.singletonList("CSW_2.0.2"));
sch.setCleanUpOnDelete(false);
Bundle bundle = mock(Bundle.class);
mti = mock(MetaTypeInformation.class);
ocd = mock(ObjectClassDefinition.class);
config = mock(Configuration.class);
AttributeDefinition adi = new AttributeDefinitionImpl("attId", "attName", "attDesc", "attValue");
when(adminService.getRegistryMetacards()).thenReturn(new ArrayList());
when(bundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
when(configAdmin.listConfigurations("(id=TestRegNode")).thenReturn(null);
when(configAdmin.listConfigurations("(registry-id=urn:uuid:2014ca7f59ac46f495e32b4a67a51276")).thenReturn(null);
when(metaTypeService.getMetaTypeInformation(any(Bundle.class))).thenReturn(mti);
when(mti.getObjectClassDefinition(anyString(), anyString())).thenReturn(ocd);
when(ocd.getAttributeDefinitions(anyInt())).thenReturn(new AttributeDefinition[] { adi });
when(configAdmin.createFactoryConfiguration(anyString(), anyString())).thenReturn(config);
mcard = new MetacardImpl(new RegistryObjectMetacardType());
mcard.setTags(Collections.singleton(RegistryConstants.REGISTRY_TAG));
mcard.setId("2014ca7f59ac46f495e32b4a67a51276");
mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
mcard.setMetadata(getMetadata("/csw-rim-node-csw-binding.xml"));
mcard.setTitle("TestRegNode");
Dictionary<String, Object> eventProperties = new Hashtable<>();
eventProperties.put("ddf.catalog.event.metacard", mcard);
createEvent = new Event("ddf/catalog/event/CREATED", eventProperties);
updateEvent = new Event("ddf/catalog/event/UPDATED", eventProperties);
deleteEvent = new Event("ddf/catalog/event/DELETED", eventProperties);
System.setProperty(RegistryConstants.REGISTRY_ID_PROPERTY, "myRegId");
}
Aggregations