Fix errors when code, clientId, or tabId are null
Calling parseSessionCode inside the try-catch would result in ErrorPageException thrown by redirectToErrorPage being caught and re-reported, resulting in one log entry with `invalidRequestMessage` and another one with `unexpectedErrorHandlingRequestMessage`. Additionally, one of ErrorPageException constructors didn't pass the status to super(), resulting in the logger error message being "HTTP 500 Internal Server Error" even though the status was actually something else, like 400. I noticed that ErrorPageException can be simplified by just passing the response to super(), which is one way of fixing the problem. Closes #33232 Signed-off-by: Krzysztof Szafrański <k.p.szafranski@gmail.com>
This commit is contained in:
parent
31ce14a400
commit
731274f39e
2 changed files with 6 additions and 33 deletions
|
@ -28,44 +28,15 @@ import jakarta.ws.rs.core.Response;
|
||||||
*/
|
*/
|
||||||
public class ErrorPageException extends WebApplicationException {
|
public class ErrorPageException extends WebApplicationException {
|
||||||
|
|
||||||
private final KeycloakSession session;
|
|
||||||
private final Response.Status status;
|
|
||||||
private final String errorMessage;
|
|
||||||
private final Object[] parameters;
|
|
||||||
private final AuthenticationSessionModel authSession;
|
|
||||||
private final Response response;
|
|
||||||
|
|
||||||
|
|
||||||
public ErrorPageException(KeycloakSession session, Response.Status status, String errorMessage, Object... parameters) {
|
public ErrorPageException(KeycloakSession session, Response.Status status, String errorMessage, Object... parameters) {
|
||||||
super(errorMessage, status);
|
super(errorMessage, ErrorPage.error(session, null, status, errorMessage, parameters));
|
||||||
this.session = session;
|
|
||||||
this.status = status;
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
this.parameters = parameters;
|
|
||||||
this.authSession = null;
|
|
||||||
this.response = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorPageException(KeycloakSession session, AuthenticationSessionModel authSession, Response.Status status, String errorMessage, Object... parameters) {
|
public ErrorPageException(KeycloakSession session, AuthenticationSessionModel authSession, Response.Status status, String errorMessage, Object... parameters) {
|
||||||
this.session = session;
|
super(errorMessage, ErrorPage.error(session, authSession, status, errorMessage, parameters));
|
||||||
this.status = status;
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
this.parameters = parameters;
|
|
||||||
this.authSession = authSession;
|
|
||||||
this.response = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorPageException(Response response) {
|
public ErrorPageException(Response response) {
|
||||||
this.session = null;
|
super((Throwable) null, response);
|
||||||
this.status = null;
|
|
||||||
this.errorMessage = null;
|
|
||||||
this.parameters = null;
|
|
||||||
this.authSession = null;
|
|
||||||
this.response = response;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Response getResponse() {
|
|
||||||
return response != null ? response : ErrorPage.error(session, authSession, status, errorMessage, parameters);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,6 +404,8 @@ public class IdentityBrokerService implements IdentityProvider.AuthenticationCal
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
} catch (WebApplicationException e) {
|
||||||
|
return e.getResponse();
|
||||||
} catch (IdentityBrokerException e) {
|
} catch (IdentityBrokerException e) {
|
||||||
return redirectToErrorPage(Response.Status.BAD_GATEWAY, Messages.COULD_NOT_SEND_AUTHENTICATION_REQUEST, e, providerAlias);
|
return redirectToErrorPage(Response.Status.BAD_GATEWAY, Messages.COULD_NOT_SEND_AUTHENTICATION_REQUEST, e, providerAlias);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in a new issue