Skip to content

Commit

Permalink
added multiOptionURI parameter to the redirect url
Browse files Browse the repository at this point in the history
  • Loading branch information
ashanthamara committed Nov 24, 2023
1 parent 05e35bc commit d608511
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.owasp.encoder</groupId>
<artifactId>encoder</artifactId>
</dependency>

<!--Test Dependencies-->
<dependency>
Expand Down Expand Up @@ -133,6 +137,7 @@
org.wso2.carbon.user.core.*; version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.identity.auth.attribute.handler.*;
version="${identity.governance.imp.pkg.version.range}",
org.owasp.encoder; version="${encoder.wso2.import.version.range}",
</Import-Package>
<Private-Package>
org.wso2.carbon.identity.application.authenticator.magiclink.internal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.owasp.encoder.Encode;
import org.wso2.carbon.identity.application.authentication.framework.AbstractApplicationAuthenticator;
import org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus;
import org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator;
Expand All @@ -31,7 +32,6 @@
import org.wso2.carbon.identity.application.authentication.framework.exception.InvalidCredentialsException;
import org.wso2.carbon.identity.application.authentication.framework.exception.LogoutFailedException;
import org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException;
import org.wso2.carbon.identity.application.authentication.framework.model.AdditionalData;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatorData;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatorMessage;
Expand Down Expand Up @@ -79,9 +79,9 @@
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.LogConstants.ActionIDs.VALIDATE_MAGIC_LINK_REQUEST;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.LogConstants.MAGIC_LINK_AUTH_SERVICE;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.MAGIC_LINK_TOKEN;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.MULTI_OPTION_QUERY_PARAM;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.USERNAME_PARAM;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.USER_NAME;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.USER_PROMPT;
import static org.wso2.carbon.identity.application.authenticator.magiclink.MagicLinkAuthenticatorConstants.MLT;

/**
Expand Down Expand Up @@ -171,6 +171,7 @@ protected void initiateAuthenticationRequest(HttpServletRequest request, HttpSer
context.setProperty(MagicLinkAuthenticatorConstants.IS_IDF_INITIATED_FROM_AUTHENTICATOR, true);
String loginPage = ConfigurationFacade.getInstance().getAuthenticationEndpointURL();
String queryParams = context.getContextIdIncludedQueryParams();
String multiOptionURI = getMultiOptionURIQueryParam(request);
try {
if (log.isDebugEnabled()) {
String logMsg = String.format("Redirecting to identifier first flow since " +
Expand All @@ -179,7 +180,8 @@ protected void initiateAuthenticationRequest(HttpServletRequest request, HttpSer
log.debug(logMsg);
}
String redirectUri = loginPage + ("?" + queryParams) + MagicLinkAuthenticatorConstants.AUTHENTICATORS +
MagicLinkAuthenticatorConstants.IDF_HANDLER_NAME + ":" + MagicLinkAuthenticatorConstants.LOCAL;
MagicLinkAuthenticatorConstants.IDF_HANDLER_NAME + ":" + MagicLinkAuthenticatorConstants.LOCAL
+ multiOptionURI;
response.sendRedirect(redirectUri);
if (LoggerUtils.isDiagnosticLogsEnabled() && finalDiagnosticLogBuilder != null) {
finalDiagnosticLogBuilder.resultMessage("Redirecting to identifier first flow since the last " +
Expand Down Expand Up @@ -674,4 +676,20 @@ private void setAuthParamsForIdfInitiatedFromMagicLink(AuthenticatorData authent
authenticatorParamMetadataList.add(usernameMetadata);
authenticatorData.setAuthParams(authenticatorParamMetadataList);
}

/**
* Get the multi option URI query params.
*
* @param request HttpServletRequest.
*/
private static String getMultiOptionURIQueryParam(HttpServletRequest request) {

String multiOptionURI = "";
if (request != null) {
multiOptionURI = request.getParameter(MULTI_OPTION_QUERY_PARAM);
multiOptionURI = multiOptionURI != null ? "&" + MULTI_OPTION_QUERY_PARAM + "=" +
Encode.forUriComponent(multiOptionURI) : "";
}
return multiOptionURI;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private MagicLinkAuthenticatorConstants() {
public static final String EXPIRYTIME = "expiry-time";
public static final String IS_API_BASED_AUTHENTICATION_SUPPORTED = "isAPIBasedAuthenticationSupported";
public static final String CALLBACK_URL = "callbackUrl";
public static final String MULTI_OPTION_QUERY_PARAM = "multiOptionURI";

/**
* Constants related to log management.
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
<artifactId>org.wso2.carbon.identity.auth.attribute.handler</artifactId>
<version>${identity.governance.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.owasp.encoder</groupId>
<artifactId>encoder</artifactId>
<version>${owasp.encoder.version}</version>
</dependency>

<!--Test Dependencies-->
<dependency>
Expand Down Expand Up @@ -222,6 +227,7 @@
<identity.governance.version>1.8.23</identity.governance.version>
<org.wso2.carbon.identity.organization.management.core.version>1.0.55
</org.wso2.carbon.identity.organization.management.core.version>
<owasp.encoder.version>1.2.0.wso2v1</owasp.encoder.version>

<!--Test Dependencies-->
<testng.version>6.9.10</testng.version>
Expand All @@ -241,6 +247,7 @@
<carbon.kernel.imp.pkg.version.range>[4.5.0, 5.0.0)</carbon.kernel.imp.pkg.version.range>
<carbon.user.api.imp.pkg.version.range>[1.0.1, 2.0.0)</carbon.user.api.imp.pkg.version.range>
<identity.governance.imp.pkg.version.range>[1.5.0, 3.0.0)</identity.governance.imp.pkg.version.range>
<encoder.wso2.import.version.range>[1.2.0, 2.0.0)</encoder.wso2.import.version.range>

<findbugs-maven-plugin.version>3.0.5</findbugs-maven-plugin.version>
<maven.bundle.plugin.version>3.2.0</maven.bundle.plugin.version>
Expand Down

0 comments on commit d608511

Please sign in to comment.