diff --git a/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java b/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java index 1b15a55a8f0..b495cad167f 100644 --- a/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java +++ b/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java @@ -235,6 +235,9 @@ public class OAuth2AuthzEndpoint { private static final String PARAMETERS = "params"; private static final String FORM_POST_REDIRECT_URI = "redirectURI"; + private static final String SERVICE_PROVIDER = "serviceProvider"; + private static final String TENANT_DOMAIN = "tenantDomain"; + private static final String USER_TENANT_DOMAIN = "userTenantDomain"; private static final String AUTHENTICATION_ENDPOINT = "/authenticationendpoint"; private static final String OAUTH_RESPONSE_JSP_PAGE = "/oauth_response.jsp"; @@ -645,7 +648,7 @@ private Response handleResponseFromConsent(OAuthMessage oAuthMessage) throws OAu handleUserConsent(oAuthMessage, consent, sessionState, oauth2Params, authorizationResponseDTO); if (isFormPostWithoutErrors(oAuthMessage, authorizationResponseDTO)) { - handleFormPostResponseMode(oAuthMessage, sessionState, authorizationResponseDTO); + handleFormPostResponseMode(oAuthMessage, sessionState, authorizationResponseDTO, null); if (authorizationResponseDTO.getIsForwardToOAuthResponseJSP()) { return Response.ok().build(); } @@ -938,7 +941,8 @@ private void manageOIDCSessionState(OAuthMessage oAuthMessage, OIDCSessionState private void handleFormPostResponseMode(OAuthMessage oAuthMessage, OIDCSessionState sessionState, - AuthorizationResponseDTO authorizationResponseDTO) { + AuthorizationResponseDTO authorizationResponseDTO, + AuthenticatedUser authenticatedUser) { String authenticatedIdPs = oAuthMessage.getSessionDataCacheEntry().getAuthenticatedIdPs(); OAuth2Parameters oauth2Params = getOauth2Params(oAuthMessage); @@ -957,7 +961,12 @@ sessionState, oauth2Params, getLoggedInUser(oAuthMessage).getAuthenticatedSubjec String params = buildParams(authorizationResponseDTO.getSuccessResponseDTO().getFormPostBody(), authenticatedIdPs, sessionStateValue); String redirectURI = oauth2Params.getRedirectURI(); - forwardToOauthResponseJSP(oAuthMessage, params, redirectURI); + if (authenticatedUser != null) { + forwardToOauthResponseJSP(oAuthMessage, params, redirectURI, authorizationResponseDTO, + authenticatedUser); + } else { + forwardToOauthResponseJSP(oAuthMessage, params, redirectURI); + } authorizationResponseDTO.setIsForwardToOAuthResponseJSP(true); } else { authorizationResponseDTO.setAuthenticatedIDPs(authenticatedIdPs); @@ -1160,7 +1169,7 @@ private Response handleSuccessfulAuthentication(OAuthMessage oAuthMessage, OAuth if (!authorizationResponseDTO.getIsConsentRedirect()) { if (isFormPostWithoutErrors(oAuthMessage, authorizationResponseDTO)) { - handleFormPostResponseMode(oAuthMessage, sessionState, authorizationResponseDTO); + handleFormPostResponseMode(oAuthMessage, sessionState, authorizationResponseDTO, authenticatedUser); if (authorizationResponseDTO.getIsForwardToOAuthResponseJSP()) { return Response.ok().build(); } @@ -4125,6 +4134,25 @@ private Response forwardToOauthResponseJSP(OAuthMessage oAuthMessage, String par } } + private Response forwardToOauthResponseJSP(OAuthMessage oAuthMessage, String params, String redirectURI, + AuthorizationResponseDTO authorizationResponseDTO, + AuthenticatedUser authenticatedUser) { + try { + HttpServletRequest request = oAuthMessage.getRequest(); + request.setAttribute(USER_TENANT_DOMAIN, authenticatedUser.getTenantDomain()); + request.setAttribute(TENANT_DOMAIN, authorizationResponseDTO.getSigningTenantDomain()); + request.setAttribute(SERVICE_PROVIDER, getServiceProvider(authorizationResponseDTO.getClientId())); + forwardToOauthResponseJSP(oAuthMessage, params, redirectURI); + return Response.ok().build(); + } catch (OAuthSystemException exception) { + log.error("Error occurred while setting service provider in the request to oauth_response.jsp page.", + exception); + return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) + .entity("Internal Server Error: " + exception.getMessage()) + .build(); + } + } + private boolean isPromptSelectAccount(OAuth2Parameters oauth2Params) { return OAuthConstants.Prompt.SELECT_ACCOUNT.equals(oauth2Params.getPrompt());