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