Search in sources :

Example 11 with ClientRegistrationException

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

the class InitialAccessTokenTest method createMultiple.

@Test
public void createMultiple() throws ClientRegistrationException {
    ClientInitialAccessPresentation response = resource.create(new ClientInitialAccessCreatePresentation(0, 2));
    reg.auth(Auth.token(response));
    ClientRepresentation rep = new ClientRepresentation();
    ClientRepresentation created = reg.create(rep);
    Assert.assertNotNull(created);
    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 12 with ClientRegistrationException

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

the class OIDCClientRegistrationTest method testDefaultAcrValues.

@Test
public void testDefaultAcrValues() throws Exception {
    // Set realm acr-to-loa mapping
    RealmRepresentation realmRep = adminClient.realm("test").toRepresentation();
    Map<String, Integer> acrLoaMap = new HashMap<>();
    acrLoaMap.put("copper", 0);
    acrLoaMap.put("silver", 1);
    acrLoaMap.put("gold", 2);
    realmRep.getAttributes().put(Constants.ACR_LOA_MAP, JsonSerialization.writeValueAsString(acrLoaMap));
    adminClient.realm("test").update(realmRep);
    OIDCClientRepresentation clientRep = createRep();
    clientRep.setDefaultAcrValues(Arrays.asList("silver", "foo"));
    try {
        OIDCClientRepresentation response = reg.oidc().create(clientRep);
        fail("Expected 400");
    } catch (ClientRegistrationException e) {
        assertEquals(400, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
    }
    clientRep.setDefaultAcrValues(Arrays.asList("silver", "gold"));
    OIDCClientRepresentation response = reg.oidc().create(clientRep);
    Assert.assertNames(response.getDefaultAcrValues(), "silver", "gold");
    // Test Keycloak representation
    ClientRepresentation kcClient = getClient(response.getClientId());
    OIDCAdvancedConfigWrapper config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
    Assert.assertNames(config.getAttributeMultivalued(Constants.DEFAULT_ACR_VALUES), "silver", "gold");
    // Revert realm acr-to-loa mappings
    realmRep.getAttributes().remove(Constants.ACR_LOA_MAP);
    adminClient.realm("test").update(realmRep);
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) OIDCAdvancedConfigWrapper(org.keycloak.protocol.oidc.OIDCAdvancedConfigWrapper) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 13 with ClientRegistrationException

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

the class OIDCClientRegistrationTest method updateClientError.

@Test
public void updateClientError() throws ClientRegistrationException {
    try {
        OIDCClientRepresentation response = create();
        reg.auth(Auth.token(response));
        response.setResponseTypes(Arrays.asList("code", "tokenn"));
        reg.oidc().update(response);
        fail("Not expected to end with success");
    } catch (ClientRegistrationException cre) {
    }
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) Test(org.junit.Test)

Example 14 with ClientRegistrationException

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

the class TestsHelper method deleteClient.

public static void deleteClient(String clientId) {
    ClientRegistration reg = ClientRegistration.create().url(keycloakBaseUrl, testRealm).build();
    try {
        reg.auth(Auth.token(registrationAccessCode));
        reg.delete(clientId);
    } catch (ClientRegistrationException e) {
        e.printStackTrace();
    }
}
Also used : ClientRegistration(org.keycloak.client.registration.ClientRegistration) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException)

Example 15 with ClientRegistrationException

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

the class FluentTestsHelper method deleteClient.

/**
 * Deletes a client previously created by this helper. This will throw an error if you try to delete an
 * arbitrary client.
 *
 * @param clientId Client id to be deleted.
 * @return <code>this</code>
 * @throws ClientRegistrationException Thrown when client registration error occurs.
 */
public FluentTestsHelper deleteClient(String clientId) throws ClientRegistrationException {
    assert isInitialized;
    ClientData clientData = createdClients.get(clientId);
    if (clientData == null) {
        throw new ClientRegistrationException("This client wasn't created by this helper!");
    }
    ClientRegistration reg = ClientRegistration.create().url(keycloakBaseUrl, testRealm).build();
    reg.auth(Auth.token(clientData.getRegistrationCode()));
    reg.delete(clientId);
    return this;
}
Also used : ClientRegistration(org.keycloak.client.registration.ClientRegistration) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException)

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