Search in sources :

Example 56 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class ConfigureTestCommons method configureEnforceValidityErrorsAndWarnings.

public static void configureEnforceValidityErrorsAndWarnings(String enforceErrors, String enforceWarnings, AdminConfig configAdmin) throws IOException {
    Configuration config = configAdmin.getConfiguration(METACARD_VALIDATITY_MARKER_PLUGIN_SERVICE_PID, null);
    Dictionary properties = new Hashtable<>();
    properties.put("enforceErrors", enforceErrors);
    properties.put("enforceWarnings", enforceWarnings);
    config.update(properties);
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable)

Example 57 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class ConfigureTestCommons method configureMetacardValidityFilterPlugin.

public static void configureMetacardValidityFilterPlugin(List<String> securityAttributeMappings, AdminConfig configAdmin) throws IOException {
    Configuration config = configAdmin.getConfiguration(METACARD_VALIDATITY_FILTER_PLUGIN_SERVICE_PID, null);
    Dictionary properties = new Hashtable<>();
    properties.put("attributeMap", securityAttributeMappings);
    config.update(properties);
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable)

Example 58 with Dictionary

use of java.util.Dictionary 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 59 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class TestSecurity method testAccessGroupsGuest.

@Test
public void testAccessGroupsGuest() throws Exception {
    List attr = ImmutableList.of("security.access-groups=http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
    Dictionary authZProperties = configureAuthZRealm(attr, getAdminConfig());
    Dictionary metacardAttributeSecurityFilterProperties = null;
    String url = null;
    try {
        String testData = IOUtils.toString(IOUtils.toInputStream(getFileContent(XML_RECORD_RESOURCE_PATH + "/accessGroupTokenMetacard.xml")));
        testData = testData.replace(ACCESS_GROUP_REPLACE_TOKEN, "guest");
        String id = CatalogTestCommons.ingest(testData, MediaType.TEXT_XML);
        metacardAttributeSecurityFilterProperties = configureMetacardAttributeSecurityFiltering(attr, ImmutableList.of(""), getAdminConfig());
        url = SERVICE_ROOT.getUrl() + "/catalog/query?q=" + id + "&src=local";
        configureRestForGuest(SDK_SOAP_CONTEXT);
        waitForSecurityHandlers(url);
        getSecurityPolicy().waitForGuestAuthReady(url);
        //anon guest
        String response = getGuestRestResponseAsString(url);
        assertThat(response, containsString("Lady Liberty"));
        //configure for basic
        configureRestForBasic(SDK_SOAP_CONTEXT);
        waitForSecurityHandlers(url);
        getSecurityPolicy().waitForBasicAuthReady(url);
        //user with permissions gets results
        response = getBasicRestResponseAsString(url, A_USER, USER_PASSWORD);
        assertThat(response, containsString("Lady Liberty"));
        //user without permissions gets results
        response = getBasicRestResponseAsString(url, B_USER, USER_PASSWORD);
        assertThat(response, containsString("Lady Liberty"));
    } finally {
        configureAuthZRealm(authZProperties, getAdminConfig());
        if (metacardAttributeSecurityFilterProperties != null) {
            configureMetacardAttributeSecurityFiltering(metacardAttributeSecurityFilterProperties, getAdminConfig());
        }
        configureRestForGuest(SDK_SOAP_CONTEXT);
        getSecurityPolicy().waitForGuestAuthReady(url);
    //metacard will be deleted in @After
    }
}
Also used : Dictionary(java.util.Dictionary) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 60 with Dictionary

use of java.util.Dictionary 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

Dictionary (java.util.Dictionary)198 Hashtable (java.util.Hashtable)91 Test (org.junit.Test)48 Configuration (org.osgi.service.cm.Configuration)33 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)28 State (org.eclipse.osgi.service.resolver.State)28 Enumeration (java.util.Enumeration)27 Properties (java.util.Properties)27 BundleContext (org.osgi.framework.BundleContext)24 ArrayList (java.util.ArrayList)22 ServiceReference (org.osgi.framework.ServiceReference)21 HashMap (java.util.HashMap)20 ServiceRegistration (org.osgi.framework.ServiceRegistration)20 IOException (java.io.IOException)17 Map (java.util.Map)17 Bundle (org.osgi.framework.Bundle)16 LinkedHashMap (java.util.LinkedHashMap)13 List (java.util.List)13 Matchers.anyString (org.mockito.Matchers.anyString)11 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)11