001package com.nimbusds.openid.connect.provider.spi.authz;
002
003
004import org.checkerframework.checker.nullness.qual.Nullable;
005
006import com.nimbusds.oauth2.sdk.ErrorObject;
007import com.nimbusds.oauth2.sdk.OAuth2Error;
008
009
010/**
011 * Invalid OAuth 2.0 authorisation / OpenID authentication request exception.
012 */
013public class InvalidAuthorizationRequestException extends Exception {
014        
015        
016        /**
017         * The error object.
018         */
019        private final ErrorObject errorObject;
020        
021        
022        /**
023         * {@code true} if redirection to the client is disabled.
024         */
025        private final boolean redirectDisabled;
026        
027        
028        /**
029         * Creates a new invalid OAuth 2.0 authorisation / OpenID
030         * authentication request exception. The error code is set to
031         * {@link OAuth2Error#INVALID_REQUEST invalid_request}. The exception
032         * will result in redirection back to the OAuth 2.0 client with the
033         * error.
034         *
035         * @param message The exception message, will be logged. Should not be
036         *                {@code null}.
037         */
038        public InvalidAuthorizationRequestException(final @Nullable String message) {
039                this(message, OAuth2Error.INVALID_REQUEST, false);
040        }
041        
042        
043        /**
044         * Creates a new invalid OAuth 2.0 authorisation / OpenID
045         * authentication request exception.
046         *
047         * @param message          The exception message, will be logged.
048         *                         Should not be {@code null}.
049         * @param errorObject      The error object, with code and optional
050         *                         description and URI. Must not be
051         *                         {@code null}.
052         * @param redirectDisabled {@code true} if redirection back to the
053         *                         OAuth 2.0 client with the error is disabled,
054         *                         {@code false} to perform the regular
055         *                         redirection to {@code redirect_uri} with
056         *                         the error.
057         */
058        public InvalidAuthorizationRequestException(final @Nullable String message,
059                                                    final ErrorObject errorObject,
060                                                    final boolean redirectDisabled) {
061                super(message);
062                if (errorObject == null) {
063                        throw new IllegalArgumentException("The error object must not be null");
064                }
065                this.errorObject = errorObject;
066                this.redirectDisabled = redirectDisabled;
067        }
068        
069        
070        /**
071         * Returns the error object with code and optional description and URI.
072         *
073         * @return The error object.
074         */
075        public ErrorObject getErrorObject() {
076                return errorObject;
077        }
078        
079        
080        /**
081         * Returns {@code true} if redirection back to the OAuth 2.0 client
082         * with the error is disabled.
083         *
084         * @return {@code true} if redirection is disabled, {@code false} to
085         *         perform the regular redirection to {@code redirect_uri} with
086         *         the error.
087         */
088        public boolean isRedirectDisabled() {
089                return redirectDisabled;
090        }
091}