|
| 1 | +/* |
| 2 | + * Copyright 2020-2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.security.oauth2.server.authorization.oidc.web.authentication; |
| 17 | + |
| 18 | +import java.util.Map; |
| 19 | + |
| 20 | +import jakarta.servlet.http.HttpServletRequest; |
| 21 | + |
| 22 | +import org.springframework.util.LinkedMultiValueMap; |
| 23 | +import org.springframework.util.MultiValueMap; |
| 24 | +import org.springframework.util.StringUtils; |
| 25 | + |
| 26 | +/** |
| 27 | + * Utility methods for the OAuth 2.0 Protocol Endpoints. |
| 28 | + * |
| 29 | + * @author Joe Grandja |
| 30 | + * @author Greg Li |
| 31 | + * @since 1.1.4 |
| 32 | + */ |
| 33 | +final class OAuth2EndpointUtils { |
| 34 | + |
| 35 | + private OAuth2EndpointUtils() { |
| 36 | + } |
| 37 | + |
| 38 | + static MultiValueMap<String, String> getFormParameters(HttpServletRequest request) { |
| 39 | + Map<String, String[]> parameterMap = request.getParameterMap(); |
| 40 | + MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(); |
| 41 | + parameterMap.forEach((key, values) -> { |
| 42 | + String queryString = StringUtils.hasText(request.getQueryString()) ? request.getQueryString() : ""; |
| 43 | + // If not query parameter then it's a form parameter |
| 44 | + if (!queryString.contains(key) && values.length > 0) { |
| 45 | + for (String value : values) { |
| 46 | + parameters.add(key, value); |
| 47 | + } |
| 48 | + } |
| 49 | + }); |
| 50 | + return parameters; |
| 51 | + } |
| 52 | + |
| 53 | + static MultiValueMap<String, String> getQueryParameters(HttpServletRequest request) { |
| 54 | + Map<String, String[]> parameterMap = request.getParameterMap(); |
| 55 | + MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(); |
| 56 | + parameterMap.forEach((key, values) -> { |
| 57 | + String queryString = StringUtils.hasText(request.getQueryString()) ? request.getQueryString() : ""; |
| 58 | + if (queryString.contains(key) && values.length > 0) { |
| 59 | + for (String value : values) { |
| 60 | + parameters.add(key, value); |
| 61 | + } |
| 62 | + } |
| 63 | + }); |
| 64 | + return parameters; |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments