Search in sources :

Example 1 with ComponentResource

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) Logger(org.jboss.logging.Logger) ComponentResource(org.keycloak.admin.client.resource.ComponentResource) ComponentsResource(org.keycloak.admin.client.resource.ComponentsResource)

Example 2 with ComponentResource

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);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) ComponentResource(org.keycloak.admin.client.resource.ComponentResource) BadRequestException(javax.ws.rs.BadRequestException) LDAPProvidersIntegrationTest(org.keycloak.testsuite.federation.ldap.LDAPProvidersIntegrationTest) Test(org.junit.Test)

Example 3 with ComponentResource

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);
    }
}
Also used : KeyPairGenerator(java.security.KeyPairGenerator) X509Certificate(java.security.cert.X509Certificate) KeyPair(java.security.KeyPair) ComponentResource(org.keycloak.admin.client.resource.ComponentResource) Attributes(org.keycloak.keys.Attributes) ImportedRsaKeyProviderFactory(org.keycloak.keys.ImportedRsaKeyProviderFactory) RealmResource(org.keycloak.admin.client.resource.RealmResource) CertificateUtils(org.keycloak.common.util.CertificateUtils) PemUtils(org.keycloak.common.util.PemUtils) KeyType(org.keycloak.crypto.KeyType) Collectors(java.util.stream.Collectors) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) Base64(org.keycloak.common.util.Base64) ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) List(java.util.List) Certificate(java.security.cert.Certificate) Response(javax.ws.rs.core.Response) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyProvider(org.keycloak.keys.KeyProvider) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ApiUtil(org.keycloak.testsuite.admin.ApiUtil) ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) ComponentResource(org.keycloak.admin.client.resource.ComponentResource)

Example 4 with ComponentResource

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));
}
Also used : LDAPStorageMapper(org.keycloak.storage.ldap.mappers.LDAPStorageMapper) ComponentResource(org.keycloak.admin.client.resource.ComponentResource) ComponentTypeRepresentation(org.keycloak.representations.idm.ComponentTypeRepresentation)

Example 5 with ComponentResource

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");
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) ComponentResource(org.keycloak.admin.client.resource.ComponentResource) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Aggregations

ComponentResource (org.keycloak.admin.client.resource.ComponentResource)5 ComponentRepresentation (org.keycloak.representations.idm.ComponentRepresentation)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Certificate (java.security.cert.Certificate)1 X509Certificate (java.security.cert.X509Certificate)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 BadRequestException (javax.ws.rs.BadRequestException)1 Logger (org.jboss.logging.Logger)1 ComponentsResource (org.keycloak.admin.client.resource.ComponentsResource)1 RealmResource (org.keycloak.admin.client.resource.RealmResource)1 Base64 (org.keycloak.common.util.Base64)1 CertificateUtils (org.keycloak.common.util.CertificateUtils)1 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)1 PemUtils (org.keycloak.common.util.PemUtils)1 KeyType (org.keycloak.crypto.KeyType)1