Search in sources :

Example 41 with RealmModel

use of org.keycloak.models.RealmModel in project keycloak by keycloak.

the class LDAPHardcodedAttributeTest method testHarcodedMapper.

@Test
public void testHarcodedMapper() {
    testingClient.server().run(session -> {
        LDAPTestContext ctx = LDAPTestContext.init(session);
        RealmModel appRealm = ctx.getRealm();
        UserModel user = session.users().getUserByUsername(appRealm, "johnkeycloak");
        Assert.assertNotNull(user);
        Assert.assertTrue(user.isEmailVerified());
        Assert.assertEquals("en", user.getFirstAttribute("locale"));
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserModel(org.keycloak.models.UserModel) Test(org.junit.Test)

Example 42 with RealmModel

use of org.keycloak.models.RealmModel in project keycloak by keycloak.

the class LDAPHardcodedAttributeTest method afterImportTestRealm.

@Override
protected void afterImportTestRealm() {
    testingClient.server().run(session -> {
        LDAPTestContext ctx = LDAPTestContext.init(session);
        RealmModel appRealm = ctx.getRealm();
        ComponentModel localeMapperModel = KeycloakModelUtils.createComponentModel("localeMapper", ctx.getLdapModel().getId(), HardcodedAttributeMapperFactory.PROVIDER_ID, LDAPStorageMapper.class.getName(), HardcodedAttributeMapper.USER_MODEL_ATTRIBUTE, "locale", HardcodedAttributeMapper.ATTRIBUTE_VALUE, "en");
        ComponentModel emailVerifiedMapperModel = KeycloakModelUtils.createComponentModel("emailVerifiedMapper", ctx.getLdapModel().getId(), HardcodedAttributeMapperFactory.PROVIDER_ID, LDAPStorageMapper.class.getName(), HardcodedAttributeMapper.USER_MODEL_ATTRIBUTE, "emailVerified", HardcodedAttributeMapper.ATTRIBUTE_VALUE, "true");
        appRealm.addComponentModel(localeMapperModel);
        appRealm.addComponentModel(emailVerifiedMapperModel);
        // Delete all LDAP users and add some new for testing
        LDAPStorageProvider ldapFedProvider = LDAPTestUtils.getLdapProvider(session, ctx.getLdapModel());
        LDAPTestUtils.removeAllLDAPUsers(ldapFedProvider, appRealm);
        LDAPTestUtils.addLDAPUser(ldapFedProvider, appRealm, "johnkeycloak", "John", "Doe", "john@email.org", null, "1234");
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) LDAPStorageMapper(org.keycloak.storage.ldap.mappers.LDAPStorageMapper) ComponentModel(org.keycloak.component.ComponentModel) LDAPStorageProvider(org.keycloak.storage.ldap.LDAPStorageProvider)

Example 43 with RealmModel

use of org.keycloak.models.RealmModel in project keycloak by keycloak.

the class LDAPMSADFullNameTest method test01_addUserWithoutFullName.

// @Test
// public void test01Sleep() throws Exception {
// Thread.sleep(1000000);
// }
@Test
public void test01_addUserWithoutFullName() {
    testingClient.server().run(session -> {
        LDAPTestContext ctx = LDAPTestContext.init(session);
        RealmModel appRealm = ctx.getRealm();
        UserModel john = session.users().addUser(appRealm, "johnkeycloak");
        john.setEmail("johnkeycloak@email.cz");
    });
    testingClient.server().run(session -> {
        LDAPTestContext ctx = LDAPTestContext.init(session);
        RealmModel appRealm = ctx.getRealm();
        UserModel john = session.users().getUserByUsername(appRealm, "johnkeycloak");
        Assert.assertNotNull(john.getFederationLink());
        assertDnStartsWith(session, ctx, john, "cn=johnkeycloak");
        session.users().removeUser(appRealm, john);
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserModel(org.keycloak.models.UserModel) Test(org.junit.Test)

Example 44 with RealmModel

use of org.keycloak.models.RealmModel in project keycloak by keycloak.

the class LDAPMSADFullNameTest method test02_registerUserWithFullName.

@Test
public void test02_registerUserWithFullName() {
    loginPage.open();
    loginPage.clickRegister();
    registerPage.assertCurrent();
    registerPage.register("Johny", "Anthony", "johnyanth@check.cz", "johnkeycloak", "Password1", "Password1");
    Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType());
    testingClient.server().run(session -> {
        LDAPTestContext ctx = LDAPTestContext.init(session);
        RealmModel appRealm = ctx.getRealm();
        UserModel john = session.users().getUserByUsername(appRealm, "johnkeycloak");
        assertUser(session, ctx, john, "johnkeycloak", "Johny", "Anthony", true, "cn=Johny Anthony");
        session.users().removeUser(appRealm, john);
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserModel(org.keycloak.models.UserModel) Test(org.junit.Test)

Example 45 with RealmModel

use of org.keycloak.models.RealmModel in project keycloak by keycloak.

the class LDAPMSADFullNameTest method test05_registerUserWithFullNameSpecialChars.

@Test
public void test05_registerUserWithFullNameSpecialChars() {
    loginPage.open();
    loginPage.clickRegister();
    registerPage.assertCurrent();
    registerPage.register("Jož,o", "Baříč", "johnyanth@check.cz", "johnkeycloak", "Password1", "Password1");
    Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType());
    testingClient.server().run(session -> {
        LDAPTestContext ctx = LDAPTestContext.init(session);
        RealmModel appRealm = ctx.getRealm();
        UserModel john = session.users().getUserByUsername(appRealm, "johnkeycloak");
        assertUser(session, ctx, john, "johnkeycloak", "Jož,o", "Baříč", true, "cn=Jož\\,o Baříč");
        session.users().removeUser(appRealm, john);
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserModel(org.keycloak.models.UserModel) Test(org.junit.Test)

Aggregations

RealmModel (org.keycloak.models.RealmModel)591 Test (org.junit.Test)249 UserModel (org.keycloak.models.UserModel)225 KeycloakSession (org.keycloak.models.KeycloakSession)152 ClientModel (org.keycloak.models.ClientModel)149 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)90 ModelTest (org.keycloak.testsuite.arquillian.annotation.ModelTest)84 ComponentModel (org.keycloak.component.ComponentModel)83 RoleModel (org.keycloak.models.RoleModel)73 UserSessionModel (org.keycloak.models.UserSessionModel)64 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)62 List (java.util.List)55 LDAPStorageProvider (org.keycloak.storage.ldap.LDAPStorageProvider)51 GroupModel (org.keycloak.models.GroupModel)47 HashMap (java.util.HashMap)38 Collectors (java.util.stream.Collectors)34 CachedUserModel (org.keycloak.models.cache.CachedUserModel)34 Path (javax.ws.rs.Path)30 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)30 Map (java.util.Map)29