Search in sources :

Example 26 with ClientRegistrationException

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

the class OIDCClientRegistrationTest method testClientWithNotDefinedScope.

@Test
public void testClientWithNotDefinedScope() throws Exception {
    OIDCClientRepresentation clientRep = null;
    OIDCClientRepresentation response = null;
    String clientScope = "notdefinedscope address";
    clientRep = createRep();
    clientRep.setScope(clientScope);
    try {
        response = reg.oidc().create(clientRep);
        fail("Expected 403");
    } catch (ClientRegistrationException e) {
        assertEquals(403, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
    }
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) Test(org.junit.Test)

Example 27 with ClientRegistrationException

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

the class RegistrationAccessTokenTest method assertRead.

private ClientRepresentation assertRead(String id, String registrationAccess, boolean expectSuccess) throws ClientRegistrationException {
    if (expectSuccess) {
        reg.auth(Auth.token(registrationAccess));
        ClientRepresentation rep = reg.get(id);
        assertNotNull(rep);
        return rep;
    } else {
        reg.auth(Auth.token(registrationAccess));
        try {
            reg.get(client.getClientId());
            fail("Expected 403");
        } catch (Exception e) {
            assertEquals(401, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
        }
    }
    return null;
}
Also used : ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) HttpErrorException(org.keycloak.client.registration.HttpErrorException) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Example 28 with ClientRegistrationException

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

the class InitialAccessTokenResourceTest method testPeriodicExpiration.

@Test
public void testPeriodicExpiration() throws ClientRegistrationException, InterruptedException {
    ClientInitialAccessPresentation response1 = resource.create(new ClientInitialAccessCreatePresentation(1, 1));
    ClientInitialAccessPresentation response2 = resource.create(new ClientInitialAccessCreatePresentation(1000, 1));
    ClientInitialAccessPresentation response3 = resource.create(new ClientInitialAccessCreatePresentation(1000, 0));
    ClientInitialAccessPresentation response4 = resource.create(new ClientInitialAccessCreatePresentation(0, 1));
    List<ClientInitialAccessPresentation> list = resource.list();
    assertEquals(4, list.size());
    setTimeOffset(10);
    testingClient.testing().removeExpired(REALM_NAME);
    list = resource.list();
    assertEquals(2, list.size());
    List<String> remainingIds = list.stream().map(initialAccessPresentation -> initialAccessPresentation.getId()).collect(Collectors.toList());
    Assert.assertNames(remainingIds, response2.getId(), response4.getId());
    setTimeOffset(2000);
    testingClient.testing().removeExpired(REALM_NAME);
    list = resource.list();
    assertEquals(1, list.size());
    Assert.assertEquals(list.get(0).getId(), response4.getId());
    // Cleanup
    realm.clientInitialAccess().delete(response4.getId());
}
Also used : OperationType(org.keycloak.events.admin.OperationType) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) ResourceType(org.keycloak.events.admin.ResourceType) Assert(org.keycloak.testsuite.Assert) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) AdminEventPaths(org.keycloak.testsuite.util.AdminEventPaths) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) ClientInitialAccessResource(org.keycloak.admin.client.resource.ClientInitialAccessResource) Collectors(java.util.stream.Collectors) Assert.assertThat(org.junit.Assert.assertThat) ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) AuthServer(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer) Time(org.keycloak.common.util.Time) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ClientInitialAccessCreatePresentation(org.keycloak.representations.idm.ClientInitialAccessCreatePresentation) ClientInitialAccessPresentation(org.keycloak.representations.idm.ClientInitialAccessPresentation) Test(org.junit.Test)

Example 29 with ClientRegistrationException

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

the class TestsHelper method createClient.

public static String createClient(ClientRepresentation clientRepresentation) {
    ClientRegistration reg = ClientRegistration.create().url(keycloakBaseUrl, testRealm).build();
    reg.auth(Auth.token(initialAccessCode));
    try {
        clientRepresentation = reg.create(clientRepresentation);
        registrationAccessCode = clientRepresentation.getRegistrationAccessToken();
        ObjectMapper mapper = new ObjectMapper();
        reg.auth(Auth.token(registrationAccessCode));
        clientConfiguration = mapper.writeValueAsString(reg.getAdapterConfig(clientRepresentation.getClientId()));
    } catch (ClientRegistrationException e) {
        e.printStackTrace();
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    return clientConfiguration;
}
Also used : ClientRegistration(org.keycloak.client.registration.ClientRegistration) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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