use of org.osgi.service.cm.Configuration in project ddf by codice.
the class TestSecurity method beforeTest.
@BeforeExam
public void beforeTest() throws Exception {
try {
waitForSystemReady();
Configuration config = getAdminConfig().getConfiguration("org.codice.ddf.admin.config.policy.AdminConfigPolicy");
config.setBundleLocation("mvn:ddf.admin.core/admin-core-configpolicy/" + System.getProperty("ddf.version"));
Dictionary properties = new Hashtable<>();
List<String> featurePolicies = new ArrayList<>();
featurePolicies.addAll(Arrays.asList(getDefaultRequiredApps()));
featurePolicies.addAll(FEATURES_TO_FILTER);
featurePolicies.replaceAll(featureName -> featureName + "=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=admin\"");
List<String> servicePolicies = new ArrayList<>();
servicePolicies.addAll(SERVICES_TO_FILTER);
servicePolicies.replaceAll(serviceName -> serviceName + "=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=admin\"");
properties.put("featurePolicies", featurePolicies.stream().toArray(String[]::new));
properties.put("servicePolicies", servicePolicies.stream().toArray(String[]::new));
config.update(properties);
} catch (Exception e) {
LoggingUtils.failWithThrowableStacktrace(e, "Failed in @BeforeExam: ");
}
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class FederationAdmin method allRegistryInfo.
@Override
public List<Map<String, Object>> allRegistryInfo() {
List<Map<String, Object>> metatypes = helper.getMetatypes();
for (Map metatype : metatypes) {
try {
List<Configuration> configs = helper.getConfigurations(metatype);
ArrayList<Map<String, Object>> configurations = new ArrayList<>();
if (configs != null) {
for (Configuration config : configs) {
Map<String, Object> registry = new HashMap<>();
boolean disabled = config.getPid().endsWith(DISABLED);
registry.put(MAP_ENTRY_ID, config.getPid());
registry.put(MAP_ENTRY_ENABLED, !disabled);
registry.put(MAP_ENTRY_FPID, config.getFactoryPid());
if (!disabled) {
registry.put(MAP_ENTRY_NAME, helper.getName(config));
registry.put(MAP_ENTRY_BUNDLE_NAME, helper.getBundleName(config));
registry.put(MAP_ENTRY_BUNDLE_LOCATION, config.getBundleLocation());
registry.put(MAP_ENTRY_BUNDLE, helper.getBundleId(config));
} else {
registry.put(MAP_ENTRY_NAME, config.getPid());
}
Dictionary<String, Object> properties = config.getProperties();
Map<String, Object> plist = new HashMap<>();
for (String key : Collections.list(properties.keys())) {
plist.put(key, properties.get(key));
}
registry.put(MAP_ENTRY_PROPERTIES, plist);
configurations.add(registry);
}
metatype.put(MAP_ENTRY_CONFIGURATIONS, configurations);
}
} catch (InvalidSyntaxException | IOException e) {
LOGGER.info("Error getting registry info:", e);
}
}
Collections.sort(metatypes, (o1, o2) -> ((String) o1.get("id")).compareToIgnoreCase((String) o2.get("id")));
return metatypes;
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class FederationAdminTest method testAllRegistryInfo.
@Test
public void testAllRegistryInfo() throws Exception {
List<Map<String, Object>> metatypes = new ArrayList<>();
List<Configuration> configurations = new ArrayList<>();
Dictionary<String, Object> props = new Hashtable<>();
Dictionary<String, Object> propsDisabled = new Hashtable<>();
metatypes.add(new HashMap<>());
props.put("key1", "value1");
propsDisabled.put("key2", "value2");
Configuration config = mock(Configuration.class);
configurations.add(config);
when(config.getPid()).thenReturn("myPid");
when(config.getFactoryPid()).thenReturn("myFpid");
when(config.getProperties()).thenReturn(props);
Configuration configDisabled = mock(Configuration.class);
configurations.add(configDisabled);
when(configDisabled.getPid()).thenReturn("myPid_disabled");
when(configDisabled.getFactoryPid()).thenReturn("myFpid_disabled");
when(configDisabled.getProperties()).thenReturn(propsDisabled);
when(helper.getMetatypes()).thenReturn(metatypes);
when(helper.getConfigurations(any(Map.class))).thenReturn(configurations);
when(helper.getName(any(Configuration.class))).thenReturn("name");
when(helper.getBundleName(any(Configuration.class))).thenReturn("bundleName");
when(helper.getBundleId(any(Configuration.class))).thenReturn(1234L);
List<Map<String, Object>> updatedMetatypes = federationAdmin.allRegistryInfo();
assertThat(updatedMetatypes.size(), is(1));
ArrayList<Map<String, Object>> configs = (ArrayList<Map<String, Object>>) updatedMetatypes.get(0).get("configurations");
assertThat(configs.size(), is(2));
Map<String, Object> activeConfig = configs.get(0);
Map<String, Object> disabledConfig = configs.get(1);
assertThat(activeConfig.get("name"), equalTo("name"));
assertThat(activeConfig.get("id"), equalTo("myPid"));
assertThat(activeConfig.get("fpid"), equalTo("myFpid"));
assertThat(activeConfig.get("enabled"), equalTo(true));
assertThat(((Map<String, Object>) activeConfig.get("properties")).get("key1"), equalTo("value1"));
assertThat(disabledConfig.get("name"), equalTo("myPid_disabled"));
assertThat(disabledConfig.get("id"), equalTo("myPid_disabled"));
assertThat(disabledConfig.get("fpid"), equalTo("myFpid_disabled"));
assertThat(disabledConfig.get("enabled"), equalTo(false));
assertThat(((Map<String, Object>) disabledConfig.get("properties")).get("key2"), equalTo("value2"));
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class FederationAdminTest method testRegistryStatus.
@Test
public void testRegistryStatus() throws Exception {
RegistryStore source = mock(RegistryStore.class);
Configuration config = mock(Configuration.class);
Dictionary<String, Object> props = new Hashtable<>();
props.put("service.pid", "servicePid");
when(config.getProperties()).thenReturn(props);
when(source.isAvailable()).thenReturn(true);
when(helper.getRegistrySources()).thenReturn(Collections.singletonList(source));
when(helper.getConfiguration(any(ConfiguredService.class))).thenReturn(config);
assertThat(federationAdmin.registryStatus("servicePid"), is(true));
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdminExt method addConfigurationData.
private void addConfigurationData(Map<String, Object> service, Configuration[] configs) {
for (Configuration config : configs) {
// ignore configuration object if it is invalid
final String pid = config.getPid();
if (!isAllowedPid(pid)) {
continue;
}
Map<String, Object> configData = new HashMap<String, Object>();
configData.put(MAP_ENTRY_ID, pid);
String fpid = config.getFactoryPid();
if (fpid != null) {
configData.put(MAP_ENTRY_FPID, fpid);
}
// insert an entry for the PID
try {
ObjectClassDefinition ocd = getObjectClassDefinition(config);
if (ocd != null) {
configData.put(MAP_ENTRY_NAME, ocd.getName());
} else {
// no object class definition, use plain PID
configData.put(MAP_ENTRY_NAME, pid);
}
} catch (IllegalArgumentException t) {
// Catch exception thrown by getObjectClassDefinition so other configurations
// are displayed
// no object class definition, use plain PID
configData.put(MAP_ENTRY_NAME, pid);
}
final Bundle bundle = getBoundBundle(config);
if (null != bundle) {
configData.put(MAP_ENTRY_BUNDLE, bundle.getBundleId());
configData.put(MAP_ENTRY_BUNDLE_NAME, getName(bundle));
configData.put(MAP_ENTRY_BUNDLE_LOCATION, bundle.getLocation());
}
Map<String, Object> propertiesTable = new HashMap<String, Object>();
Dictionary<String, Object> properties = config.getProperties();
if (properties != null) {
Enumeration<String> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
propertiesTable.put(key, properties.get(key));
}
}
// If the configuration property is a password, set its value to "password" so that
// the real password value will be hidden.
List<HashMap<String, Object>> metatypeList = (List<HashMap<String, Object>>) service.get("metatype");
metatypeList.stream().filter(metatype -> AttributeDefinition.PASSWORD == (Integer) metatype.get("type")).forEach(metatype -> {
String passwordProperty = (String) metatype.get("id");
propertiesTable.put(passwordProperty, "password");
});
configData.put(MAP_ENTRY_PROPERTIES, propertiesTable);
Map<String, Object> pluginDataMap = getConfigurationPluginData(configData.get(MAP_ENTRY_ID).toString(), Collections.unmodifiableMap(configData));
if (pluginDataMap != null && !pluginDataMap.isEmpty()) {
configData.putAll(pluginDataMap);
}
List<Map<String, Object>> configurations = null;
if (service.containsKey(ENABLED_CONFIGURATION)) {
configurations = (List<Map<String, Object>>) service.get(ENABLED_CONFIGURATION);
} else if (service.containsKey(DISABLED_CONFIGURATION)) {
configurations = (List<Map<String, Object>>) service.get(DISABLED_CONFIGURATION);
} else {
configurations = new ArrayList<Map<String, Object>>();
}
configurations.add(configData);
if (((String) configData.get(MAP_ENTRY_ID)).contains(DISABLED_SERVICE_ID)) {
configData.put(ENABLED, false);
} else {
configData.put(ENABLED, true);
}
service.put(ENABLED_CONFIGURATION, configurations);
}
}
Aggregations