use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class ClientRegistrationTest method registerOrUpdateClientExpectingValidationErrors.
private void registerOrUpdateClientExpectingValidationErrors(ClientRepresentation rep, boolean register, boolean redirectUris, String... expectedErrors) {
HttpErrorException errorException = null;
try {
if (register) {
registerClient(rep);
} else {
reg.update(rep);
}
fail("Expected exception");
} catch (ClientRegistrationException e) {
errorException = (HttpErrorException) e.getCause();
}
expectedErrors = Arrays.stream(expectedErrors).filter(Objects::nonNull).toArray(String[]::new);
assertEquals(errorException.getStatusLine().getStatusCode(), 400);
OAuth2ErrorRepresentation errorRep;
try {
errorRep = JsonSerialization.readValue(errorException.getErrorResponse(), OAuth2ErrorRepresentation.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
List<String> actualErrors = asList(errorRep.getErrorDescription().split("; "));
assertThat(actualErrors, containsInAnyOrder(expectedErrors));
assertEquals(redirectUris ? INVALID_REDIRECT_URI : INVALID_CLIENT_METADATA, errorRep.getError());
}
use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class ClientRegistrationTest method deleteClientAsAdminWithNoAccess.
@Test
public void deleteClientAsAdminWithNoAccess() throws ClientRegistrationException {
authManageClients();
ClientRepresentation client = registerClient();
try {
authNoAccess();
deleteClient(client);
fail("Expected 403");
} catch (ClientRegistrationException e) {
assertEquals(403, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
}
}
use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class ClientRegistrationTest method updateClientNotFound.
@Test
public void updateClientNotFound() throws ClientRegistrationException {
authManageClients();
try {
ClientRepresentation client = new ClientRepresentation();
client.setClientId("invalid");
reg.update(client);
fail("Expected 404");
} catch (ClientRegistrationException e) {
assertEquals(404, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
}
}
use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class ClientRegistrationTest method testClientUriValidation.
private void testClientUriValidation(boolean register, String expectedRootUrlError, String expectedBaseUrlError, String expectedBackchannelLogoutUrlError, String expectedRedirectUrisError, String... testUrls) {
ClientRepresentation rep;
if (register) {
authCreateClients();
rep = buildClient();
} else {
try {
registerClientAsAdmin();
rep = reg.get(CLIENT_ID);
} catch (ClientRegistrationException e) {
throw new RuntimeException(e);
}
}
for (String testUrl : testUrls) {
if (expectedRootUrlError != null) {
rep.setRootUrl(testUrl);
registerOrUpdateClientExpectingValidationErrors(rep, register, false, expectedRootUrlError);
}
rep.setRootUrl(null);
if (expectedBaseUrlError != null) {
rep.setBaseUrl(testUrl);
registerOrUpdateClientExpectingValidationErrors(rep, register, false, expectedBaseUrlError);
}
rep.setBaseUrl(null);
if (expectedBackchannelLogoutUrlError != null) {
OIDCAdvancedConfigWrapper.fromClientRepresentation(rep).setBackchannelLogoutUrl(testUrl);
registerOrUpdateClientExpectingValidationErrors(rep, register, false, expectedBackchannelLogoutUrlError);
}
OIDCAdvancedConfigWrapper.fromClientRepresentation(rep).setBackchannelLogoutUrl(null);
if (expectedRedirectUrisError != null) {
rep.setRedirectUris(Collections.singletonList(testUrl));
registerOrUpdateClientExpectingValidationErrors(rep, register, true, expectedRedirectUrisError);
}
rep.setRedirectUris(null);
if (expectedRootUrlError != null)
rep.setRootUrl(testUrl);
if (expectedBaseUrlError != null)
rep.setBaseUrl(testUrl);
if (expectedRedirectUrisError != null)
rep.setRedirectUris(Collections.singletonList(testUrl));
registerOrUpdateClientExpectingValidationErrors(rep, register, expectedRedirectUrisError != null, expectedRootUrlError, expectedBaseUrlError, expectedRedirectUrisError);
rep.setRootUrl(null);
rep.setBaseUrl(null);
rep.setRedirectUris(null);
}
}
use of org.keycloak.client.registration.ClientRegistrationException in project keycloak by keycloak.
the class ClientRegistrationTest method registerClientAsAdminWithoutScope.
@Test
public void registerClientAsAdminWithoutScope() throws ClientRegistrationException {
Set<String> realmDefaultClientScopes = new HashSet<>(adminClient.realm(REALM_NAME).getDefaultDefaultClientScopes().stream().filter(scope -> Objects.equals(scope.getProtocol(), OIDCLoginProtocol.LOGIN_PROTOCOL)).map(i -> i.getName()).collect(Collectors.toList()));
Set<String> realmOptionalClientScopes = new HashSet<>(adminClient.realm(REALM_NAME).getDefaultOptionalClientScopes().stream().filter(scope -> Objects.equals(scope.getProtocol(), OIDCLoginProtocol.LOGIN_PROTOCOL)).map(i -> i.getName()).collect(Collectors.toList()));
authManageClients();
ClientRepresentation client = new ClientRepresentation();
client.setClientId(CLIENT_ID);
client.setSecret(CLIENT_SECRET);
ClientRepresentation createdClient = reg.create(client);
assertEquals(CLIENT_ID, createdClient.getClientId());
client = adminClient.realm(REALM_NAME).clients().get(createdClient.getId()).toRepresentation();
assertEquals(CLIENT_ID, client.getClientId());
// Remove this client after test
getCleanup().addClientUuid(createdClient.getId());
assertTrue(realmDefaultClientScopes.equals(new HashSet<>(client.getDefaultClientScopes())));
assertTrue(realmOptionalClientScopes.equals(new HashSet<>(client.getOptionalClientScopes())));
}
Aggregations