Search in sources :

Example 1 with ListFieldImpl

use of org.codice.ddf.admin.common.fields.base.ListFieldImpl in project admin-console-beta by connexta.

the class SourceUtilCommons method getSourceConfigurations.

/**
     * Gets the configurations for the given factoryPids using the {@link ConfiguratorFactory}. A mapper is used
     * to transform the service properties to a {@link SourceConfigUnionField}. Providing the pid parameter
     * will return only the configuration with that pid.
     *
     * @param factoryPids factory pids to lookup configurations for
     * @param mapper a {@link Function} taking a map of string to objects and returning a {@code SourceConfigUnionField}
     * @param pid a servicePid to select a single configuration, returns all configs when null or empty
     * @return a list of {@code SourceInfoField}s configured in the system
     */
public static ListField<SourceInfoField> getSourceConfigurations(List<String> factoryPids, Function<Map<String, Object>, SourceConfigUnionField> mapper, String pid, ConfiguratorFactory configuratorFactory) {
    ListFieldImpl<SourceInfoField> sourceInfoListField = new ListFieldImpl<>(SourceInfoField.class);
    ConfigReader configReader = configuratorFactory.getConfigReader();
    if (StringUtils.isNotEmpty(pid)) {
        SourceConfigUnionField config = mapper.apply(configReader.getConfig(pid));
        sourceInfoListField.add(createSourceInfoField(true, config));
        populateSourceAvailability(sourceInfoListField.getList(), configuratorFactory);
        return sourceInfoListField;
    }
    factoryPids.stream().flatMap(factoryPid -> configReader.getManagedServiceConfigs(factoryPid).values().stream()).map(mapper).forEach(config -> sourceInfoListField.add(createSourceInfoField(false, config)));
    populateSourceAvailability(sourceInfoListField.getList(), configuratorFactory);
    return sourceInfoListField;
}
Also used : ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) ConfigReader(org.codice.ddf.admin.configurator.ConfigReader) SourceConfigUnionField(org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField) SourceInfoField(org.codice.ddf.admin.sources.fields.SourceInfoField)

Example 2 with ListFieldImpl

use of org.codice.ddf.admin.common.fields.base.ListFieldImpl in project admin-console-beta by connexta.

the class PolicyManagerServiceProperties method contextPolicyServiceToContextPolicyFields.

public ListField<ContextPolicyBin> contextPolicyServiceToContextPolicyFields(ConfiguratorFactory configurator) {
    ContextPolicyManager policyManager = configurator.getConfigReader().getServiceReference(ContextPolicyManager.class);
    List<ContextPolicyBin> policies = new ArrayList<>();
    Collection<ContextPolicy> allPolicies = policyManager.getAllContextPolicies();
    for (ContextPolicy policy : allPolicies) {
        boolean foundBin = false;
        Map<String, String> policyRequiredAttributes = policy.getAllowedAttributes().stream().collect(Collectors.toMap(map -> map.getAttributeName(), map -> map.getAttributeValue()));
        //Check if bin containing an identical context policy exists already, if so add the context path to it
        for (ContextPolicyBin bin : policies) {
            if (bin.realm().equals(policy.getRealm()) && ListUtils.isEqualList(bin.authTypes(), policy.getAuthenticationMethods()) && hasSameRequiredAttributes(bin, policyRequiredAttributes)) {
                bin.addContextPath(policy.getContextPath());
                foundBin = true;
            }
        }
        if (!foundBin) {
            policies.add(new ContextPolicyBin().realm(policy.getRealm()).addClaimsMap(policyRequiredAttributes).authTypes(policy.getAuthenticationMethods()).addContextPath(policy.getContextPath()));
        }
    }
    ListField<ContextPolicyBin> policiesField = new ListFieldImpl<>(ContextPolicyBin.class);
    policiesField.addAll(policies);
    return policiesField;
}
Also used : ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ListUtils(org.apache.commons.collections.ListUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) ServiceCommons(org.codice.ddf.admin.common.services.ServiceCommons) ConfigReader(org.codice.ddf.admin.configurator.ConfigReader) List(java.util.List) Map(java.util.Map) ListField(org.codice.ddf.admin.api.fields.ListField) ContextPolicyBin(org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) ConfiguratorFactory(org.codice.ddf.admin.configurator.ConfiguratorFactory) ContextPath(org.codice.ddf.admin.common.fields.common.ContextPath) ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) ArrayList(java.util.ArrayList) ContextPolicyBin(org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin) ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager)

Aggregations

ListFieldImpl (org.codice.ddf.admin.common.fields.base.ListFieldImpl)2 ConfigReader (org.codice.ddf.admin.configurator.ConfigReader)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 ListUtils (org.apache.commons.collections.ListUtils)1 ListField (org.codice.ddf.admin.api.fields.ListField)1 ContextPath (org.codice.ddf.admin.common.fields.common.ContextPath)1 ServiceCommons (org.codice.ddf.admin.common.services.ServiceCommons)1 ConfiguratorFactory (org.codice.ddf.admin.configurator.ConfiguratorFactory)1 ContextPolicyBin (org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin)1 SourceInfoField (org.codice.ddf.admin.sources.fields.SourceInfoField)1 SourceConfigUnionField (org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField)1 ContextPolicy (org.codice.ddf.security.policy.context.ContextPolicy)1 ContextPolicyManager (org.codice.ddf.security.policy.context.ContextPolicyManager)1