diff --git a/src/main/java/dev/dinauer/oidcproxy/Resource.java b/src/main/java/dev/dinauer/oidcproxy/Resource.java index f54b99b..7d6d542 100644 --- a/src/main/java/dev/dinauer/oidcproxy/Resource.java +++ b/src/main/java/dev/dinauer/oidcproxy/Resource.java @@ -6,6 +6,7 @@ import dev.dinauer.oidcproxy.proxy.ForwardService; import dev.dinauer.oidcproxy.proxy.ResponseHandler; import dev.dinauer.oidcproxy.proxy.TimedHttpResponse; import dev.dinauer.oidcproxy.proxy.exception.ProxyHttpException; +import dev.dinauer.oidcproxy.proxy.exception.SessionNotFoundException; import dev.dinauer.oidcproxy.proxy.exception.TokenNotFoundException; import dev.dinauer.oidcproxy.startup.PathConverter; import dev.dinauer.oidcproxy.startup.ProxyRoute; @@ -89,9 +90,9 @@ public class Resource accessLog.log(AccessLog.Type.ERROR, context, PathConverter.toPath(requestSegments), route.target(), e.getStatusCode(), e.getTime()); ResponseHandler.error(context, e.getStatusCode()); } - catch (TokenNotFoundException e) + catch (TokenNotFoundException | SessionNotFoundException e) { - LOG.error("Token not found.", e); + LOG.error("Token / Session not found.", e); ResponseHandler.error(context, 401); } catch (InterruptedException e) diff --git a/src/main/java/dev/dinauer/oidcproxy/proxy/ForwardService.java b/src/main/java/dev/dinauer/oidcproxy/proxy/ForwardService.java index 158b23c..19e4e84 100644 --- a/src/main/java/dev/dinauer/oidcproxy/proxy/ForwardService.java +++ b/src/main/java/dev/dinauer/oidcproxy/proxy/ForwardService.java @@ -1,6 +1,7 @@ package dev.dinauer.oidcproxy.proxy; import dev.dinauer.oidcproxy.proxy.exception.ProxyHttpException; +import dev.dinauer.oidcproxy.proxy.exception.SessionNotFoundException; import dev.dinauer.oidcproxy.proxy.exception.TokenNotFoundException; import dev.dinauer.oidcproxy.session.SessionCache; import dev.dinauer.oidcproxy.proxy.header.HeaderFilter; @@ -23,7 +24,7 @@ public class ForwardService @Inject HeaderFilter headerFilter; - public TimedHttpResponse send(RoutingContext context, String route, String strategy) throws IOException, InterruptedException, ProxyHttpException, TokenNotFoundException + public TimedHttpResponse send(RoutingContext context, String route, String strategy) throws IOException, InterruptedException, ProxyHttpException, TokenNotFoundException, SessionNotFoundException { HttpRequestBuilder builder = HttpRequestBuilder.create(); builder.setUri(route); diff --git a/src/main/java/dev/dinauer/oidcproxy/proxy/exception/SessionNotFoundException.java b/src/main/java/dev/dinauer/oidcproxy/proxy/exception/SessionNotFoundException.java new file mode 100644 index 0000000..a769561 --- /dev/null +++ b/src/main/java/dev/dinauer/oidcproxy/proxy/exception/SessionNotFoundException.java @@ -0,0 +1,8 @@ +package dev.dinauer.oidcproxy.proxy.exception; + +public class SessionNotFoundException extends Exception +{ + public SessionNotFoundException() + { + } +} diff --git a/src/main/java/dev/dinauer/oidcproxy/proxy/header/HeaderFilter.java b/src/main/java/dev/dinauer/oidcproxy/proxy/header/HeaderFilter.java index 73a5143..f448a00 100644 --- a/src/main/java/dev/dinauer/oidcproxy/proxy/header/HeaderFilter.java +++ b/src/main/java/dev/dinauer/oidcproxy/proxy/header/HeaderFilter.java @@ -1,5 +1,6 @@ package dev.dinauer.oidcproxy.proxy.header; +import dev.dinauer.oidcproxy.proxy.exception.SessionNotFoundException; import dev.dinauer.oidcproxy.proxy.exception.TokenNotFoundException; import dev.dinauer.oidcproxy.proxy.header.strategy.OidcStrategy; import dev.dinauer.oidcproxy.session.SessionCache; @@ -21,7 +22,7 @@ public class HeaderFilter @Inject OidcStrategy oidcStrategy; - public List> filter(HttpServerRequest request, String strategy) throws TokenNotFoundException + public List> filter(HttpServerRequest request, String strategy) throws TokenNotFoundException, SessionNotFoundException { List> headers = filterHop2HopHeaders(request.headers().entries()); if ("OIDC".equals(strategy)) diff --git a/src/main/java/dev/dinauer/oidcproxy/proxy/header/strategy/OidcStrategy.java b/src/main/java/dev/dinauer/oidcproxy/proxy/header/strategy/OidcStrategy.java index 353a457..b610d0c 100644 --- a/src/main/java/dev/dinauer/oidcproxy/proxy/header/strategy/OidcStrategy.java +++ b/src/main/java/dev/dinauer/oidcproxy/proxy/header/strategy/OidcStrategy.java @@ -1,5 +1,6 @@ package dev.dinauer.oidcproxy.proxy.header.strategy; +import dev.dinauer.oidcproxy.proxy.exception.SessionNotFoundException; import dev.dinauer.oidcproxy.proxy.exception.TokenNotFoundException; import dev.dinauer.oidcproxy.session.SessionCache; import io.quarkus.security.UnauthorizedException; @@ -21,7 +22,7 @@ public class OidcStrategy @Inject SessionCache sessionCache; - public List> filter(HttpServerRequest request, List> input) throws TokenNotFoundException + public List> filter(HttpServerRequest request, List> input) throws TokenNotFoundException, SessionNotFoundException { if (!hasAuthHeader(input)) { @@ -30,7 +31,7 @@ public class OidcStrategy return input; } - private String getAccessToken(HttpServerRequest request) throws TokenNotFoundException + private String getAccessToken(HttpServerRequest request) throws TokenNotFoundException, SessionNotFoundException { for (Cookie cookie : request.cookies()) { @@ -40,7 +41,7 @@ public class OidcStrategy return sessionCache.get(session); } } - throw new UnauthorizedException(); + throw new SessionNotFoundException(); } private boolean hasAuthHeader(List> input)