Skip to content

Commit bf3e30e

Browse files
committed
fixes
Signed-off-by: Pavel Jareš <[email protected]>
1 parent e1860fe commit bf3e30e

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/config/DefaultExcptionHandler.java renamed to api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/config/DefaultExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@Slf4j
3131
@ControllerAdvice
3232
@RequiredArgsConstructor
33-
public class DefaultExcptionHandler {
33+
public class DefaultExceptionHandler {
3434

3535
private final AuthExceptionHandler authExceptionHandler;
3636

@@ -46,7 +46,7 @@ public Mono<ResponseEntity<ApiMessageView>> handleException(ServerWebExchange ex
4646
};
4747

4848
try {
49-
authExceptionHandler.handleException(exchange.getRequest().getURI().toString(), consumer, exchange.getResponse().getHeaders()::add, exception);
49+
authExceptionHandler.handleException(exchange.getRequest().getPath().value(), consumer, exchange.getResponse().getHeaders()::add, exception);
5050
return MonoOperator.just(responseJson.get());
5151
} catch (ServletException e) {
5252
log.error("Cannot handle exception: {}", exception, e);

api-catalog-services/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ management:
179179
endpoints:
180180
migrate-legacy-ids: true
181181
web:
182-
base-path: /application
182+
base-path: /apicatalog/application
183183
exposure:
184184
include: health,info,hystrixstream
185185
health:

api-catalog-services/src/test/java/org/zowe/apiml/apicatalog/functional/ApiCatalogProtectedEndpointTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ApiCatalogProtectedEndpointTest extends ApiCatalogFunctionalTest {
2727
void requestSuccessWithBody() {
2828
// the method could return 200 or 503 depends on the state, but the aim is to check if it is accessible
2929
given().when()
30-
.get(getCatalogUriWithPath("application/health"))
30+
.get(getCatalogUriWithPath("apicatalog/application/health"))
3131
.then()
3232
.statusCode(not(HttpStatus.SC_UNAUTHORIZED))
3333
.body("status", not(nullValue()))

api-catalog-services/src/test/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ management:
156156
endpoints:
157157
migrate-legacy-ids: true
158158
web:
159-
base-path: /application
159+
base-path: /apicatalog/application
160160
exposure:
161161
include: health,info
162162
health:

apiml-security-common/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dependencies {
44
implementation libs.spring.boot.starter.web
55
implementation libs.spring.boot.starter.security
66
implementation libs.reactor
7+
implementation libs.spring.webflux
78

89
implementation libs.apache.commons.lang3
910
implementation libs.http.client5

apiml-security-common/src/main/java/org/zowe/apiml/security/common/error/AuthExceptionHandler.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.security.authentication.InsufficientAuthenticationException;
2424
import org.springframework.security.core.AuthenticationException;
2525
import org.springframework.stereotype.Component;
26+
import org.springframework.web.reactive.resource.NoResourceFoundException;
2627
import org.zowe.apiml.config.ApplicationInfo;
2728
import org.zowe.apiml.constants.ApimlConstants;
2829
import org.zowe.apiml.message.api.ApiMessageView;
@@ -32,8 +33,6 @@
3233
import java.util.Map;
3334
import java.util.function.BiConsumer;
3435

35-
import static java.util.Map.entry;
36-
3736
/**
3837
* Exception handler deals with exceptions (methods listed below) that are thrown during the authentication process
3938
*/
@@ -60,11 +59,15 @@ private static class HandlerContext {
6059
}
6160

6261
@FunctionalInterface
63-
private interface ExceptionHandler {
64-
void handle(RuntimeException ex, HandlerContext ctx);
62+
private interface ExceptionHandler<E> {
63+
void handle(E ex, HandlerContext ctx);
64+
}
65+
66+
private <E extends Exception> Map.Entry<Class<E>, ExceptionHandler<E>> entry(Class<E> clazz, ExceptionHandler<E> handler) {
67+
return Map.entry(clazz, handler);
6568
}
6669

67-
private final Map<Class<? extends RuntimeException>, ExceptionHandler> exceptionHandlers = Map.ofEntries(
70+
private final Map<Class<? extends Exception>, ExceptionHandler> exceptionHandlers = Map.ofEntries(
6871
entry(InsufficientAuthenticationException.class,
6972
(ex, ctx) -> handleAuthenticationRequired(ctx.requestUri, ctx.function, ctx.addHeader, ex)),
7073
entry(BadCredentialsException.class,
@@ -76,7 +79,7 @@ private interface ExceptionHandler {
7679
entry(TokenNotValidException.class,
7780
(ex, ctx) -> handleTokenNotValid(ctx.requestUri, ctx.function, ctx.addHeader, ex)),
7881
entry(NoMainframeIdentityException.class,
79-
(ex, ctx) -> handleNoMainframeIdentity(ctx.requestUri, ctx.function, ctx.addHeader, (NoMainframeIdentityException) ex)),
82+
(ex, ctx) -> handleNoMainframeIdentity(ctx.requestUri, ctx.function, ctx.addHeader, ex)),
8083
entry(TokenNotProvidedException.class,
8184
(ex, ctx) -> handleTokenNotProvided(ctx.requestUri, ctx.function, ex)),
8285
entry(TokenExpireException.class,
@@ -90,7 +93,7 @@ private interface ExceptionHandler {
9093
entry(InvalidCertificateException.class,
9194
(ex, ctx) -> handleInvalidCertificate(ctx.function, ex)),
9295
entry(ZosAuthenticationException.class,
93-
(ex, ctx) -> handleZosAuthenticationException(ctx.function, (ZosAuthenticationException) ex)),
96+
(ex, ctx) -> handleZosAuthenticationException(ctx.function, ex)),
9497
entry(InvalidTokenTypeException.class,
9598
(ex, ctx) -> handleInvalidTokenTypeException(ctx.requestUri, ctx.function, ex)),
9699
entry(AuthenticationServiceException.class,
@@ -99,13 +102,15 @@ private interface ExceptionHandler {
99102
(ex, ctx) -> handleAuthenticationException(ctx.requestUri, ctx.function, ex)),
100103
entry(ServiceNotAccessibleException.class,
101104
(ex, ctx) -> handleServiceNotAccessibleException(ctx.requestUri, ctx.function, ex)),
105+
entry(NoResourceFoundException.class,
106+
(ex, ctx) -> handleNoResourceFoundException(ctx.function, ex)),
102107
entry(RuntimeException.class,
103108
(ex, ctx) -> handleRuntimeException(ctx.requestUri, ctx.function, ex))
104109
);
105110

106111
private ExceptionHandler resolveHandler(RuntimeException ex) {
107112
Class<?> exClass = ex.getClass();
108-
while (exClass != null && RuntimeException.class.isAssignableFrom(exClass)) {
113+
while (exClass != null) {
109114
ExceptionHandler handler = exceptionHandlers.get(exClass);
110115
if (handler != null) {
111116
return handler;
@@ -235,6 +240,11 @@ private void handleServiceNotAccessibleException(String uri, BiConsumer<ApiMessa
235240
function.accept(message, status);
236241
}
237242

243+
private void handleNoResourceFoundException(BiConsumer<ApiMessageView, HttpStatus> function, NoResourceFoundException ex) {
244+
log.debug(MESSAGE_FORMAT, HttpStatus.NOT_FOUND.value(), ex.getMessage());
245+
writeErrorResponse("org.zowe.apiml.common.notFound", HttpStatus.NOT_FOUND, function);
246+
}
247+
238248
private void handleRuntimeException(String uri, BiConsumer<ApiMessageView, HttpStatus> function, RuntimeException ex) {
239249
log.debug(MESSAGE_FORMAT, HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage());
240250
writeErrorResponse("org.zowe.apiml.common.internalRequestError", HttpStatus.INTERNAL_SERVER_ERROR, function, uri, ExceptionUtils.getMessage(ex), ExceptionUtils.getRootCauseMessage(ex));

0 commit comments

Comments
 (0)