use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class AbstractUserStorageDirtyDeletionTest method getFederationProvider.
protected ComponentRepresentation getFederationProvider(UserStorageProvider.EditMode editMode, boolean importEnabled) {
ComponentRepresentation provider = new ComponentRepresentation();
provider.setName(getClass().getSimpleName());
provider.setProviderId(UserMapStorageFactory.PROVIDER_ID);
provider.setProviderType(UserStorageProvider.class.getName());
provider.setConfig(new MultivaluedHashMap<>());
provider.getConfig().putSingle("priority", Integer.toString(0));
provider.getConfig().putSingle(LDAPConstants.EDIT_MODE, editMode.name());
provider.getConfig().putSingle(IMPORT_ENABLED, Boolean.toString(importEnabled));
return provider;
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class BrokenUserStorageTest method testBootWithBadProviderId.
@Test
public void testBootWithBadProviderId() throws Exception {
testingClient.server().run(session -> {
// set this system property
System.setProperty(RealmAdapter.COMPONENT_PROVIDER_EXISTS_DISABLED, "true");
RealmModel realm = session.realms().getRealmByName("master");
UserStorageProviderModel model = new UserStorageProviderModel();
model.setName("bad-provider-id");
model.setPriority(2);
model.setParentId(realm.getId());
model.setProviderId("error");
ComponentModel component = realm.importComponentModel(model);
});
controller.stop(suiteContext.getAuthServerInfo().getQualifier());
controller.start(suiteContext.getAuthServerInfo().getQualifier());
reconnectAdminClient();
loginSuccessAndLogout("test-user@localhost", "password");
// make sure we can list components and delete provider as this is an admin console operation
RealmResource master = adminClient.realms().realm("master");
String masterId = master.toRepresentation().getId();
List<ComponentRepresentation> components = master.components().query(masterId, UserStorageProvider.class.getName());
ComponentRepresentation found = null;
for (ComponentRepresentation rep : components) {
if (rep.getName().equals("bad-provider-id")) {
found = rep;
}
}
Assert.assertNotNull(found);
master.components().component(found.getId()).remove();
List<ComponentRepresentation> components2 = master.components().query(masterId, UserStorageProvider.class.getName());
Assert.assertEquals(components.size() - 1, components2.size());
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class ComponentExportImportTest method testSingleFile.
@Test
public void testSingleFile() {
clearExportImportProperties(testingClient);
RealmRepresentation realmRep = RealmBuilder.create().name(REALM_NAME).build();
adminClient.realms().create(realmRep);
String realmId = testRealmResource().toRepresentation().getId();
ComponentRepresentation parentComponent = new ComponentRepresentation();
parentComponent.setParentId(realmId);
parentComponent.setName("parent");
parentComponent.setSubType("subtype");
parentComponent.setProviderId(UserMapStorageFactory.PROVIDER_ID);
parentComponent.setProviderType(UserStorageProvider.class.getName());
parentComponent.setConfig(new MultivaluedHashMap<>());
parentComponent.getConfig().putSingle("priority", Integer.toString(0));
parentComponent.getConfig().putSingle("attr", "value");
parentComponent.getConfig().putSingle(IMPORT_ENABLED, Boolean.toString(false));
String parentComponentId = addComponent(parentComponent);
ComponentRepresentation subcomponent = new ComponentRepresentation();
subcomponent.setParentId(parentComponentId);
subcomponent.setName("child");
subcomponent.setSubType("subtype2");
subcomponent.setProviderId(UserMapStorageFactory.PROVIDER_ID);
subcomponent.setProviderType(UserStorageProvider.class.getName());
subcomponent.setConfig(new MultivaluedHashMap<>());
subcomponent.getConfig().putSingle("priority", Integer.toString(0));
subcomponent.getConfig().putSingle("attr", "value2");
subcomponent.getConfig().putSingle(IMPORT_ENABLED, Boolean.toString(false));
String subcomponentId = addComponent(subcomponent);
final String exportFilePath = exportFile.getAbsolutePath();
// export
testingClient.server().run(session -> {
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
ExportImportConfig.setFile(exportFilePath);
ExportImportConfig.setRealmName(REALM_NAME);
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
new ExportImportManager(session).runExport();
});
testRealmResource().remove();
try {
testRealmResource().toRepresentation();
Assert.fail("Realm wasn't expected to be found");
} catch (NotFoundException nfe) {
// Expected
}
// import
testingClient.server().run(session -> {
Assert.assertNull(session.realms().getRealmByName(REALM_NAME));
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
new ExportImportManager(session).runImport();
});
// Assert realm was imported
Assert.assertNotNull(testRealmResource().toRepresentation());
try {
parentComponent = testRealmResource().components().component(parentComponentId).toRepresentation();
subcomponent = testRealmResource().components().component(subcomponentId).toRepresentation();
} catch (NotFoundException nfe) {
fail("Components not found after import.");
}
Assert.assertEquals(parentComponent.getParentId(), realmId);
Assert.assertEquals(parentComponent.getName(), "parent");
Assert.assertEquals(parentComponent.getSubType(), "subtype");
Assert.assertEquals(parentComponent.getProviderId(), UserMapStorageFactory.PROVIDER_ID);
Assert.assertEquals(parentComponent.getProviderType(), UserStorageProvider.class.getName());
Assert.assertEquals(parentComponent.getConfig().getFirst("attr"), "value");
Assert.assertEquals(subcomponent.getParentId(), parentComponent.getId());
Assert.assertEquals(subcomponent.getName(), "child");
Assert.assertEquals(subcomponent.getSubType(), "subtype2");
Assert.assertEquals(subcomponent.getProviderId(), UserMapStorageFactory.PROVIDER_ID);
Assert.assertEquals(subcomponent.getProviderType(), UserStorageProvider.class.getName());
Assert.assertEquals(subcomponent.getConfig().getFirst("attr"), "value2");
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class GroupStorageTest method addProvidersBeforeTest.
@Before
public void addProvidersBeforeTest() throws URISyntaxException, IOException {
ComponentRepresentation provider = new ComponentRepresentation();
provider.setName("group-storage-hardcoded");
provider.setProviderId(HardcodedGroupStorageProviderFactory.PROVIDER_ID);
provider.setProviderType(GroupStorageProvider.class.getName());
provider.setConfig(new MultivaluedHashMap<>());
provider.getConfig().putSingle(HardcodedGroupStorageProviderFactory.GROUP_NAME, "hardcoded-group");
provider.getConfig().putSingle(HardcodedGroupStorageProviderFactory.DELAYED_SEARCH, Boolean.toString(false));
providerId = addComponent(provider);
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class LDAPSyncTest method test04SameUUIDAndUsernameSync.
// KEYCLOAK-1571
@Test
public void test04SameUUIDAndUsernameSync() {
String origUuidAttrName = testingClient.server().fetch(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
// Remove all users from model
session.userLocalStorage().getUsersStream(ctx.getRealm(), true).collect(Collectors.toList()).forEach(user -> session.userLocalStorage().removeUser(ctx.getRealm(), user));
// Change name of UUID attribute to same like usernameAttribute
String uidAttrName = ctx.getLdapProvider().getLdapIdentityStore().getConfig().getUsernameLdapAttribute();
String origUuidAttrNamee = ctx.getLdapModel().get(LDAPConstants.UUID_LDAP_ATTRIBUTE);
ctx.getLdapModel().put(LDAPConstants.UUID_LDAP_ATTRIBUTE, uidAttrName);
// 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 origUuidAttrNamee;
}, String.class);
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
KeycloakSessionFactory sessionFactory = session.getKeycloakSessionFactory();
SynchronizationResult syncResult = new UserStorageSyncManager().syncAllUsers(sessionFactory, "test", ctx.getLdapModel());
Assert.assertEquals(0, syncResult.getFailed());
});
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
// Assert users imported with correct LDAP_ID
LDAPTestAsserts.assertUserImported(session.users(), ctx.getRealm(), "user1", "User1FN", "User1LN", "user1@email.org", "121");
LDAPTestAsserts.assertUserImported(session.users(), ctx.getRealm(), "user2", "User2FN", "User2LN", "user2@email.org", "122");
UserModel user1 = session.users().getUserByUsername(ctx.getRealm(), "user1");
Assert.assertEquals("user1", user1.getFirstAttribute(LDAPConstants.LDAP_ID));
});
// Revert config changes
ComponentRepresentation ldapRep = testRealm().components().component(ldapModelId).toRepresentation();
ldapRep.getConfig().putSingle(LDAPConstants.UUID_LDAP_ATTRIBUTE, origUuidAttrName);
testRealm().components().component(ldapModelId).update(ldapRep);
}
Aggregations