Search in sources :

Example 11 with MultivaluedHashMap

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

the class JettyAdapterSessionStore method saveRequest.

public void saveRequest() {
    // remember the current URI
    HttpSession session = myRequest.getSession();
    synchronized (session) {
        // But only if it is not set already, or we save every uri that leads to a login form redirect
        if (session.getAttribute(FormAuthenticator.__J_URI) == null) {
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            session.setAttribute(FormAuthenticator.__J_URI, buf.toString());
            session.setAttribute(JettyHttpFacade.__J_METHOD, myRequest.getMethod());
            if ("application/x-www-form-urlencoded".equals(myRequest.getContentType()) && "POST".equalsIgnoreCase(myRequest.getMethod())) {
                MultiMap<String> formParameters = extractFormParameters(myRequest);
                MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>();
                for (String key : formParameters.keySet()) {
                    for (Object value : formParameters.getValues(key)) {
                        map.add(key, (String) value);
                    }
                }
                session.setAttribute(CACHED_FORM_PARAMETERS, map);
            }
        }
    }
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) HttpSession(javax.servlet.http.HttpSession)

Example 12 with MultivaluedHashMap

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

the class LDAPMappersComparatorTest method testCompareWithCNUsername.

@Test
public void testCompareWithCNUsername() {
    MultivaluedHashMap<String, String> cfg = new MultivaluedHashMap<>();
    cfg.add(LDAPConstants.USERNAME_LDAP_ATTRIBUTE, LDAPConstants.CN);
    LDAPMappersComparator ldapMappersComparator = new LDAPMappersComparator(new LDAPConfig(cfg));
    List<ComponentModel> mappers = getMappers();
    Collections.sort(mappers, ldapMappersComparator.sortAsc());
    assertOrder(mappers, "username-cn", "sAMAccountName", "first name", "full name");
    Collections.sort(mappers, ldapMappersComparator.sortDesc());
    assertOrder(mappers, "full name", "first name", "sAMAccountName", "username-cn");
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) LDAPMappersComparator(org.keycloak.storage.ldap.mappers.LDAPMappersComparator) LDAPConfig(org.keycloak.storage.ldap.LDAPConfig) ComponentModel(org.keycloak.component.ComponentModel) Test(org.junit.Test)

Example 13 with MultivaluedHashMap

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

the class RealmAdapter method entityToModel.

protected ComponentModel entityToModel(ComponentEntity c) {
    ComponentModel model = new ComponentModel();
    model.setId(c.getId());
    model.setName(c.getName());
    model.setProviderType(c.getProviderType());
    model.setProviderId(c.getProviderId());
    model.setSubType(c.getSubType());
    model.setParentId(c.getParentId());
    MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
    for (ComponentConfigEntity configEntity : c.getComponentConfigs()) {
        config.add(configEntity.getName(), configEntity.getValue());
    }
    model.setConfig(config);
    return model;
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ComponentModel(org.keycloak.component.ComponentModel)

Example 14 with MultivaluedHashMap

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

the class LDAPIdentityStoreRegistry method getLdapStore.

public LDAPIdentityStore getLdapStore(KeycloakSession session, ComponentModel ldapModel, Map<ComponentModel, LDAPConfigDecorator> configDecorators) {
    LDAPIdentityStoreContext context = ldapStores.get(ldapModel.getId());
    // Ldap config might have changed for the realm. In this case, we must re-initialize
    MultivaluedHashMap<String, String> configModel = ldapModel.getConfig();
    LDAPConfig ldapConfig = new LDAPConfig(configModel);
    for (Map.Entry<ComponentModel, LDAPConfigDecorator> entry : configDecorators.entrySet()) {
        ComponentModel mapperModel = entry.getKey();
        LDAPConfigDecorator decorator = entry.getValue();
        decorator.updateLDAPConfig(ldapConfig, mapperModel);
    }
    if (context == null || !ldapConfig.equals(context.config)) {
        logLDAPConfig(session, ldapModel, ldapConfig);
        LDAPIdentityStore store = createLdapIdentityStore(session, ldapConfig);
        context = new LDAPIdentityStoreContext(ldapConfig, store);
        ldapStores.put(ldapModel.getId(), context);
    }
    return context.store;
}
Also used : LDAPIdentityStore(org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore) ComponentModel(org.keycloak.component.ComponentModel) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) LDAPConfigDecorator(org.keycloak.storage.ldap.mappers.LDAPConfigDecorator)

Example 15 with MultivaluedHashMap

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

the class MapComponentEntity method toModel.

static ComponentModel toModel(MapComponentEntity entity) {
    ComponentModel model = new ComponentModel();
    model.setId(entity.getId());
    model.setName(entity.getName());
    model.setProviderId(entity.getProviderId());
    model.setProviderType(entity.getProviderType());
    model.setSubType(entity.getSubType());
    model.setParentId(entity.getParentId());
    Map<String, List<String>> config = entity.getConfig();
    model.setConfig(config == null ? null : new MultivaluedHashMap<>(config));
    return model;
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ComponentModel(org.keycloak.component.ComponentModel) List(java.util.List)

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