Search in sources :

Example 91 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class LDAPTestContext method init.

public static LDAPTestContext init(KeycloakSession session) {
    RealmModel testRealm = session.realms().getRealm(AbstractLDAPTest.TEST_REALM_NAME);
    ComponentModel ldapCompModel = LDAPTestUtils.getLdapProviderModel(testRealm);
    UserStorageProviderModel ldapModel = new UserStorageProviderModel(ldapCompModel);
    LDAPStorageProvider ldapProvider = LDAPTestUtils.getLdapProvider(session, ldapModel);
    return new LDAPTestContext(testRealm, ldapModel, ldapProvider);
}
Also used : RealmModel(org.keycloak.models.RealmModel) ComponentModel(org.keycloak.component.ComponentModel) LDAPStorageProvider(org.keycloak.storage.ldap.LDAPStorageProvider) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 92 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class LDAPUserPropertiesMappingTest method createAndReadUser.

@Test
public void createAndReadUser() {
    testingClient.server(TEST_REALM_NAME).run(session -> {
        KeycloakContext context = session.getContext();
        RealmModel realm = context.getRealm();
        UserModel test10 = session.users().getUserByUsername(DIETMAR, realm);
        Assert.assertTrue(test10.isEnabled());
        Assert.assertTrue(test10.isEmailVerified());
        UserModel test11 = session.users().getUserByUsername(STEFAN, realm);
        Assert.assertFalse(test11.isEnabled());
        Assert.assertFalse(test11.isEmailVerified());
        ComponentModel ldapProviderModel = LDAPTestUtils.getLdapProviderModel(realm);
        LDAPStorageProvider ldapProvider = LDAPTestUtils.getLdapProvider(session, ldapProviderModel);
        LDAPObject user10FromLdap = ldapProvider.loadLDAPUserByUsername(realm, DIETMAR);
        Assert.assertTrue(Boolean.parseBoolean(user10FromLdap.getAttributeAsString(USER_EMAIL_VERIFIED_LDAP_ATTRIBUTE)));
        Assert.assertTrue(Boolean.parseBoolean(user10FromLdap.getAttributeAsString(USER_ENABLED_LDAP_ATTRIBUTE)));
        LDAPObject user11FromLdap = ldapProvider.loadLDAPUserByUsername(realm, STEFAN);
        Assert.assertFalse(Boolean.parseBoolean(user11FromLdap.getAttributeAsString(USER_EMAIL_VERIFIED_LDAP_ATTRIBUTE)));
        Assert.assertFalse(Boolean.parseBoolean(user11FromLdap.getAttributeAsString(USER_ENABLED_LDAP_ATTRIBUTE)));
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserModel(org.keycloak.models.UserModel) KeycloakContext(org.keycloak.models.KeycloakContext) ComponentModel(org.keycloak.component.ComponentModel) LDAPStorageProvider(org.keycloak.storage.ldap.LDAPStorageProvider) LDAPObject(org.keycloak.storage.ldap.idm.model.LDAPObject) Test(org.junit.Test)

Example 93 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class LDAPUserPropertiesMappingTest method afterImportTestRealm.

@Override
protected void afterImportTestRealm() {
    testingClient.server().run(session -> {
        LDAPTestContext ctx = LDAPTestContext.init(session);
        RealmModel appRealm = ctx.getRealm();
        ComponentModel ldapModel = appRealm.getComponentsStream(appRealm.getId(), UserStorageProvider.class.getName()).findFirst().get();
        ldapModel.getConfig().putSingle(UserStorageProviderModel.IMPORT_ENABLED, "false");
        appRealm.updateComponent(ldapModel);
        ComponentModel emailVerifiedMapperModel = LDAPTestUtils.addUserAttributeMapper(appRealm, ldapModel, "customEmailVerifiedMapper", "emailVerified", USER_EMAIL_VERIFIED_LDAP_ATTRIBUTE);
        appRealm.updateComponent(emailVerifiedMapperModel);
        ComponentModel enabledMapperModel = LDAPTestUtils.addUserAttributeMapper(appRealm, ldapModel, "customEnabledMapper", "enabled", USER_ENABLED_LDAP_ATTRIBUTE);
        appRealm.updateComponent(enabledMapperModel);
        appRealm.getClientByClientId("test-app").setDirectAccessGrantsEnabled(true);
        LDAPStorageProvider ldapFedProvider = LDAPTestUtils.getLdapProvider(session, ldapModel);
        LDAPTestUtils.addLdapUser(session, appRealm, ldapFedProvider, DIETMAR, null, user -> {
            user.setEnabled(true);
            user.setEmailVerified(true);
        });
        LDAPTestUtils.addLdapUser(session, appRealm, ldapFedProvider, STEFAN, null, user -> {
            user.setEnabled(false);
            user.setEmailVerified(false);
        });
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserStorageProvider(org.keycloak.storage.UserStorageProvider) ComponentModel(org.keycloak.component.ComponentModel) LDAPStorageProvider(org.keycloak.storage.ldap.LDAPStorageProvider)

Example 94 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class ClientStorageTest method testSearchTimeout.

@Test
public void testSearchTimeout() throws Exception {
    runTestWithTimeout(4000, () -> {
        String hardcodedClient = HardcodedClientStorageProviderFactory.PROVIDER_ID;
        String delayedSearch = HardcodedClientStorageProviderFactory.DELAYED_SEARCH;
        String providerId = this.providerId;
        testingClient.server().run(session -> {
            RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST);
            assertThat(session.clientStorageManager().searchClientsByClientIdStream(realm, "client", null, null).map(ClientModel::getClientId).collect(Collectors.toList()), allOf(hasItem(hardcodedClient), hasItem("root-url-client")));
            // test the pagination; the clients from local storage (root-url-client) are fetched first
            assertThat(session.clientStorageManager().searchClientsByClientIdStream(realm, "client", 0, 1).map(ClientModel::getClientId).collect(Collectors.toList()), allOf(not(hasItem(hardcodedClient)), hasItem("root-url-client")));
            assertThat(session.clientStorageManager().searchClientsByClientIdStream(realm, "client", 1, 1).map(ClientModel::getClientId).collect(Collectors.toList()), allOf(hasItem(hardcodedClient), not(hasItem("root-url-client"))));
            // update the provider to simulate delay during the search
            ComponentModel memoryProvider = realm.getComponent(providerId);
            memoryProvider.getConfig().putSingle(delayedSearch, Boolean.toString(true));
            realm.updateComponent(memoryProvider);
        });
        testingClient.server().run(session -> {
            // search for clients and check hardcoded-client is not present
            assertThat(session.clientStorageManager().searchClientsByClientIdStream(session.realms().getRealmByName(AuthRealm.TEST), "client", null, null).map(ClientModel::getClientId).collect(Collectors.toList()), allOf(not(hasItem(hardcodedClient)), hasItem("root-url-client")));
        });
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientModel(org.keycloak.models.ClientModel) ComponentModel(org.keycloak.component.ComponentModel) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 95 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class RoleStorageTest method testSearchTimeout.

@Test
public void testSearchTimeout() throws Exception {
    runTestWithTimeout(4000, () -> {
        String hardcodedRole = HardcodedRoleStorageProviderFactory.PROVIDER_ID;
        String delayedSearch = HardcodedRoleStorageProviderFactory.DELAYED_SEARCH;
        String providerId = this.providerId;
        testingClient.server().run(session -> {
            RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST);
            assertThat(session.roleStorageManager().searchForRolesStream(realm, "role", null, null).map(RoleModel::getName).collect(Collectors.toList()), allOf(hasItem(hardcodedRole), hasItem("sample-realm-role")));
            // update the provider to simulate delay during the search
            ComponentModel memoryProvider = realm.getComponent(providerId);
            memoryProvider.getConfig().putSingle(delayedSearch, Boolean.toString(true));
            realm.updateComponent(memoryProvider);
        });
        testingClient.server().run(session -> {
            RealmModel realm = session.realms().getRealmByName(AuthRealm.TEST);
            // search for roles and check hardcoded-role is not present
            assertThat(session.roleStorageManager().searchForRolesStream(realm, "role", null, null).map(RoleModel::getName).collect(Collectors.toList()), allOf(not(hasItem(hardcodedRole)), hasItem("sample-realm-role")));
        });
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) ComponentModel(org.keycloak.component.ComponentModel) RoleModel(org.keycloak.models.RoleModel) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Aggregations

ComponentModel (org.keycloak.component.ComponentModel)155 RealmModel (org.keycloak.models.RealmModel)74 Test (org.junit.Test)52 LDAPStorageProvider (org.keycloak.storage.ldap.LDAPStorageProvider)46 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)34 UserModel (org.keycloak.models.UserModel)29 HashMap (java.util.HashMap)22 UserStorageProviderModel (org.keycloak.storage.UserStorageProviderModel)22 GroupModel (org.keycloak.models.GroupModel)21 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)18 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)18 ComponentValidationException (org.keycloak.component.ComponentValidationException)16 UserStorageProvider (org.keycloak.storage.UserStorageProvider)16 LDAPStorageMapper (org.keycloak.storage.ldap.mappers.LDAPStorageMapper)15 GroupLDAPStorageMapper (org.keycloak.storage.ldap.mappers.membership.group.GroupLDAPStorageMapper)15 Path (javax.ws.rs.Path)14 DeclarativeUserProfileProvider (org.keycloak.userprofile.DeclarativeUserProfileProvider)13 ModelException (org.keycloak.models.ModelException)11 UPAttribute (org.keycloak.userprofile.config.UPAttribute)11 UPConfig (org.keycloak.userprofile.config.UPConfig)11