Search in sources :

Example 41 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class UserStorageTest method testRegistration.

@Test
public void testRegistration() {
    UserRepresentation memuser = new UserRepresentation();
    memuser.setUsername("memuser");
    String uid = ApiUtil.createUserAndResetPasswordWithAdminClient(testRealmResource(), memuser, "password");
    loginSuccessAndLogout("memuser", "password");
    loginSuccessAndLogout("memuser", "password");
    loginSuccessAndLogout("memuser", "password");
    memuser = user(uid).toRepresentation();
    assertNotNull(memuser);
    assertNotNull(memuser.getOrigin());
    ComponentRepresentation origin = testRealmResource().components().component(memuser.getOrigin()).toRepresentation();
    Assert.assertEquals("memory", origin.getName());
    testRealmResource().users().get(memuser.getId()).remove();
    try {
        // provider doesn't implement UserQueryProvider --> have to lookup by uid
        user(uid).toRepresentation();
        fail("`memuser` wasn't removed");
    } catch (NotFoundException nfe) {
    // expected
    }
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) NotFoundException(javax.ws.rs.NotFoundException) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) ModelTest(org.keycloak.testsuite.arquillian.annotation.ModelTest) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 42 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class ComponentResource method getComponent.

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public ComponentRepresentation getComponent(@PathParam("id") String id) {
    auth.realm().requireViewRealm();
    ComponentModel model = realm.getComponent(id);
    if (model == null) {
        throw new NotFoundException("Could not find component");
    }
    ComponentRepresentation rep = ModelToRepresentation.toRepresentation(session, model, false);
    return rep;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) ComponentModel(org.keycloak.component.ComponentModel) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 43 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class TokenSignatureUtil method createKeyRep.

private static ComponentRepresentation createKeyRep(String name, String providerId) {
    ComponentRepresentation rep = new ComponentRepresentation();
    rep.setName(name);
    rep.setParentId(TEST_REALM_NAME);
    rep.setProviderId(providerId);
    rep.setProviderType(KeyProvider.class.getName());
    rep.setConfig(new MultivaluedHashMap<>());
    return rep;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) KeyProvider(org.keycloak.keys.KeyProvider)

Example 44 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class AbstractAdvancedBrokerTest method testWithLinkedFederationProvider.

/**
 * Refers to in old test suite: org.keycloak.testsuite.broker.AbstractKeycloakIdentityProviderTest#testWithLinkedFederationProvider
 */
@Test
public void testWithLinkedFederationProvider() {
    try {
        updateExecutions(AbstractBrokerTest::disableUpdateProfileOnFirstLogin);
        ComponentRepresentation component = new ComponentRepresentation();
        component.setId(DummyUserFederationProviderFactory.PROVIDER_NAME);
        component.setName(DummyUserFederationProviderFactory.PROVIDER_NAME);
        component.setProviderId(DummyUserFederationProviderFactory.PROVIDER_NAME);
        component.setProviderType(UserStorageProvider.class.getName());
        adminClient.realm(bc.consumerRealmName()).components().add(component);
        createUser(bc.providerRealmName(), "test-user", "password", "FirstName", "LastName", "test-user@localhost.com");
        driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
        loginPage.clickSocial(bc.getIDPAlias());
        loginPage.login("test-user", "password");
        waitForAccountManagementTitle();
        accountUpdateProfilePage.assertCurrent();
        accountPage.password();
        accountPasswordPage.changePassword("bad", "new-password", "new-password");
        assertEquals("Invalid existing password.", accountPasswordPage.getError());
        accountPasswordPage.changePassword("secret", "new-password", "new-password");
        assertEquals("Your password has been updated.", accountUpdateProfilePage.getSuccess());
        logoutFromRealm(getProviderRoot(), bc.providerRealmName());
        logoutFromRealm(getConsumerRoot(), bc.consumerRealmName());
        createUser(bc.providerRealmName(), "test-user-noemail", "password", "FirstName", "LastName", "test-user-noemail@localhost.com");
        driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
        loginPage.clickSocial(bc.getIDPAlias());
        loginPage.login("test-user-noemail", "password");
        waitForAccountManagementTitle();
        accountUpdateProfilePage.assertCurrent();
        accountPage.password();
        accountPasswordPage.changePassword("new-password", "new-password");
        assertEquals("Your password has been updated.", accountUpdateProfilePage.getSuccess());
    } finally {
        removeUserByUsername(adminClient.realm(bc.consumerRealmName()), "test-user");
        removeUserByUsername(adminClient.realm(bc.consumerRealmName()), "test-user-noemail");
    }
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) UserStorageProvider(org.keycloak.storage.UserStorageProvider) Test(org.junit.Test)

Example 45 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class KcOIDCBrokerWithSignatureTest method rotateKeys.

private void rotateKeys() {
    String activeKid = providerRealm().keys().getKeyMetadata().getActive().get(Algorithm.RS256);
    // Rotate public keys on the parent broker
    String realmId = providerRealm().toRepresentation().getId();
    ComponentRepresentation keys = new ComponentRepresentation();
    keys.setName("generated");
    keys.setProviderType(KeyProvider.class.getName());
    keys.setProviderId("rsa-generated");
    keys.setParentId(realmId);
    keys.setConfig(new MultivaluedHashMap<>());
    keys.getConfig().putSingle("priority", Long.toString(System.currentTimeMillis()));
    Response response = providerRealm().components().add(keys);
    assertEquals(201, response.getStatus());
    response.close();
    String updatedActiveKid = providerRealm().keys().getKeyMetadata().getActive().get(Algorithm.RS256);
    assertNotEquals(activeKid, updatedActiveKid);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) KeyProvider(org.keycloak.keys.KeyProvider) Response(javax.ws.rs.core.Response)

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