Ignore empty query params in the callback url
@@ -523,12 +523,6 @@ public class IdentityManagementEndpointUtil {
URL url = new URL(callbackUrl);
StringBuilder encodedCallbackUrl = new StringBuilder(
new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath(), null).toString());
-
- String malformedQueryParam = getMalformedQueryParam(url.getQuery());
- if (malformedQueryParam != null) {
- throw new MalformedURLException(
- String.format("The query param: %s does not contain a value", malformedQueryParam));
- }
Map<String, String> encodedQueryMap = getEncodedQueryParamMap(url.getQuery());
if (MapUtils.isNotEmpty(encodedQueryMap)) {
@@ -562,12 +556,6 @@ public class IdentityManagementEndpointUtil {
URI uri = new URI(callbackUrl);
StringBuilder encodedCallbackUrl = new StringBuilder(
new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, null).toString());
-
- String malformedQueryParam = getMalformedQueryParam(uri.getQuery());
- if (malformedQueryParam != null) {
- throw new URISyntaxException(malformedQueryParam,
- String.format("The query param: %s does not contain a value", malformedQueryParam));
- }
Map<String, String> encodedQueryMap = getEncodedQueryParamMap(uri.getQuery());
if (MapUtils.isNotEmpty(encodedQueryMap)) {
@@ -588,13 +576,20 @@ public class IdentityManagementEndpointUtil {
public static Map<String, String> getEncodedQueryParamMap(String queryParams) {
Map<String, String> encodedQueryMap = new HashMap<>();
- if (StringUtils.isNotBlank(queryParams)) {
- encodedQueryMap = Arrays.stream(queryParams.split(SPLITTING_CHAR))
- .map(entry -> entry.split(PADDING_CHAR))
- .collect(Collectors.toMap(entry -> Encode.forUriComponent(entry[0]),
- entry -> Encode.forUriComponent(entry[1])));
+ if (StringUtils.isBlank(queryParams)) {
+ return encodedQueryMap;
+ }
+ String[] params = queryParams.split(SPLITTING_CHAR);
+ if (ArrayUtils.isEmpty(params)) {
+ return encodedQueryMap;
+ }
+ for (String param : params) {
+ String[] queryParamWithValue = param.split(PADDING_CHAR);
+ if (queryParamWithValue.length > 1) {
+ encodedQueryMap.put(Encode.forUriComponent(queryParamWithValue[0]),
+ Encode.forUriComponent(queryParamWithValue[1]));
+ }
}
-
return encodedQueryMap;
}
@@ -618,30 +613,6 @@ public class IdentityManagementEndpointUtil {
}
}
- /**
- * Get malformed query param if the query string contains any. A malformed query param will be any param with no
- * value.
- *
- * @param queryParams Query params.
- * @return Malformed query param. Null will be returned if there are no malformed query params.
- */
- private static String getMalformedQueryParam(String queryParams) {
-
- if (StringUtils.isBlank(queryParams)) {
- return null;
- }
- String[] params = queryParams.split(SPLITTING_CHAR);
- if (ArrayUtils.isEmpty(params)) {
- return null;
- }
- for (String param : params) {
- if (StringUtils.isNotBlank(param) && param.split(PADDING_CHAR).length < 2) {
- return param;
- }
- }
- return null;
- }
-
/**
* Method to replace the last occurrence of the provided string in the base string.
*
