001package com.nimbusds.oauth2.sdk; 002 003 004import java.net.URL; 005 006import com.nimbusds.oauth2.sdk.id.ClientID; 007import com.nimbusds.oauth2.sdk.id.State; 008 009 010/** 011 * The base class for exceptions defined in this SDK. 012 */ 013public class GeneralException extends Exception { 014 015 016 /** 017 * The associated error, {@code null} if not specified. 018 */ 019 private final ErrorObject error; 020 021 022 /** 023 * The associated client identifier, {@code null} if not specified. 024 */ 025 private final ClientID clientID; 026 027 028 /** 029 * The redirection URI, {@code null} if not specified or redirection is 030 * not to be performed for this error. Implies a HTTP status code 302. 031 */ 032 private final URL redirectURI; 033 034 035 /** 036 * Optional state parameter, {@code null} if not specified. 037 */ 038 private final State state; 039 040 041 /** 042 * Creates a new general exception. 043 * 044 * @param message The exception message. May be {@code null}. 045 */ 046 public GeneralException(final String message) { 047 048 this(message, null, null, null, null, null); 049 } 050 051 052 /** 053 * Creates a new general exception. 054 * 055 * @param message The exception message. May be {@code null}. 056 * @param cause The exception cause, {@code null} if not specified. 057 */ 058 public GeneralException(final String message, final Throwable cause) { 059 060 this(message, null, null, null, null, cause); 061 } 062 063 064 /** 065 * Creates a new general exception. 066 * 067 * @param message The exception message. May be {@code null}. 068 * @param error The associated error, {@code null} if not specified. 069 */ 070 public GeneralException(final String message, 071 final ErrorObject error) { 072 073 this(message, error, null, null, null, null); 074 } 075 076 077 /** 078 * Creates a new general exception. 079 * 080 * @param message The exception message. May be {@code null}. 081 * @param error The associated error, {@code null} if not specified. 082 * @param cause The exception cause, {@code null} if not specified. 083 */ 084 public GeneralException(final String message, 085 final ErrorObject error, 086 final Throwable cause) { 087 088 this(message, error, null, null, null, cause); 089 } 090 091 092 /** 093 * Creates a new general exception. 094 * 095 * @param message The exception message. May be {@code null}. 096 * @param error The associated error, {@code null} if not 097 * specified. 098 * @param clientID The associated client identifier, {@code null} if 099 * not specified. 100 * @param redirectURI The associated redirection URI, {@code null} if 101 * not specified. 102 * @param state The optional associated state parameter, 103 * {@code null} if not specified. 104 */ 105 public GeneralException(final String message, 106 final ErrorObject error, 107 final ClientID clientID, 108 final URL redirectURI, 109 final State state) { 110 111 this(message, error, clientID, redirectURI, state, null); 112 } 113 114 115 /** 116 * Creates a new general exception. 117 * 118 * @param message The exception message. May be {@code null}. 119 * @param error The associated error, {@code null} if not 120 * specified. 121 * @param clientID The associated client identifier, {@code null} if 122 * not specified. 123 * @param redirectURI The associated redirection URI, {@code null} if 124 * not specified. 125 * @param state The optional associated state parameter, 126 * {@code null} if not specified. 127 * @param cause The exception cause, {@code null} if not 128 * specified. 129 */ 130 public GeneralException(final String message, 131 final ErrorObject error, 132 final ClientID clientID, 133 final URL redirectURI, 134 final State state, 135 final Throwable cause) { 136 137 super(message, cause); 138 139 this.error = error; 140 this.clientID = clientID; 141 this.redirectURI = redirectURI; 142 this.state = state; 143 } 144 145 146 /** 147 * Gets the associated error. 148 * 149 * @return The error, {@code null} if not specified. 150 */ 151 public ErrorObject getErrorObject() { 152 153 return error; 154 } 155 156 157 /** 158 * Gets the associated client identifier. 159 * 160 * @return The client ID, {@code null} if not specified. 161 */ 162 public ClientID getClientID() { 163 164 return clientID; 165 } 166 167 168 /** 169 * Gets the associated redirection URI. 170 * 171 * @return The redirection URI, {@code null} if redirection is not to 172 * be performed for this error. 173 */ 174 public URL getRedirectionURI() { 175 176 return redirectURI; 177 } 178 179 180 /** 181 * Gets the optional associated state parameter. 182 * 183 * @return The optional state parameter, {@code null} if not specified 184 * or redirection is not to be performed. 185 */ 186 public State getState() { 187 188 return state; 189 } 190}