stream.reset(); if (Response.Status.FORBIDDEN.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token, status is FORBIDDEN"; } else if (Response.Status.UNAUTHORIZED.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token, status is UNAUTHORIZED"; } else if (Response.Status.BAD_REQUEST.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token, status is BAD_REQUEST. Response data: " + getResponseData(r); } else if (Response.Status.NOT_FOUND.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token, status is NOT_FOUND."; } else if (!Response.Status.OK.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token. Response status is " + response.getResponseStatus() + ". Response data: " + getResponseData(r);
stream.reset(); if (Response.Status.FORBIDDEN.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token, status is FORBIDDEN"; } else if (Response.Status.UNAUTHORIZED.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token, status is UNAUTHORIZED"; } else if (Response.Status.BAD_REQUEST.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token, status is BAD_REQUEST. Response data: " + getResponseData(r); } else if (Response.Status.NOT_FOUND.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token, status is NOT_FOUND."; } else if (!Response.Status.OK.equals(response.getResponseStatus())) { error = "Error handling the Keycloak token. Response status is " + response.getResponseStatus() + ". Response data: " + getResponseData(r);
protected ClientResponseFailure mockForbiddenResponse() { ClientResponseFailure error = mock(ClientResponseFailure.class); ClientResponse response = mock(ClientResponse.class); Response.Status responseStatus = Response.Status.FORBIDDEN; when(error.getResponse()).thenReturn(response); when(response.getResponseStatus()).thenReturn(responseStatus); return error; }
protected ClientResponseFailure mockForbiddenResponse() { ClientResponseFailure error = mock(ClientResponseFailure.class); ClientResponse response = mock(ClientResponse.class); Response.Status responseStatus = Response.Status.FORBIDDEN; when(error.getResponse()).thenReturn(response); when(response.getResponseStatus()).thenReturn(responseStatus); return error; }
protected void consumeRealm(final Consumer<RealmResource> consumer) { try { consumer.accept(getRealmResource()); } catch (ClientResponseFailure e) { if (STATUS_NOT_AUTHORIZED == e.getResponse().getResponseStatus().getStatusCode()) { throw new RealmManagementNotAuthorizedException(getKeyCloakInstance().getRealm()); } else { throw new SecurityManagementException(e); } } }
protected void consumeRealm(final Consumer<RealmResource> consumer) { try { consumer.accept(getRealmResource()); } catch (ClientResponseFailure e) { if (STATUS_NOT_AUTHORIZED == e.getResponse().getResponseStatus().getStatusCode()) { throw new RealmManagementNotAuthorizedException(getKeyCloakInstance().getRealm()); } else { throw new SecurityManagementException(e); } } }
@Override public void handle(final ClientResponse<?> response) throws RuntimeException { try { final BaseClientResponse<?> r = (BaseClientResponse<?>) response; final InputStream stream = r.getStreamFactory().getInputStream(); stream.reset(); final Object entity = response.getEntity(Object.class); if (entity instanceof RuntimeException) { final RuntimeException exception = (RuntimeException) entity; throw exception; } if (entity instanceof Exception) { final Exception exception = (Exception) entity; throw new RESTBonitaRuntimeExceptionWrapper(exception); } if (Status.FORBIDDEN.getStatusCode() == response.getResponseStatus().getStatusCode()) { throw new BonitaRuntimeException("Forbidden returned"); } } catch (final IOException e) { new BonitaRuntimeException("Error while reading client response", e); } // RESTEasy will throw the original ClientResponseFailure }
@Override public void handle(final ClientResponse<?> response) throws RuntimeException { try { final BaseClientResponse<?> r = (BaseClientResponse<?>) response; final InputStream stream = r.getStreamFactory().getInputStream(); stream.reset(); final Object entity = response.getEntity(Object.class); if (entity instanceof RuntimeException) { final RuntimeException exception = (RuntimeException) entity; throw exception; } if (entity instanceof Exception) { final Exception exception = (Exception) entity; throw new RESTBonitaRuntimeExceptionWrapper(exception); } if (Status.FORBIDDEN.getStatusCode() == response.getResponseStatus().getStatusCode()) { throw new BonitaRuntimeException("Forbidden returned"); } } catch (final IOException e) { new BonitaRuntimeException("Error while reading client response", e); } // RESTEasy will throw the original ClientResponseFailure }
protected RoleRepresentation getRoleRepresentation(String name, RoleResource roleResource) { if (roleResource != null) { try { return roleResource.toRepresentation(); } catch (NotFoundException e) { throw new GroupNotFoundException(name); } catch (ClientResponseFailure clientResponseFailure) { int status = clientResponseFailure.getResponse().getResponseStatus().getStatusCode(); if (404 == status) { throw new GroupNotFoundException(name); } } catch (Exception e) { throw new SecurityManagementException(e); } } throw new GroupNotFoundException(name); }
protected RoleRepresentation getRoleRepresentation(String name, RoleResource roleResource) { if (roleResource != null) { try { return roleResource.toRepresentation(); } catch (NotFoundException e) { throw new GroupNotFoundException(name); } catch (ClientResponseFailure clientResponseFailure) { int status = clientResponseFailure.getResponse().getResponseStatus().getStatusCode(); if (404 == status) { throw new GroupNotFoundException(name); } } catch (Exception e) { throw new SecurityManagementException(e); } } throw new GroupNotFoundException(name); }
throw new OpenStackResponseException(response.getResponseStatus() .getReasonPhrase(), response.getStatus());