-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: on RootProvider always rely on the Error page if unexpected erro…
…r is raised fixes gravitee-io/issues#9000 fixes AM-535 (cherry picked from commit 39355e4)
- Loading branch information
1 parent
f77003e
commit 82a5d40
Showing
6 changed files
with
171 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ava/io/gravitee/am/gateway/handler/root/resources/handler/error/AbstractErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.am.gateway.handler.root.resources.handler.error; | ||
|
||
import io.gravitee.am.common.exception.oauth2.OAuth2Exception; | ||
import io.gravitee.am.common.oauth2.Parameters; | ||
import io.gravitee.am.common.utils.ConstantKeys; | ||
import io.gravitee.am.gateway.handler.common.vertx.utils.RequestUtils; | ||
import io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest; | ||
import io.gravitee.am.gateway.policy.PolicyChainException; | ||
import io.gravitee.am.model.oidc.Client; | ||
import io.gravitee.am.service.exception.AbstractManagementException; | ||
import io.gravitee.common.http.HttpHeaders; | ||
import io.vertx.core.Handler; | ||
import io.vertx.ext.auth.webauthn.impl.attestation.AttestationException; | ||
import io.vertx.ext.web.handler.HttpException; | ||
import io.vertx.reactivex.core.MultiMap; | ||
import io.vertx.reactivex.core.http.HttpServerRequest; | ||
import io.vertx.reactivex.core.http.HttpServerResponse; | ||
import io.vertx.reactivex.ext.web.RoutingContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static io.gravitee.am.common.utils.ConstantKeys.CLIENT_CONTEXT_KEY; | ||
import static io.gravitee.am.common.utils.ConstantKeys.TOKEN_CONTEXT_KEY; | ||
import static io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest.CONTEXT_PATH; | ||
import static java.util.Objects.isNull; | ||
|
||
/** | ||
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
public abstract class AbstractErrorHandler implements Handler<RoutingContext> { | ||
|
||
protected final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
protected final String errorPage; | ||
|
||
public AbstractErrorHandler(String errorPage) { | ||
this.errorPage = errorPage; | ||
} | ||
|
||
@Override | ||
public final void handle(RoutingContext routingContext) { | ||
if (routingContext.failed()) { | ||
try { | ||
doHandle(routingContext); | ||
} catch (Exception e) { | ||
logger.error("Unable to handle error response", e); | ||
String errorPageURL = routingContext.get(CONTEXT_PATH) + errorPage; | ||
|
||
final HttpServerRequest request = routingContext.request(); | ||
// prepare query parameters | ||
MultiMap parameters = RequestUtils.getCleanedQueryParams(routingContext.request()); | ||
// get client if exists | ||
Client client = routingContext.get(CLIENT_CONTEXT_KEY); | ||
if (client != null) { | ||
parameters.set(Parameters.CLIENT_ID, client.getClientId()); | ||
} else if (request.getParam(Parameters.CLIENT_ID) != null) { | ||
parameters.set(Parameters.CLIENT_ID, (request.getParam(Parameters.CLIENT_ID))); | ||
} | ||
|
||
// append error information | ||
parameters.set(ConstantKeys.ERROR_PARAM_KEY, "server_error"); | ||
parameters.set(ConstantKeys.ERROR_DESCRIPTION_PARAM_KEY, "Unexpected error occurred"); | ||
|
||
// redirect | ||
String proxiedErrorPage = UriBuilderRequest.resolveProxyRequest(request, errorPageURL, parameters, true); | ||
doRedirect(routingContext.response(), proxiedErrorPage); | ||
} | ||
} | ||
} | ||
|
||
protected abstract void doHandle(RoutingContext routingContext); | ||
|
||
protected void doRedirect(HttpServerResponse response, String url) { | ||
response.putHeader(HttpHeaders.LOCATION, url).setStatusCode(302).end(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters