Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update oauth endpoint request with t, ut and sp #2175

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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());
Expand Down
Loading