Skip to content

Commit ff51730

Browse files
authored
Merge pull request #191 from AmshikaH/master
Add multiOptionURI parsing for additional query parameters
2 parents 969a0d4 + 2e0cc8f commit ff51730

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

components/org.wso2.carbon.identity.application.authenticator.oidc/src/main/java/org/wso2/carbon/identity/application/authenticator/oidc/OIDCAuthenticatorConstants.java

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ private OIDCAuthenticatorConstants() {
6868
public static final String POST_LOGOUT_REDIRECT_URI = "post_logout_redirect_uri";
6969
public static final String ID_TOKEN_HINT = "id_token_hint";
7070

71+
public static final String MULTI_OPTION_URI = "multiOptionURI";
72+
public static final String URI_QUERY_PARAM_DELIMITER = "&";
73+
public static final String QUERY_PARAM_KEY_VALUE_DELIMITER = "=";
74+
7175
public static final String AUTH_PARAM = "$authparam";
7276
public static final String DYNAMIC_AUTH_PARAMS_LOOKUP_REGEX = "\\$authparam\\{(\\w+)\\}";
7377

components/org.wso2.carbon.identity.application.authenticator.oidc/src/main/java/org/wso2/carbon/identity/application/authenticator/oidc/OpenIDConnectAuthenticator.java

+49-4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,13 @@
125125
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.LogConstants.ActionIDs.INITIATE_OUTBOUND_AUTH_REQUEST;
126126
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.LogConstants.ActionIDs.PROCESS_AUTHENTICATION_RESPONSE;
127127
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.LogConstants.OUTBOUND_AUTH_OIDC_SERVICE;
128+
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.MULTI_OPTION_URI;
128129
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.OIDC_FEDERATION_NONCE;
130+
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.QUERY_PARAM_KEY_VALUE_DELIMITER;
129131
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.REDIRECT_URL_SUFFIX;
130132
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.SCOPE_PARAM_SUFFIX;
131133
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.STATE_PARAM_SUFFIX;
134+
import static org.wso2.carbon.identity.application.authenticator.oidc.OIDCAuthenticatorConstants.URI_QUERY_PARAM_DELIMITER;
132135
import static org.wso2.carbon.identity.base.IdentityConstants.FEDERATED_IDP_SESSION_ID;
133136

134137
/**
@@ -2033,10 +2036,10 @@ private String interpretQueryString(AuthenticationContext context, String queryS
20332036
Matcher matcher = pattern.matcher(queryString);
20342037
while (matcher.find()) {
20352038
String name = matcher.group(1);
2036-
String[] values = parameters.get(name);
2037-
String value = "";
2038-
if (values != null && values.length > 0) {
2039-
value = values[0];
2039+
String value = getParameterFromParamMap(parameters, name);
2040+
if (StringUtils.isBlank(value)) {
2041+
String multiOptionURI = getParameterFromParamMap(parameters, MULTI_OPTION_URI);
2042+
value = getParameterFromURIString(multiOptionURI, name);
20402043
}
20412044
if (LOG.isDebugEnabled()) {
20422045
LOG.debug("InterpretQueryString name: " + name + ", value: " + value);
@@ -2049,6 +2052,48 @@ private String interpretQueryString(AuthenticationContext context, String queryS
20492052
return queryString;
20502053
}
20512054

2055+
/**
2056+
* Gets the value of the parameter corresponding to the given parameter
2057+
* name from the request's parameter map.
2058+
*
2059+
* @param parameters The parameter map of the request.
2060+
* @param parameterName The name of the parameter to be retrieved.
2061+
* @return The value of the parameter if it is present in the parameter map.
2062+
* If it is not present, an empty String is returned instead.
2063+
*/
2064+
private String getParameterFromParamMap(Map<String, String[]> parameters, String parameterName) {
2065+
2066+
String[] parameterValueMap = parameters.get(parameterName);
2067+
if (parameterValueMap != null && parameterValueMap.length > 0) {
2068+
return parameterValueMap[0];
2069+
}
2070+
return StringUtils.EMPTY;
2071+
}
2072+
2073+
/**
2074+
* Parses the given URI String to get the parameter value corresponding to the
2075+
* given parameter name.
2076+
*
2077+
* @param uriString The URI String to be parsed.
2078+
* @param parameterName The name of the parameter to be retrieved.
2079+
* @return The value of the parameter if it is present in the URI String.
2080+
* If it is not present, an empty String is returned instead.
2081+
*/
2082+
private String getParameterFromURIString(String uriString, String parameterName) {
2083+
2084+
if (StringUtils.isNotBlank(uriString)) {
2085+
String[] queryParams = uriString.split(URI_QUERY_PARAM_DELIMITER, -1);
2086+
for (String queryParam: queryParams) {
2087+
String[] queryParamComponents = queryParam.split(QUERY_PARAM_KEY_VALUE_DELIMITER);
2088+
if (queryParamComponents.length == 2 && queryParamComponents[0].equalsIgnoreCase(parameterName)) {
2089+
return queryParamComponents[1];
2090+
}
2091+
}
2092+
}
2093+
return StringUtils.EMPTY;
2094+
}
2095+
2096+
20522097
/**
20532098
* Evaluate the query string for additional query params with actual key and value.
20542099
*

0 commit comments

Comments
 (0)