Java Code Examples for org.keycloak.common.util.MultivaluedHashMap#entrySet()

The following examples show how to use org.keycloak.common.util.MultivaluedHashMap#entrySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentImportService.java    From keycloak-config-cli with Apache License 2.0 6 votes vote down vote up
private boolean isComponentEqual(ComponentRepresentation existingComponent, ComponentRepresentation patchedComponent) {
    // compare component config
    MultivaluedHashMap<String, String> existingComponentConfig = existingComponent.getConfig();
    MultivaluedHashMap<String, String> patchedComponentConfig = patchedComponent.getConfig();

    // https://lists.jboss.org/pipermail/keycloak-user/2018-December/016706.html
    boolean isUserStorageProvider = patchedComponent.getProviderType().equals("org.keycloak.storage.ldap.mappers.UserStorageProvider");
    boolean looksEquals = CloneUtil.deepEquals(existingComponent, patchedComponent, "config");
    boolean componentConfigHaveSameKeys = patchedComponentConfig.keySet().equals(existingComponentConfig.keySet());
    if (isUserStorageProvider || !looksEquals || !componentConfigHaveSameKeys) {
        return false;
    }

    for (Map.Entry<String, List<String>> config : patchedComponentConfig.entrySet()) {
        List<String> patchedComponentConfigValue = config.getValue();
        List<String> existingComponentConfigValue = existingComponentConfig.get(config.getKey());

        if (!patchedComponentConfigValue.containsAll(existingComponentConfigValue) || !existingComponentConfigValue.containsAll(patchedComponentConfigValue)) {
            return false;
        }
    }

    return true;
}
 
Example 2
Source File: ComponentImportService.java    From keycloak-config-cli with Apache License 2.0 6 votes vote down vote up
private boolean checkIfComponentMissingImport(ComponentRepresentation existingComponent, MultivaluedHashMap<String, ComponentExportRepresentation> componentsToImport) {
    String existingComponentProviderType = existingComponent.getProviderType();
    String existingComponentName = existingComponent.getName();

    for (Map.Entry<String, List<ComponentExportRepresentation>> entry : componentsToImport.entrySet()) {
        String providerType = entry.getKey();
        List<ComponentExportRepresentation> componentToImport = entry.getValue();

        if (!existingComponentProviderType.equals(providerType)) {
            continue;
        }

        boolean isInImport = componentToImport.stream().anyMatch(component -> existingComponentName.equals(component.getName()));

        if (isInImport) {
            return false;
        }
    }

    return true;
}
 
Example 3
Source File: StateService.java    From keycloak-config-cli with Apache License 2.0 6 votes vote down vote up
private void setComponents(RealmImport realmImport) {
    MultivaluedHashMap<String, ComponentExportRepresentation> components = realmImport.getComponents();
    if (components == null) return;

    List<Object> state = new ArrayList<>();

    for (Map.Entry<String, List<ComponentExportRepresentation>> entry : components.entrySet()) {
        for (ComponentExportRepresentation component : entry.getValue()) {
            String componentName = component.getName();
            state.add(componentName);

            setSubComponents(component);
        }
    }

    stateRepository.setState("components", state);
}
 
Example 4
Source File: StateService.java    From keycloak-config-cli with Apache License 2.0 6 votes vote down vote up
private void setSubComponents(ComponentExportRepresentation component) {
    MultivaluedHashMap<String, ComponentExportRepresentation> subComponents = component.getSubComponents();
    if (subComponents.isEmpty()) {
        return;
    }

    List<Object> state = new ArrayList<>();
    for (Map.Entry<String, List<ComponentExportRepresentation>> subEntry : subComponents.entrySet()) {
        List<String> nameOfSubComponents = subEntry.getValue().stream()
                .map(ComponentExportRepresentation::getName)
                .collect(Collectors.toList());

        state.addAll(nameOfSubComponents);
    }

    stateRepository.setState("sub-components-" + component.getName(), state);
}
 
Example 5
Source File: RepresentationToModel.java    From keycloak with Apache License 2.0 6 votes vote down vote up
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());
            }
        }
    }
}
 
Example 6
Source File: ResourceAdminManager.java    From keycloak with Apache License 2.0 6 votes vote down vote up
protected void logoutUserSessions(RealmModel realm, List<UserSessionModel> userSessions) {
    // Map from "app" to clientSessions for this app
    MultivaluedHashMap<String, AuthenticatedClientSessionModel> clientSessions = new MultivaluedHashMap<>();
    for (UserSessionModel userSession : userSessions) {
        putClientSessions(clientSessions, userSession);
    }

    logger.debugv("logging out {0} resources ", clientSessions.size());
    //logger.infov("logging out resources: {0}", clientSessions);

    for (Map.Entry<String, List<AuthenticatedClientSessionModel>> entry : clientSessions.entrySet()) {
        if (entry.getValue().size() == 0) {
            continue;
        }
        logoutClientSessions(realm, entry.getValue().get(0).getClient(), entry.getValue());
    }
}
 
Example 7
Source File: StripSecretsUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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;
}