Search in sources :

Example 66 with Configuration

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: ");
    }
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) NoHttpResponseException(org.apache.http.NoHttpResponseException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) BeforeExam(org.codice.ddf.itests.common.annotations.BeforeExam)

Example 67 with Configuration

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;
}
Also used : RegistrySourceConfiguration(org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration) Configuration(org.osgi.service.cm.Configuration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 68 with Configuration

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"));
}
Also used : RegistrySourceConfiguration(org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 69 with Configuration

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));
}
Also used : RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) RegistrySourceConfiguration(org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfiguredService(ddf.catalog.service.ConfiguredService) Test(org.junit.Test)

Example 70 with Configuration

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);
    }
}
Also used : Constants(org.osgi.framework.Constants) Enumeration(java.util.Enumeration) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) ArrayList(java.util.ArrayList) Configuration(org.osgi.service.cm.Configuration) Locale(java.util.Locale) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ServiceReference(org.osgi.framework.ServiceReference) ManagedServiceFactory(org.osgi.service.cm.ManagedServiceFactory) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) KeyValuePermission(ddf.security.permission.KeyValuePermission) IOException(java.io.IOException) AttributeDefinition(org.osgi.service.metatype.AttributeDefinition) Collectors(java.util.stream.Collectors) ConfigurationAdminPlugin(org.codice.ddf.ui.admin.api.plugin.ConfigurationAdminPlugin) BundleContext(org.osgi.framework.BundleContext) Sets(com.google.common.collect.Sets) MetaTypeService(org.osgi.service.metatype.MetaTypeService) List(java.util.List) Filter(org.osgi.framework.Filter) Entry(java.util.Map.Entry) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ManagedService(org.osgi.service.cm.ManagedService) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Collections(java.util.Collections) SecurityUtils(org.apache.shiro.SecurityUtils) FrameworkUtil(org.osgi.framework.FrameworkUtil) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition)

Aggregations

Configuration (org.osgi.service.cm.Configuration)226 Test (org.junit.Test)85 Hashtable (java.util.Hashtable)75 IOException (java.io.IOException)55 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)49 Dictionary (java.util.Dictionary)36 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 ServiceReference (org.osgi.framework.ServiceReference)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)18 Matchers.anyString (org.mockito.Matchers.anyString)16 BundleContext (org.osgi.framework.BundleContext)15 RegistrySourceConfiguration (org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration)11 Map (java.util.Map)10 Bundle (org.osgi.framework.Bundle)10 File (java.io.File)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 Mockito.anyString (org.mockito.Mockito.anyString)9 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)8 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)7