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);
}
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)));
});
}
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);
});
});
}
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")));
});
});
}
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")));
});
});
}
Aggregations