use of org.keycloak.client.registration.HttpErrorException in project keycloak by keycloak.
the class ClientRegistrationTester method main.
public static void main(String[] args) throws ClientRegistrationException {
ClientRepresentation rep = createRep1();
ClientRegistration reg = ClientRegistration.create().url("http://localhost:8081/auth", "test").build();
try {
ClientRepresentation createdRep = reg.create(rep);
System.out.println("Created client: " + createdRep.getClientId());
} catch (ClientRegistrationException ex) {
HttpErrorException httpEx = (HttpErrorException) ex.getCause();
System.err.println("HttpException when registering client. Status=" + httpEx.getStatusLine().getStatusCode() + ", Details=" + httpEx.getErrorResponse());
}
}
use of org.keycloak.client.registration.HttpErrorException 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.HttpErrorException 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;
}
Aggregations