use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class LDAPBinaryAttributesTest method after.
@After
public void after() {
ComponentRepresentation jpegMapper = adminClient.realm("test").components().query(ldapModelId, LDAPStorageMapper.class.getName(), "jpeg-mapper").get(0);
adminClient.realm("test").components().component(jpegMapper.getId()).remove();
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class LDAPGroupMapperSyncTest method test05SyncRestAPI.
@Test
public void test05SyncRestAPI() {
ComponentRepresentation groupMapperRep = findMapperRepByName("groupsMapper");
try {
// testing KEYCLOAK-3980 which threw an NPE because I was looking up the factory wrong.
SynchronizationResultRepresentation syncResultRep = adminClient.realm("test").userStorage().syncMapperData(ldapModelId, groupMapperRep.getId(), "error");
Assert.fail("Should throw 400");
} catch (BadRequestException e) {
}
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class ExportImportTest method testRealmExportImport.
private void testRealmExportImport() throws LifecycleException {
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
testingClient.testing().exportImport().setRealmName("test");
testingClient.testing().exportImport().runExport();
List<ComponentRepresentation> components = adminClient.realm("test").components().query();
KeysMetadataRepresentation keyMetadata = adminClient.realm("test").keys().getKeyMetadata();
String sampleRealmRoleId = adminClient.realm("test").roles().get("sample-realm-role").toRepresentation().getId();
Map<String, List<String>> roleAttributes = adminClient.realm("test").roles().get("attribute-role").toRepresentation().getAttributes();
String testAppId = adminClient.realm("test").clients().findByClientId("test-app").get(0).getId();
String sampleClientRoleId = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getId();
String sampleClientRoleAttribute = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getAttributes().get("sample-client-role-attribute").get(0);
// Delete some realm (and some data in admin realm)
adminClient.realm("test").remove();
Assert.assertNames(adminClient.realms().findAll(), "test-realm", "master");
assertNotAuthenticated("test", "test-user@localhost", "password");
assertNotAuthenticated("test", "user1", "password");
assertNotAuthenticated("test", "user2", "password");
assertNotAuthenticated("test", "user3", "password");
assertNotAuthenticated("test", "user-requiredOTP", "password");
assertNotAuthenticated("test", "user-requiredWebAuthn", "password");
// Configure import
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
testingClient.testing().exportImport().runImport();
// Ensure data are imported back, but just for "test" realm
Assert.assertNames(adminClient.realms().findAll(), "master", "test", "test-realm");
assertAuthenticated("test", "test-user@localhost", "password");
assertAuthenticated("test", "user1", "password");
assertAuthenticated("test", "user2", "password");
assertAuthenticated("test", "user3", "password");
assertAuthenticated("test", "user-requiredOTP", "password");
assertAuthenticated("test", "user-requiredWebAuthn", "password");
RealmResource testRealmRealm = adminClient.realm("test");
assertTrue(testRealmRealm.users().search("user-requiredOTP").get(0).getRequiredActions().get(0).equals(UserModel.RequiredAction.CONFIGURE_TOTP.name()));
assertTrue(testRealmRealm.users().search("user-requiredWebAuthn").get(0).getRequiredActions().get(0).equals(WebAuthnRegisterFactory.PROVIDER_ID));
List<ComponentRepresentation> componentsImported = adminClient.realm("test").components().query();
assertComponents(components, componentsImported);
KeysMetadataRepresentation keyMetadataImported = adminClient.realm("test").keys().getKeyMetadata();
assertEquals(keyMetadata.getActive(), keyMetadataImported.getActive());
String importedSampleRealmRoleId = adminClient.realm("test").roles().get("sample-realm-role").toRepresentation().getId();
assertEquals(sampleRealmRoleId, importedSampleRealmRoleId);
Map<String, List<String>> importedRoleAttributes = adminClient.realm("test").roles().get("attribute-role").toRepresentation().getAttributes();
Assert.assertRoleAttributes(roleAttributes, importedRoleAttributes);
String importedSampleClientRoleId = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getId();
assertEquals(sampleClientRoleId, importedSampleClientRoleId);
String importedSampleClientRoleAttribute = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getAttributes().get("sample-client-role-attribute").get(0);
assertEquals(sampleClientRoleAttribute, importedSampleClientRoleAttribute);
checkEventsConfig(adminClient.realm("test").getRealmEventsConfig());
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class ExportImportTest method assertComponents.
private void assertComponents(List<ComponentRepresentation> expected, List<ComponentRepresentation> actual) {
expected.sort((o1, o2) -> o1.getId().compareTo(o2.getId()));
actual.sort((o1, o2) -> o1.getId().compareTo(o2.getId()));
assertEquals(expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
ComponentRepresentation e = expected.get(i);
ComponentRepresentation a = actual.get(i);
assertEquals(e.getId(), a.getId());
assertEquals(e.getName(), a.getName());
assertEquals(e.getProviderId(), a.getProviderId());
assertEquals(e.getProviderType(), a.getProviderType());
assertEquals(e.getParentId(), a.getParentId());
assertEquals(e.getSubType(), a.getSubType());
Assert.assertNames(e.getConfig().keySet(), a.getConfig().keySet().toArray(new String[] {}));
// Compare config values without take order into account
for (Map.Entry<String, List<String>> entry : e.getConfig().entrySet()) {
List<String> eList = entry.getValue();
List<String> aList = a.getConfig().getList(entry.getKey());
Assert.assertNames(eList, aList.toArray(new String[] {}));
}
}
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class LDAPNoMSADTest method testUpdateWithUnmappedRdnAttribute.
// KEYCLOAK-4364
@Test
public void testUpdateWithUnmappedRdnAttribute() {
ComponentRepresentation snMapperRep = findMapperRepByName("last name");
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
RealmModel appRealm = ctx.getRealm();
ComponentModel snMapper = null;
// Create LDAP user with "sn" attribute in RDN like "sn=Doe2,ou=People,dc=domain,dc=com"
LDAPStorageProvider ldapProvider = LDAPTestUtils.getLdapProvider(session, ctx.getLdapModel());
LDAPObject john2 = LDAPTestUtils.addLDAPUser(ldapProvider, appRealm, "johnkeycloak2", "John2", "Doe2", "john2@email.org", null, "4321");
john2.setRdnAttributeName("sn");
ldapProvider.getLdapIdentityStore().update(john2);
// Assert DN was changed
Assert.assertEquals("sn=Doe2", john2.getDn().getFirstRdn().toString());
// Remove "sn" mapper
snMapper = appRealm.getComponentsStream(ctx.getLdapModel().getId(), LDAPStorageMapper.class.getName()).filter(mapper -> Objects.equals(mapper.getName(), "last name")).findFirst().orElse(null);
Assert.assertNotNull(snMapper);
appRealm.removeComponent(snMapper);
});
// Try to update johnkeycloak2 user. It shouldn't try to update DN
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
RealmModel appRealm = ctx.getRealm();
UserModel johnkeycloak2 = session.users().getUserByUsername(appRealm, "johnkeycloak2");
Assert.assertNotNull(johnkeycloak2);
johnkeycloak2.setFirstName("foo2");
johnkeycloak2.setLastName("foo");
});
// Re-create "sn" mapper back
snMapperRep.setId(null);
testRealm().components().add(snMapperRep);
}
Aggregations