diff --git a/io.asgardeo.tomcat.oidc.agent/src/main/java/io/asgardeo/tomcat/oidc/agent/OIDCAgentFilter.java b/io.asgardeo.tomcat.oidc.agent/src/main/java/io/asgardeo/tomcat/oidc/agent/OIDCAgentFilter.java index fbc28c1..5379d67 100644 --- a/io.asgardeo.tomcat.oidc.agent/src/main/java/io/asgardeo/tomcat/oidc/agent/OIDCAgentFilter.java +++ b/io.asgardeo.tomcat.oidc.agent/src/main/java/io/asgardeo/tomcat/oidc/agent/OIDCAgentFilter.java @@ -21,10 +21,12 @@ import com.nimbusds.oauth2.sdk.util.StringUtils; import io.asgardeo.java.oidc.sdk.HTTPSessionBasedOIDCProcessor; import io.asgardeo.java.oidc.sdk.SSOAgentConstants; +import io.asgardeo.java.oidc.sdk.bean.RequestContext; import io.asgardeo.java.oidc.sdk.bean.SessionContext; import io.asgardeo.java.oidc.sdk.config.model.OIDCAgentConfig; import io.asgardeo.java.oidc.sdk.exception.SSOAgentClientException; import io.asgardeo.java.oidc.sdk.exception.SSOAgentException; +import io.asgardeo.java.oidc.sdk.exception.SSOAgentServerException; import io.asgardeo.java.oidc.sdk.request.OIDCRequestResolver; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; @@ -106,6 +108,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo } if (requestResolver.isCallbackResponse()) { + RequestContext requestContext = getRequestContext(request); try { oidcManager.handleOIDCCallback(request, response); } catch (SSOAgentException e) { @@ -117,7 +120,8 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo response.sendRedirect(oidcAgentConfig.getIndexPage()); return; } - response.sendRedirect("home.jsp"); + String homePage = resolveTargetPage(requestContext); + response.sendRedirect(homePage); return; } @@ -132,6 +136,29 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo } } + private String resolveTargetPage(RequestContext requestContext) { + + String targetPage = "home.jsp"; + if (StringUtils.isNotBlank(oidcAgentConfig.getHomePage())) { + targetPage = oidcAgentConfig.getHomePage(); + } else if (requestContext != null) { + if (requestContext.getParameter(SSOAgentConstants.REDIRECT_URI_KEY) != null) { + targetPage = requestContext.getParameter(SSOAgentConstants.REDIRECT_URI_KEY).toString(); + } + } + return targetPage; + } + + private RequestContext getRequestContext(HttpServletRequest request) throws SSOAgentServerException { + + HttpSession session = request.getSession(false); + + if (session != null && session.getAttribute(SSOAgentConstants.REQUEST_CONTEXT) != null) { + return (RequestContext) request.getSession(false).getAttribute(SSOAgentConstants.REQUEST_CONTEXT); + } + throw new SSOAgentServerException("Request context null."); + } + @Override public void destroy() { diff --git a/pom.xml b/pom.xml index b50df85..2ddce1b 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,7 @@ - 0.1.12 + 0.1.19 1.4 2.11.0