use of org.keycloak.representations.idm.ComponentRepresentation in project openremote by openremote.
the class LDAPComponentBuilder method build.
public ComponentRepresentation build() {
ComponentRepresentation componentRepresentation = new ComponentRepresentation();
componentRepresentation.setName(name);
componentRepresentation.setParentId(parentId);
componentRepresentation.setProviderType(providerType.toString());
componentRepresentation.setProviderId(providerId.toString());
componentRepresentation.setConfig(ldapConfig);
return componentRepresentation;
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class UserStorageOTPTest method addProvidersBeforeTest.
@Before
public void addProvidersBeforeTest() throws URISyntaxException, IOException {
ComponentRepresentation dummyProvider = new ComponentRepresentation();
dummyProvider.setName("dummy");
dummyProvider.setId(DummyUserFederationProviderFactory.PROVIDER_NAME);
dummyProvider.setProviderId(DummyUserFederationProviderFactory.PROVIDER_NAME);
dummyProvider.setProviderType(UserStorageProvider.class.getName());
dummyProvider.setConfig(new MultivaluedHashMap<>());
dummyProvider.getConfig().putSingle("priority", Integer.toString(0));
dummyProvider.getConfig().putSingle(IMPORT_ENABLED, Boolean.toString(false));
addComponent(testRealm(), getCleanup(), dummyProvider);
UserRepresentation user = UserBuilder.create().username("test-user").email("test-user@something.org").build();
String testUserId = ApiUtil.createUserWithAdminClient(testRealm(), user);
getCleanup().addUserId(testUserId);
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class UserStorageTest method addProvidersBeforeTest.
@Before
public void addProvidersBeforeTest() throws URISyntaxException, IOException {
ComponentRepresentation memProvider = new ComponentRepresentation();
memProvider.setName("memory");
memProvider.setProviderId(UserMapStorageFactory.PROVIDER_ID);
memProvider.setProviderType(UserStorageProvider.class.getName());
memProvider.setConfig(new MultivaluedHashMap<>());
memProvider.getConfig().putSingle("priority", Integer.toString(0));
memProvider.getConfig().putSingle(IMPORT_ENABLED, Boolean.toString(false));
memProviderId = addComponent(memProvider);
// copy files used by the following RO/RW user providers
File stResDir = new File(getClass().getResource("/storage-test").toURI());
if (stResDir.exists() && stResDir.isDirectory() && CONFIG_DIR.exists() && CONFIG_DIR.isDirectory()) {
for (File f : stResDir.listFiles()) {
log.infof("Copying %s to %s", f.getName(), CONFIG_DIR.getAbsolutePath());
FileUtils.copyFileToDirectory(f, CONFIG_DIR);
}
} else {
throw new RuntimeException("Property `auth.server.config.dir` must be set to run UserStorageTests.");
}
ComponentRepresentation propProviderRO = new ComponentRepresentation();
propProviderRO.setName("read-only-user-props");
propProviderRO.setProviderId(UserPropertyFileStorageFactory.PROVIDER_ID);
propProviderRO.setProviderType(UserStorageProvider.class.getName());
propProviderRO.setConfig(new MultivaluedHashMap<>());
propProviderRO.getConfig().putSingle("priority", Integer.toString(1));
propProviderRO.getConfig().putSingle("propertyFile", CONFIG_DIR.getAbsolutePath() + File.separator + "read-only-user-password.properties");
propProviderROId = addComponent(propProviderRO);
propProviderRWId = addComponent(newPropProviderRW());
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class LDAPProvidersIntegrationNoImportTest method testUnsynced.
@Test
@Override
public // Unsynced mode doesn't have much sense in no-import. So it is not allowed at the configuration level
void testUnsynced() throws Exception {
ComponentResource ldapProviderResource = testRealm().components().component(ldapModelId);
ComponentRepresentation ldapProviderRep = ldapProviderResource.toRepresentation();
String currentEditMode = ldapProviderRep.getConfig().getFirst(LDAPConstants.EDIT_MODE);
Assert.assertEquals(UserStorageProvider.EditMode.WRITABLE.toString(), currentEditMode);
// Try update editMode to UNSYNCED. It should not work as UNSYNCED with no-import is not allowed
ldapProviderRep.getConfig().putSingle(LDAPConstants.EDIT_MODE, UserStorageProvider.EditMode.UNSYNCED.toString());
try {
ldapProviderResource.update(ldapProviderRep);
Assert.fail("Not expected to successfully update provider");
} catch (BadRequestException bre) {
// Expected
}
// Try to set editMode to WRITABLE should work
ldapProviderRep.getConfig().putSingle(LDAPConstants.EDIT_MODE, currentEditMode);
ldapProviderResource.update(ldapProviderRep);
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class LDAPSyncTest method test05MissingLDAPUsernameSync.
// KEYCLOAK-1728
@Test
public void test05MissingLDAPUsernameSync() {
String origUsernameAttrName = testingClient.server().fetch(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
// Remove all users from model
session.userLocalStorage().getUsersStream(ctx.getRealm(), true).peek(user -> System.out.println("trying to delete user: " + user.getUsername())).collect(Collectors.toList()).forEach(user -> {
UserCache userCache = session.userCache();
if (userCache != null) {
userCache.evict(ctx.getRealm(), user);
}
session.userLocalStorage().removeUser(ctx.getRealm(), user);
});
// Add street mapper and add some user including street
ComponentModel streetMapper = LDAPTestUtils.addUserAttributeMapper(ctx.getRealm(), ctx.getLdapModel(), "streetMapper", "street", LDAPConstants.STREET);
LDAPObject streetUser = LDAPTestUtils.addLDAPUser(ctx.getLdapProvider(), ctx.getRealm(), "user8", "User8FN", "User8LN", "user8@email.org", "user8street", "126");
// Change name of username attribute name to street
String origUsernameAttrNamee = ctx.getLdapModel().get(LDAPConstants.USERNAME_LDAP_ATTRIBUTE);
ctx.getLdapModel().getConfig().putSingle(LDAPConstants.USERNAME_LDAP_ATTRIBUTE, "street");
// Need to change this due to ApacheDS pagination bug (For other LDAP servers, pagination works fine) TODO: Remove once ApacheDS upgraded and pagination is fixed
ctx.getLdapModel().put(LDAPConstants.BATCH_SIZE_FOR_SYNC, "10");
ctx.getRealm().updateComponent(ctx.getLdapModel());
return origUsernameAttrNamee;
}, String.class);
// Just user8 synced. All others failed to sync
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
KeycloakSessionFactory sessionFactory = session.getKeycloakSessionFactory();
SynchronizationResult syncResult = new UserStorageSyncManager().syncAllUsers(sessionFactory, "test", ctx.getLdapModel());
Assert.assertEquals(1, syncResult.getAdded());
Assert.assertTrue(syncResult.getFailed() > 0);
});
// Revert config changes
ComponentRepresentation ldapRep = testRealm().components().component(ldapModelId).toRepresentation();
if (origUsernameAttrName == null) {
ldapRep.getConfig().remove(LDAPConstants.USERNAME_LDAP_ATTRIBUTE);
} else {
ldapRep.getConfig().putSingle(LDAPConstants.USERNAME_LDAP_ATTRIBUTE, origUsernameAttrName);
}
testRealm().components().component(ldapModelId).update(ldapRep);
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
// Revert config changes
ComponentModel streetMapper = LDAPTestUtils.getSubcomponentByName(ctx.getRealm(), ctx.getLdapModel(), "streetMapper");
ctx.getRealm().removeComponent(streetMapper);
});
}
Aggregations