From 26d7ae710cafe431aa7bdbb2600e8607f5a82fd0 Mon Sep 17 00:00:00 2001 From: ChanikaRuchini Date: Mon, 21 Mar 2022 10:50:13 +0530 Subject: [PATCH] Fix Asgardeo Java OIDC app redirection Issue --- .../sdk/HTTPSessionBasedOIDCProcessor.java | 4 ++++ .../java/oidc/sdk/SSOAgentConstants.java | 2 ++ .../config/FileBasedOIDCConfigProvider.java | 2 ++ .../sdk/config/model/OIDCAgentConfig.java | 21 +++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/HTTPSessionBasedOIDCProcessor.java b/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/HTTPSessionBasedOIDCProcessor.java index 99e076e..0ea24cd 100644 --- a/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/HTTPSessionBasedOIDCProcessor.java +++ b/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/HTTPSessionBasedOIDCProcessor.java @@ -63,6 +63,10 @@ public void sendForLogin(HttpServletRequest request, HttpServletResponse respons HttpSession session = request.getSession(); RequestContext requestContext = defaultOIDCManager.sendForLogin(request, response); + if (request.getRequestURI() != null) { + String redirectPageURI = request.getRequestURI().substring(request.getContextPath().length() + 1); + requestContext.setParameter(SSOAgentConstants.REDIRECT_URI_KEY, redirectPageURI); + } session.setAttribute(SSOAgentConstants.REQUEST_CONTEXT, requestContext); } diff --git a/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/SSOAgentConstants.java b/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/SSOAgentConstants.java index bb98c8d..0980dbe 100644 --- a/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/SSOAgentConstants.java +++ b/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/SSOAgentConstants.java @@ -49,8 +49,10 @@ public class SSOAgentConstants { public static final String CONSUMER_SECRET = "consumerSecret"; public static final String CALL_BACK_URL = "callBackURL"; public static final String SKIP_URIS = "skipURIs"; + public static final String REDIRECT_URI_KEY = "redirectURI"; public static final String INDEX_PAGE = "indexPage"; public static final String ERROR_PAGE = "errorPage"; + public static final String HOME_PAGE = "homePage"; public static final String LOGOUT_URL = "logoutURL"; public static final String SCOPE = "scope"; public static final String OAUTH2_GRANT_TYPE = "grantType"; diff --git a/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/config/FileBasedOIDCConfigProvider.java b/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/config/FileBasedOIDCConfigProvider.java index 7efe3c4..fbd3125 100644 --- a/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/config/FileBasedOIDCConfigProvider.java +++ b/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/config/FileBasedOIDCConfigProvider.java @@ -69,6 +69,7 @@ private void initConfig(Properties properties) throws SSOAgentClientException { new Secret(properties.getProperty(SSOAgentConstants.CONSUMER_SECRET)) : null; String indexPage = properties.getProperty(SSOAgentConstants.INDEX_PAGE); String errorPage = properties.getProperty(SSOAgentConstants.ERROR_PAGE); + String homePage = properties.getProperty(SSOAgentConstants.HOME_PAGE); String logoutURL = properties.getProperty(SSOAgentConstants.LOGOUT_URL); JWSAlgorithm jwsAlgorithm = StringUtils.isNotBlank(properties.getProperty(SSOAgentConstants.ID_TOKEN_SIGN_ALG)) ? @@ -149,6 +150,7 @@ private void initConfig(Properties properties) throws SSOAgentClientException { oidcAgentConfig.setConsumerSecret(consumerSecret); oidcAgentConfig.setIndexPage(indexPage); oidcAgentConfig.setErrorPage(errorPage); + oidcAgentConfig.setHomePage(homePage); oidcAgentConfig.setLogoutURL(logoutURL); oidcAgentConfig.setIssuer(issuer); oidcAgentConfig.setSkipURIs(skipURIs); diff --git a/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/config/model/OIDCAgentConfig.java b/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/config/model/OIDCAgentConfig.java index 248e6eb..92ab003 100644 --- a/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/config/model/OIDCAgentConfig.java +++ b/io.asgardeo.java.oidc.sdk/src/main/java/io/asgardeo/java/oidc/sdk/config/model/OIDCAgentConfig.java @@ -38,6 +38,7 @@ public class OIDCAgentConfig { private Secret consumerSecret; private String indexPage; private String errorPage; + private String homePage; private String logoutURL; private URI callbackUrl; private Scope scope; @@ -136,6 +137,26 @@ public void setErrorPage(String errorPage) { this.errorPage = errorPage; } + /** + * Returns the home page of the OIDC agent. + * + * @return Home page of the OIDC agent. + */ + public String getHomePage() { + + return homePage; + } + + /** + * Sets the home page for the OIDC agent. + * + * @param homePage The home page of the OIDC agent. + */ + public void setHomePage(String homePage) { + + this.homePage = homePage; + } + /** * Returns the logout URL of the OIDC agent. *