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

Fix branding not applied to mfa #6021

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 @@ -75,9 +75,11 @@
import java.io.IOException;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
Expand All @@ -96,6 +98,7 @@
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.ACCOUNT_DISABLED_CLAIM_URI;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.ACCOUNT_LOCKED_CLAIM_URI;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.ACCOUNT_UNLOCK_TIME_CLAIM;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.AUTHENTICATOR;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.AnalyticsAttributes.SESSION_ID;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.BACK_TO_FIRST_STEP;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.ERROR_DESCRIPTION_APP_DISABLED;
Expand Down Expand Up @@ -393,6 +396,10 @@ && isStepHasMultiOption(context)

if (!context.isLogoutRequest()) {
FrameworkUtils.getAuthenticationRequestHandler().handle(request, responseWrapper, context);
// Adding spIp param to the redirect URL if the authenticator is not the organization authenticator.
if (!ORGANIZATION_AUTHENTICATOR.equals(request.getParameter(AUTHENTICATOR))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are trying skip adding sp-uuid to the consent page when it is organization authenticator. Trying to understand the how it created an issue. I hope you can proceed with the improvement exclude this and explain the issue may be via sharing the network trace where we can identify how it caused an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not for consent page. It's for the MFA pages in sub org applications.
When organization authenticator is being used, it's the point where the application auth process switches from main org to sub org. At this point the flow is still being executed at the main org level application. But the url being generated here leads to sub org first factor page. If we add the spId in the context to the URL, it'll be the main org application id, which is not valid for the sub org application page.

addServiceProviderIdToRedirectUrl(responseWrapper, context);
}
} else {
FrameworkUtils.getLogoutRequestHandler().handle(request, responseWrapper, context);
}
Expand Down Expand Up @@ -1325,4 +1332,35 @@ private boolean isStepHasMultiOption(AuthenticationContext context) {
}
return false;
}

private void addServiceProviderIdToRedirectUrl(CommonAuthResponseWrapper responseWrapper,
AuthenticationContext context) {

if (responseWrapper == null || context == null) {
return;
}
try {
String redirectURL = responseWrapper.getRedirectURL();
String serviceProviderID = context.getServiceProviderResourceId();
if (StringUtils.isNotBlank(redirectURL) && StringUtils.isNotBlank(serviceProviderID)) {
URI uri = new URI(redirectURL);
String query = uri.getRawQuery();
if (StringUtils.isNotBlank(query)) {
if (!query.contains(FrameworkConstants.REQUEST_PARAM_SP_UUID + "=")) {
redirectURL = redirectURL + "&" + FrameworkConstants.REQUEST_PARAM_SP_UUID
+ "=" + URLEncoder.encode(serviceProviderID,
StandardCharsets.UTF_8.name());
}
} else {
redirectURL = redirectURL + "?" + FrameworkConstants.REQUEST_PARAM_SP_UUID
+ "=" + URLEncoder.encode(serviceProviderID, StandardCharsets.UTF_8.name());
}
responseWrapper.sendRedirect(redirectURL);
}
} catch (URISyntaxException | IOException e) {
// No need to break the flow due to this error since added spId to redirect URL is used only
// for branding purposes.
log.debug("Error while adding spId to redirect URL.");
}
}
}
Loading