Search in sources :

Example 31 with MultivaluedHashMap

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

the class ResourceAdminManager method logoutClientSessions.

protected Response logoutClientSessions(RealmModel realm, ClientModel resource, List<AuthenticatedClientSessionModel> clientSessions) {
    String managementUrl = getManagementUrl(session, resource);
    if (managementUrl != null) {
        // Key is host, value is list of http sessions for this host
        MultivaluedHashMap<String, String> adapterSessionIds = null;
        List<String> userSessions = new LinkedList<>();
        if (clientSessions != null && clientSessions.size() > 0) {
            adapterSessionIds = new MultivaluedHashMap<String, String>();
            for (AuthenticatedClientSessionModel clientSession : clientSessions) {
                String adapterSessionId = clientSession.getNote(AdapterConstants.CLIENT_SESSION_STATE);
                if (adapterSessionId != null) {
                    String host = clientSession.getNote(AdapterConstants.CLIENT_SESSION_HOST);
                    adapterSessionIds.add(host, adapterSessionId);
                }
                if (clientSession.getUserSession() != null)
                    userSessions.add(clientSession.getUserSession().getId());
            }
        }
        if (adapterSessionIds == null || adapterSessionIds.isEmpty()) {
            logger.debugv("Can't logout {0}: no logged adapter sessions", resource.getClientId());
            return null;
        }
        if (managementUrl.contains(CLIENT_SESSION_HOST_PROPERTY)) {
            // Send logout separately to each host (needed for single-sign-out in cluster for non-distributable apps - KEYCLOAK-748)
            for (Map.Entry<String, List<String>> entry : adapterSessionIds.entrySet()) {
                String host = entry.getKey();
                List<String> sessionIds = entry.getValue();
                String currentHostMgmtUrl = managementUrl.replace(CLIENT_SESSION_HOST_PROPERTY, host);
                sendLogoutRequest(realm, resource, sessionIds, userSessions, 0, currentHostMgmtUrl);
            }
            return Response.ok().build();
        } else {
            // Send single logout request
            List<String> allSessionIds = new ArrayList<String>();
            for (List<String> currentIds : adapterSessionIds.values()) {
                allSessionIds.addAll(currentIds);
            }
            return sendLogoutRequest(realm, resource, allSessionIds, userSessions, 0, managementUrl);
        }
    } else {
        logger.debugv("Can't logout {0}: no management url", resource.getClientId());
        return null;
    }
}
Also used : AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) LinkedList(java.util.LinkedList)

Example 32 with MultivaluedHashMap

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

the class LDAPMappersComparatorTest method testCompareWithSAMAccountNameUsername.

@Test
public void testCompareWithSAMAccountNameUsername() {
    MultivaluedHashMap<String, String> cfg = new MultivaluedHashMap<>();
    cfg.add(LDAPConstants.USERNAME_LDAP_ATTRIBUTE, LDAPConstants.SAM_ACCOUNT_NAME);
    LDAPMappersComparator ldapMappersComparator = new LDAPMappersComparator(new LDAPConfig(cfg));
    List<ComponentModel> mappers = getMappers();
    Collections.sort(mappers, ldapMappersComparator.sortAsc());
    assertOrder(mappers, "sAMAccountName", "username-cn", "first name", "full name");
    Collections.sort(mappers, ldapMappersComparator.sortDesc());
    assertOrder(mappers, "full name", "first name", "username-cn", "sAMAccountName");
}
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 33 with MultivaluedHashMap

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

the class SSSDTest method createUserFederation.

@Before
public void createUserFederation() {
    ComponentRepresentation userFederation = new ComponentRepresentation();
    MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
    userFederation.setConfig(config);
    userFederation.setName(DISPLAY_NAME);
    userFederation.getConfig().putSingle("priority", "0");
    userFederation.setProviderType(UserStorageProvider.class.getName());
    userFederation.setProviderId(PROVIDER_NAME);
    Response response = adminClient.realm(REALM_NAME).components().add(userFederation);
    SSSDFederationID = ApiUtil.getCreatedId(response);
    response.close();
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) Response(javax.ws.rs.core.Response) UserStorageProvider(org.keycloak.storage.UserStorageProvider) Before(org.junit.Before)

Example 34 with MultivaluedHashMap

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

the class ComponentInvalidationClusterTest method createTestEntityRepresentation.

@Override
protected ComponentRepresentation createTestEntityRepresentation() {
    ComponentRepresentation comp = new ComponentRepresentation();
    MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
    comp.setName("comp_" + RandomStringUtils.randomAlphabetic(5));
    comp.setProviderId(TestAmphibianProviderFactoryImpl.PROVIDER_ID);
    comp.setProviderType(TestAmphibianProvider.class.getName());
    config.putSingle("secret", "Secret");
    config.putSingle("required", "required-value");
    config.putSingle("number", "2");
    config.put("val1", Arrays.asList(new String[] { "val1 value" }));
    config.put("val2", Arrays.asList(new String[] { "val2 value" }));
    comp.setConfig(config);
    return comp;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) TestAmphibianProvider(org.keycloak.testsuite.components.amphibian.TestAmphibianProvider)

Example 35 with MultivaluedHashMap

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

the class DefaultKeyProviders method createRsaEncKeyProvider.

private static void createRsaEncKeyProvider(String name, RealmModel realm) {
    ComponentModel generated = new ComponentModel();
    generated.setName(name);
    generated.setParentId(realm.getId());
    generated.setProviderId("rsa-enc-generated");
    generated.setProviderType(KeyProvider.class.getName());
    MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
    config.putSingle("priority", "100");
    config.putSingle("keyUse", KeyUse.ENC.name());
    config.putSingle("algorithm", JWEConstants.RSA_OAEP);
    generated.setConfig(config);
    realm.addComponentModel(generated);
}
Also used : KeyProvider(org.keycloak.keys.KeyProvider) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ComponentModel(org.keycloak.component.ComponentModel)

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