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
}
}
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;
}
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;
}
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");
}
}
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);
}
Aggregations