Search in sources :

Example 41 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class RepresentationToModel method importComponents.

protected static void importComponents(RealmModel newRealm, MultivaluedHashMap<String, ComponentExportRepresentation> components, String parentId) {
    for (Map.Entry<String, List<ComponentExportRepresentation>> entry : components.entrySet()) {
        String providerType = entry.getKey();
        for (ComponentExportRepresentation compRep : entry.getValue()) {
            ComponentModel component = new ComponentModel();
            component.setId(compRep.getId());
            component.setName(compRep.getName());
            component.setConfig(compRep.getConfig());
            component.setProviderType(providerType);
            component.setProviderId(compRep.getProviderId());
            component.setSubType(compRep.getSubType());
            component.setParentId(parentId);
            component = newRealm.importComponentModel(component);
            if (compRep.getSubComponents() != null) {
                importComponents(newRealm, compRep.getSubComponents(), component.getId());
            }
        }
    }
}
Also used : ComponentExportRepresentation(org.keycloak.representations.idm.ComponentExportRepresentation) ComponentModel(org.keycloak.component.ComponentModel) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ArtifactBindingUtils.computeArtifactBindingIdentifierString(org.keycloak.protocol.saml.util.ArtifactBindingUtils.computeArtifactBindingIdentifierString) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) HashMap(java.util.HashMap)

Example 42 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class StripSecretsUtils method stripForExport.

public static RealmRepresentation stripForExport(KeycloakSession session, RealmRepresentation rep) {
    strip(rep);
    List<ClientRepresentation> clients = rep.getClients();
    if (clients != null) {
        for (ClientRepresentation c : clients) {
            strip(c);
        }
    }
    List<IdentityProviderRepresentation> providers = rep.getIdentityProviders();
    if (providers != null) {
        for (IdentityProviderRepresentation r : providers) {
            strip(r);
        }
    }
    MultivaluedHashMap<String, ComponentExportRepresentation> components = rep.getComponents();
    if (components != null) {
        for (Map.Entry<String, List<ComponentExportRepresentation>> ent : components.entrySet()) {
            for (ComponentExportRepresentation c : ent.getValue()) {
                strip(session, ent.getKey(), c);
            }
        }
    }
    List<UserRepresentation> users = rep.getUsers();
    if (users != null) {
        for (UserRepresentation u : users) {
            strip(u);
        }
    }
    users = rep.getFederatedUsers();
    if (users != null) {
        for (UserRepresentation u : users) {
            strip(u);
        }
    }
    return rep;
}
Also used : IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) ComponentExportRepresentation(org.keycloak.representations.idm.ComponentExportRepresentation) List(java.util.List) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Example 43 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class StripSecretsUtils method strip.

public static ComponentExportRepresentation strip(KeycloakSession session, String providerType, ComponentExportRepresentation rep) {
    Map<String, ProviderConfigProperty> configProperties = ComponentUtil.getComponentConfigProperties(session, providerType, rep.getProviderId());
    if (rep.getConfig() == null) {
        return rep;
    }
    Iterator<Map.Entry<String, List<String>>> itr = rep.getConfig().entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry<String, List<String>> next = itr.next();
        ProviderConfigProperty configProperty = configProperties.get(next.getKey());
        if (configProperty != null) {
            if (configProperty.isSecret()) {
                if (next.getValue() == null || next.getValue().isEmpty()) {
                    next.setValue(Collections.singletonList(ComponentRepresentation.SECRET_VALUE));
                } else {
                    next.setValue(next.getValue().stream().map(StripSecretsUtils::maskNonVaultValue).collect(Collectors.toList()));
                }
            }
        } else {
            itr.remove();
        }
    }
    MultivaluedHashMap<String, ComponentExportRepresentation> sub = rep.getSubComponents();
    for (Map.Entry<String, List<ComponentExportRepresentation>> ent : sub.entrySet()) {
        for (ComponentExportRepresentation c : ent.getValue()) {
            strip(session, ent.getKey(), c);
        }
    }
    return rep;
}
Also used : ProviderConfigProperty(org.keycloak.provider.ProviderConfigProperty) ComponentExportRepresentation(org.keycloak.representations.idm.ComponentExportRepresentation) List(java.util.List) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap)

Example 44 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class DefaultKeycloakSessionFactory method undeploy.

@Override
public void undeploy(ProviderManager pm) {
    logger.debug("undeploy");
    // we make a copy to avoid concurrent access exceptions
    Map<Class<? extends Provider>, Map<String, ProviderFactory>> copy = getFactoriesCopy();
    MultivaluedHashMap<Class<? extends Provider>, ProviderFactory> factories = pm.getLoadedFactories();
    List<ProviderFactory> undeployed = new LinkedList<>();
    for (Map.Entry<Class<? extends Provider>, List<ProviderFactory>> entry : factories.entrySet()) {
        Map<String, ProviderFactory> registered = copy.get(entry.getKey());
        for (ProviderFactory factory : entry.getValue()) {
            undeployed.add(factory);
            logger.debugv("undeploying {0} of id {1}", factory.getClass().getName(), factory.getId());
            if (registered != null) {
                registered.remove(factory.getId());
            }
        }
    }
    factoriesMap = copy;
    for (ProviderFactory factory : undeployed) {
        factory.close();
    }
}
Also used : EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) ComponentFactoryProviderFactory(org.keycloak.component.ComponentFactoryProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) LinkedList(java.util.LinkedList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) LinkedList(java.util.LinkedList) ComponentFactoryProvider(org.keycloak.component.ComponentFactoryProvider) Provider(org.keycloak.provider.Provider)

Aggregations

MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)44 ComponentModel (org.keycloak.component.ComponentModel)15 List (java.util.List)9 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8 KeyProvider (org.keycloak.keys.KeyProvider)8 RealmModel (org.keycloak.models.RealmModel)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ComponentExportRepresentation (org.keycloak.representations.idm.ComponentExportRepresentation)6 IOException (java.io.IOException)5 HttpSession (javax.servlet.http.HttpSession)5 ComponentRepresentation (org.keycloak.representations.idm.ComponentRepresentation)5 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)5 RoleModel (org.keycloak.models.RoleModel)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 ClientModel (org.keycloak.models.ClientModel)3 ClientScopeModel (org.keycloak.models.ClientScopeModel)3 BufferedReader (java.io.BufferedReader)2