Search in sources :

Example 51 with ComponentRepresentation

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;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) UserStorageProvider(org.keycloak.storage.UserStorageProvider)

Example 52 with ComponentRepresentation

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());
}
Also used : RealmModel(org.keycloak.models.RealmModel) ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) UserStorageProvider(org.keycloak.storage.UserStorageProvider) RealmResource(org.keycloak.admin.client.resource.RealmResource) ComponentModel(org.keycloak.component.ComponentModel) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 53 with ComponentRepresentation

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");
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) UserStorageProvider(org.keycloak.storage.UserStorageProvider) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ExportImportManager(org.keycloak.exportimport.ExportImportManager) NotFoundException(javax.ws.rs.NotFoundException) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 54 with ComponentRepresentation

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);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) GroupStorageProvider(org.keycloak.storage.group.GroupStorageProvider) Before(org.junit.Before)

Example 55 with ComponentRepresentation

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);
}
Also used : UserModel(org.keycloak.models.UserModel) ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) UserStorageSyncManager(org.keycloak.services.managers.UserStorageSyncManager) SynchronizationResult(org.keycloak.storage.user.SynchronizationResult) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory) Test(org.junit.Test)

Aggregations

ComponentRepresentation (org.keycloak.representations.idm.ComponentRepresentation)120 Test (org.junit.Test)56 Response (javax.ws.rs.core.Response)44 UserStorageProvider (org.keycloak.storage.UserStorageProvider)22 KeyProvider (org.keycloak.keys.KeyProvider)17 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)13 Before (org.junit.Before)12 KeysMetadataRepresentation (org.keycloak.representations.idm.KeysMetadataRepresentation)12 RealmModel (org.keycloak.models.RealmModel)10 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)10 KeyPair (java.security.KeyPair)9 UserModel (org.keycloak.models.UserModel)9 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)8 RealmResource (org.keycloak.admin.client.resource.RealmResource)7 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)7 ComponentModel (org.keycloak.component.ComponentModel)7 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)7 OIDCClientRepresentation (org.keycloak.representations.oidc.OIDCClientRepresentation)6 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)6 List (java.util.List)5