Search in sources :

Example 21 with ClientRegistrationException

use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.

the class FAPI1Test method testFAPIBaselineOIDCClientRegistration.

@Test
public void testFAPIBaselineOIDCClientRegistration() throws Exception {
    setupPolicyFAPIBaselineForAllClient();
    // Try to register client with clientIdAndSecret - should fail
    try {
        createClientDynamically(generateSuffixedName("foo"), (OIDCClientRepresentation clientRep) -> {
            clientRep.setTokenEndpointAuthMethod(OIDCLoginProtocol.CLIENT_SECRET_BASIC);
        });
        fail();
    } catch (ClientRegistrationException e) {
        assertEquals(ERR_MSG_CLIENT_REG_FAIL, e.getMessage());
    }
    // Try to register client with "client-jwt" - should pass
    String clientUUID = createClientDynamically("client-jwt", (OIDCClientRepresentation clientRep) -> {
        clientRep.setTokenEndpointAuthMethod(OIDCLoginProtocol.PRIVATE_KEY_JWT);
        clientRep.setJwksUri("https://foo");
    });
    ClientRepresentation client = getClientByAdmin(clientUUID);
    Assert.assertEquals(JWTClientAuthenticator.PROVIDER_ID, client.getClientAuthenticatorType());
    Assert.assertFalse(client.isFullScopeAllowed());
    // Set new initialToken for register new clients
    setInitialAccessTokenForDynamicClientRegistration();
    // Try to register client with "client-secret-jwt" - should pass
    clientUUID = createClientDynamically("client-secret-jwt", (OIDCClientRepresentation clientRep) -> {
        clientRep.setTokenEndpointAuthMethod(OIDCLoginProtocol.CLIENT_SECRET_JWT);
    });
    client = getClientByAdmin(clientUUID);
    Assert.assertEquals(JWTClientSecretAuthenticator.PROVIDER_ID, client.getClientAuthenticatorType());
    // Set new initialToken for register new clients
    setInitialAccessTokenForDynamicClientRegistration();
    // Try to register client with "client-x509" - should pass
    clientUUID = createClientDynamically("client-x509", (OIDCClientRepresentation clientRep) -> {
        clientRep.setTokenEndpointAuthMethod(OIDCLoginProtocol.TLS_CLIENT_AUTH);
    });
    client = getClientByAdmin(clientUUID);
    Assert.assertEquals(X509ClientAuthenticator.PROVIDER_ID, client.getClientAuthenticatorType());
    // Check the Consent is enabled, PKCS set to S256
    Assert.assertTrue(client.isConsentRequired());
    Assert.assertEquals(OAuth2Constants.PKCE_METHOD_S256, OIDCAdvancedConfigWrapper.fromClientRepresentation(client).getPkceCodeChallengeMethod());
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 22 with ClientRegistrationException

use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.

the class InitialAccessTokenTest method create.

@Test
public void create() throws ClientRegistrationException, InterruptedException {
    ClientInitialAccessPresentation response = resource.create(new ClientInitialAccessCreatePresentation());
    reg.auth(Auth.token(response));
    ClientRepresentation rep = new ClientRepresentation();
    setTimeOffset(10);
    ClientRepresentation created = reg.create(rep);
    Assert.assertNotNull(created);
    try {
        reg.create(rep);
        Assert.fail("Expected exception");
    } catch (ClientRegistrationException e) {
        assertEquals(401, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
    }
}
Also used : ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 23 with ClientRegistrationException

use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.

the class InitialAccessTokenTest method createExpired.

@Test
public void createExpired() throws ClientRegistrationException, InterruptedException {
    ClientInitialAccessPresentation response = resource.create(new ClientInitialAccessCreatePresentation(1, 1));
    reg.auth(Auth.token(response));
    ClientRepresentation rep = new ClientRepresentation();
    setTimeOffset(10);
    try {
        reg.create(rep);
        Assert.fail("Expected exception");
    } catch (ClientRegistrationException e) {
        assertEquals(401, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
    }
}
Also used : ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 24 with ClientRegistrationException

use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.

the class InitialAccessTokenTest method createDeleted.

@Test
public void createDeleted() throws ClientRegistrationException, InterruptedException {
    ClientInitialAccessPresentation response = resource.create(new ClientInitialAccessCreatePresentation());
    reg.auth(Auth.token(response));
    resource.delete(response.getId());
    ClientRepresentation rep = new ClientRepresentation();
    try {
        reg.create(rep);
        Assert.fail("Expected exception");
    } catch (ClientRegistrationException e) {
        assertEquals(401, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
    }
}
Also used : ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 25 with ClientRegistrationException

use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.

the class OIDCClientRegistrationTest method testCIBASettings.

@Test
public void testCIBASettings() throws Exception {
    OIDCClientRepresentation clientRep = null;
    OIDCClientRepresentation response = null;
    clientRep = createRep();
    clientRep.setBackchannelTokenDeliveryMode("poll");
    response = reg.oidc().create(clientRep);
    Assert.assertEquals("poll", response.getBackchannelTokenDeliveryMode());
    // Test Keycloak representation
    ClientRepresentation kcClient = getClient(response.getClientId());
    Assert.assertEquals("poll", kcClient.getAttributes().get(CibaConfig.CIBA_BACKCHANNEL_TOKEN_DELIVERY_MODE_PER_CLIENT));
    // Create with ping mode (failes due missing clientNotificationEndpoint)
    clientRep.setBackchannelTokenDeliveryMode("ping");
    try {
        reg.oidc().create(clientRep);
        fail();
    } catch (ClientRegistrationException e) {
        assertEquals(ERR_MSG_CLIENT_REG_FAIL, e.getMessage());
    }
    // Create with ping mode (success)
    clientRep.setBackchannelClientNotificationEndpoint("https://foo/bar");
    response = reg.oidc().create(clientRep);
    Assert.assertEquals("ping", response.getBackchannelTokenDeliveryMode());
    Assert.assertEquals("https://foo/bar", response.getBackchannelClientNotificationEndpoint());
    // Create with push mode (fails)
    clientRep.setBackchannelTokenDeliveryMode("push");
    try {
        reg.oidc().create(clientRep);
        fail();
    } catch (ClientRegistrationException e) {
        assertEquals(ERR_MSG_CLIENT_REG_FAIL, e.getMessage());
    }
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Aggregations

ClientRegistrationException (org.keycloak.client.registration.ClientRegistrationException)29 Test (org.junit.Test)22 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)20 OIDCClientRepresentation (org.keycloak.representations.oidc.OIDCClientRepresentation)11 ClientInitialAccessCreatePresentation (org.keycloak.representations.idm.ClientInitialAccessCreatePresentation)7 ClientInitialAccessPresentation (org.keycloak.representations.idm.ClientInitialAccessPresentation)7 ClientRegistration (org.keycloak.client.registration.ClientRegistration)6 IOException (java.io.IOException)5 HttpErrorException (org.keycloak.client.registration.HttpErrorException)5 ClientPolicyException (org.keycloak.services.clientpolicy.ClientPolicyException)5 ClientPoliciesBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPoliciesBuilder)5 ClientPolicyBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPolicyBuilder)5 ClientProfileBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientProfileBuilder)5 ClientProfilesBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientProfilesBuilder)5 Collectors (java.util.stream.Collectors)3 BadRequestException (javax.ws.rs.BadRequestException)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 OAuthErrorException (org.keycloak.OAuthErrorException)3 List (java.util.List)2