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());
}
}
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);
}
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) {
}
}
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();
}
}
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;
}
Aggregations