6 changed files with 101 additions and 59 deletions
@ -1,47 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2002-2019 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
package org.springframework.security.oauth2.client.authentication; |
|
||||||
|
|
||||||
import org.springframework.security.oauth2.core.OAuth2AuthorizationException; |
|
||||||
import org.springframework.security.oauth2.core.OAuth2Error; |
|
||||||
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationExchange; |
|
||||||
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; |
|
||||||
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse; |
|
||||||
|
|
||||||
/** |
|
||||||
* A validator for an "exchange" of an OAuth 2.0 Authorization Request and Response. |
|
||||||
* |
|
||||||
* @author Joe Grandja |
|
||||||
* @since 5.1 |
|
||||||
* @see OAuth2AuthorizationExchange |
|
||||||
*/ |
|
||||||
final class OAuth2AuthorizationExchangeValidator { |
|
||||||
private static final String INVALID_STATE_PARAMETER_ERROR_CODE = "invalid_state_parameter"; |
|
||||||
|
|
||||||
static void validate(OAuth2AuthorizationExchange authorizationExchange) { |
|
||||||
OAuth2AuthorizationRequest authorizationRequest = authorizationExchange.getAuthorizationRequest(); |
|
||||||
OAuth2AuthorizationResponse authorizationResponse = authorizationExchange.getAuthorizationResponse(); |
|
||||||
|
|
||||||
if (authorizationResponse.statusError()) { |
|
||||||
throw new OAuth2AuthorizationException(authorizationResponse.getError()); |
|
||||||
} |
|
||||||
|
|
||||||
if (!authorizationResponse.getState().equals(authorizationRequest.getState())) { |
|
||||||
OAuth2Error oauth2Error = new OAuth2Error(INVALID_STATE_PARAMETER_ERROR_CODE); |
|
||||||
throw new OAuth2AuthorizationException(oauth2Error); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue