use of org.keycloak.admin.client.resource.ComponentResource in project keycloak by keycloak.
the class Creator method create.
public static Creator<ComponentResource> create(RealmResource realmResource, ComponentRepresentation rep) {
final ComponentsResource components = realmResource.components();
try (Response response = components.add(rep)) {
String createdId = getCreatedId(response);
final ComponentResource r = components.component(createdId);
LOG.debugf("Created component ID %s", createdId);
return new Creator(createdId, r, r::remove);
}
}
use of org.keycloak.admin.client.resource.ComponentResource in project keycloak by keycloak.
the class LDAPProvidersIntegrationNoImportTest method testUnsynced.
@Test
@Override
public // Unsynced mode doesn't have much sense in no-import. So it is not allowed at the configuration level
void testUnsynced() throws Exception {
ComponentResource ldapProviderResource = testRealm().components().component(ldapModelId);
ComponentRepresentation ldapProviderRep = ldapProviderResource.toRepresentation();
String currentEditMode = ldapProviderRep.getConfig().getFirst(LDAPConstants.EDIT_MODE);
Assert.assertEquals(UserStorageProvider.EditMode.WRITABLE.toString(), currentEditMode);
// Try update editMode to UNSYNCED. It should not work as UNSYNCED with no-import is not allowed
ldapProviderRep.getConfig().putSingle(LDAPConstants.EDIT_MODE, UserStorageProvider.EditMode.UNSYNCED.toString());
try {
ldapProviderResource.update(ldapProviderRep);
Assert.fail("Not expected to successfully update provider");
} catch (BadRequestException bre) {
// Expected
}
// Try to set editMode to WRITABLE should work
ldapProviderRep.getConfig().putSingle(LDAPConstants.EDIT_MODE, currentEditMode);
ldapProviderResource.update(ldapProviderRep);
}
use of org.keycloak.admin.client.resource.ComponentResource in project keycloak by keycloak.
the class RealmManager method deactivateOtherRsaKeys.
private void deactivateOtherRsaKeys(String providerId) {
List<String> otherRsaKeyProviderIds = realm.keys().getKeyMetadata().getKeys().stream().filter(key -> KeyType.RSA.equals(key.getType()) && !providerId.equals(key.getProviderId())).map(key -> key.getProviderId()).collect(Collectors.toList());
for (String otherRsaKeyProviderId : otherRsaKeyProviderIds) {
ComponentResource componentResource = realm.components().component(otherRsaKeyProviderId);
ComponentRepresentation componentRepresentation = componentResource.toRepresentation();
componentRepresentation.getConfig().putSingle(Attributes.ACTIVE_KEY, "false");
componentResource.update(componentRepresentation);
}
}
use of org.keycloak.admin.client.resource.ComponentResource in project keycloak by keycloak.
the class UserStorageRestTest method findMapperTypeConfiguration.
private ComponentTypeRepresentation findMapperTypeConfiguration(String ldapModelId, String mapperProviderId) {
ComponentResource ldapProvider = realm.components().component(ldapModelId);
List<ComponentTypeRepresentation> componentTypes = ldapProvider.getSubcomponentConfig(LDAPStorageMapper.class.getName());
return componentTypes.stream().filter(componentType -> mapperProviderId.equals(componentType.getId())).findFirst().orElseThrow(() -> new IllegalStateException("Not able to find mapper with provider id: " + mapperProviderId));
}
use of org.keycloak.admin.client.resource.ComponentResource in project keycloak by keycloak.
the class OpenshiftClientStorageTest method testCodeGrantFlowWithUserConsent.
@Test
public void testCodeGrantFlowWithUserConsent() {
String clientId = "system:serviceaccount:default:sa-oauth-redirect-uri";
testCodeGrantFlow(clientId, "http://localhost:8180/auth/realms/master/app/auth", () -> assertSuccessfulResponseWithConsent(clientId), "user:info user:check-access");
ComponentResource component = testRealm().components().component(clientStorageId);
ComponentRepresentation representation = component.toRepresentation();
representation.getConfig().put(OpenshiftClientStorageProviderFactory.CONFIG_PROPERTY_REQUIRE_USER_CONSENT, Arrays.asList("false"));
component.update(representation);
testCodeGrantFlow(clientId, "http://localhost:8180/auth/realms/master/app/auth", () -> assertSuccessfulResponseWithoutConsent(clientId), "user:info user:check-access");
representation.getConfig().put(OpenshiftClientStorageProviderFactory.CONFIG_PROPERTY_REQUIRE_USER_CONSENT, Arrays.asList("true"));
component.update(representation);
testCodeGrantFlow(clientId, "http://localhost:8180/auth/realms/master/app/auth", () -> assertSuccessfulResponseWithoutConsent(clientId, Details.CONSENT_VALUE_PERSISTED_CONSENT), "user:info user:check-access");
testRealm().users().get(userId).revokeConsent(clientId);
testCodeGrantFlow(clientId, "http://localhost:8180/auth/realms/master/app/auth", () -> assertSuccessfulResponseWithConsent(clientId), "user:info user:check-access");
}
Aggregations