|
| 1 | +/* |
| 2 | + * Copyright 2020-2021 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; |
| 17 | + |
| 18 | +import org.springframework.lang.Nullable; |
| 19 | +import org.springframework.security.core.Authentication; |
| 20 | +import org.springframework.security.oauth2.core.OAuth2AuthenticationException; |
| 21 | +import org.springframework.security.oauth2.core.OAuth2Error; |
| 22 | +import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationProvider; |
| 23 | +import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken; |
| 24 | + |
| 25 | +/** |
| 26 | + * This exception is thrown by {@link OAuth2AuthorizationCodeRequestAuthenticationProvider} |
| 27 | + * when an attempt to authenticate the OAuth 2.0 Authorization Request (or Consent) fails. |
| 28 | + * |
| 29 | + * @author Joe Grandja |
| 30 | + * @since 0.1.2 |
| 31 | + * @see OAuth2AuthorizationCodeRequestAuthenticationToken |
| 32 | + * @see OAuth2AuthorizationCodeRequestAuthenticationProvider |
| 33 | + */ |
| 34 | +public class OAuth2AuthorizationCodeRequestAuthenticationException extends OAuth2AuthenticationException { |
| 35 | + private final OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthentication; |
| 36 | + |
| 37 | + /** |
| 38 | + * Constructs an {@code OAuth2AuthorizationCodeRequestAuthenticationException} using the provided parameters. |
| 39 | + * |
| 40 | + * @param error the {@link OAuth2Error OAuth 2.0 Error} |
| 41 | + * @param authorizationCodeRequestAuthentication the {@link Authentication} instance of the OAuth 2.0 Authorization Request (or Consent) |
| 42 | + */ |
| 43 | + public OAuth2AuthorizationCodeRequestAuthenticationException(OAuth2Error error, |
| 44 | + @Nullable OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthentication) { |
| 45 | + super(error); |
| 46 | + this.authorizationCodeRequestAuthentication = authorizationCodeRequestAuthentication; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Constructs an {@code OAuth2AuthorizationCodeRequestAuthenticationException} using the provided parameters. |
| 51 | + * |
| 52 | + * @param error the {@link OAuth2Error OAuth 2.0 Error} |
| 53 | + * @param cause the root cause |
| 54 | + * @param authorizationCodeRequestAuthentication the {@link Authentication} instance of the OAuth 2.0 Authorization Request (or Consent) |
| 55 | + */ |
| 56 | + public OAuth2AuthorizationCodeRequestAuthenticationException(OAuth2Error error, Throwable cause, |
| 57 | + @Nullable OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthentication) { |
| 58 | + super(error, cause); |
| 59 | + this.authorizationCodeRequestAuthentication = authorizationCodeRequestAuthentication; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns the {@link Authentication} instance of the OAuth 2.0 Authorization Request (or Consent), or {@code null} if not available. |
| 64 | + * |
| 65 | + * @return the {@link OAuth2AuthorizationCodeRequestAuthenticationToken} |
| 66 | + */ |
| 67 | + @Nullable |
| 68 | + public OAuth2AuthorizationCodeRequestAuthenticationToken getAuthorizationCodeRequestAuthentication() { |
| 69 | + return this.authorizationCodeRequestAuthentication; |
| 70 | + } |
| 71 | + |
| 72 | +} |
0 commit comments