001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.oauth2.sdk; 019 020 021import java.net.URI; 022 023import com.nimbusds.oauth2.sdk.id.ClientID; 024import com.nimbusds.oauth2.sdk.id.State; 025 026 027/** 028 * The base class for checked exceptions defined in this SDK. 029 */ 030public class GeneralException extends Exception { 031 032 033 private static final long serialVersionUID = -1641787397301043615L; 034 035 036 /** 037 * The associated error, {@code null} if not specified. 038 */ 039 private final ErrorObject error; 040 041 042 /** 043 * The associated client identifier, {@code null} if not specified. 044 */ 045 private final ClientID clientID; 046 047 048 /** 049 * The redirection URI, {@code null} if not specified or redirection is 050 * not to be performed for this error. Implies a HTTP status code 302. 051 */ 052 private final URI redirectURI; 053 054 055 /** 056 * Optional response mode parameter, {@code null} if not specified. 057 */ 058 private final ResponseMode responseMode; 059 060 061 /** 062 * Optional state parameter, {@code null} if not specified. 063 */ 064 private final State state; 065 066 067 /** 068 * Creates a new general exception. 069 * 070 * @param message The exception message. May be {@code null}. 071 */ 072 public GeneralException(final String message) { 073 074 this(message, null, null, null, null, null, null); 075 } 076 077 078 /** 079 * Creates a new general exception. 080 * 081 * @param message The exception message. May be {@code null}. 082 * @param cause The exception cause, {@code null} if not specified. 083 */ 084 public GeneralException(final String message, final Throwable cause) { 085 086 this(message, null, null, null, null, null, cause); 087 } 088 089 090 /** 091 * Creates a new general exception. 092 * 093 * @param error The associated error. The error description, if 094 * specified, is used to set the exception message. Must 095 * not be {@code null}. 096 */ 097 public GeneralException(final ErrorObject error) { 098 099 this(error.getDescription(), error, null, null, null, null, null); 100 } 101 102 103 /** 104 * Creates a new general exception. 105 * 106 * @param message The exception message. May be {@code null}. 107 * @param error The associated error, {@code null} if not specified. 108 */ 109 public GeneralException(final String message, 110 final ErrorObject error) { 111 112 this(message, error, null, null, null, null, null); 113 } 114 115 116 /** 117 * Creates a new general exception. 118 * 119 * @param message The exception message. May be {@code null}. 120 * @param error The associated error, {@code null} if not specified. 121 * @param cause The exception cause, {@code null} if not specified. 122 */ 123 public GeneralException(final String message, 124 final ErrorObject error, 125 final Throwable cause) { 126 127 this(message, error, null, null, null, null, cause); 128 } 129 130 131 /** 132 * Creates a new general exception. 133 * 134 * @param message The exception message. May be {@code null}. 135 * @param error The associated error, {@code null} if not 136 * specified. 137 * @param clientID The associated client identifier, {@code null} if 138 * not specified. 139 * @param redirectURI The associated redirection URI, {@code null} if 140 * not specified. 141 * @param responseMode The optional associated response mode, 142 * {@code null} if not specified. 143 * @param state The optional associated state parameter, 144 * {@code null} if not specified. 145 */ 146 public GeneralException(final String message, 147 final ErrorObject error, 148 final ClientID clientID, 149 final URI redirectURI, 150 final ResponseMode responseMode, 151 final State state) { 152 153 this(message, error, clientID, redirectURI, responseMode, state, null); 154 } 155 156 157 /** 158 * Creates a new general exception. 159 * 160 * @param message The exception message. May be {@code null}. 161 * @param error The associated error, {@code null} if not 162 * specified. 163 * @param clientID The associated client identifier, {@code null} 164 * if not specified. 165 * @param redirectURI The associated redirection URI, {@code null} if 166 * not specified. 167 * @param state The optional associated state parameter, 168 * {@code null} if not specified. 169 * @param responseMode The optional associated response mode, 170 * {@code null} if not specified. 171 * @param cause The exception cause, {@code null} if not 172 * specified. 173 */ 174 public GeneralException(final String message, 175 final ErrorObject error, 176 final ClientID clientID, 177 final URI redirectURI, 178 final ResponseMode responseMode, 179 final State state, 180 final Throwable cause) { 181 182 super(message, cause); 183 184 this.error = error; 185 this.clientID = clientID; 186 this.redirectURI = redirectURI; 187 this.responseMode = responseMode; 188 this.state = state; 189 } 190 191 192 /** 193 * Gets the associated error. 194 * 195 * @return The error, {@code null} if not specified. 196 */ 197 public ErrorObject getErrorObject() { 198 199 return error; 200 } 201 202 203 /** 204 * Gets the associated client identifier. 205 * 206 * @return The client ID, {@code null} if not specified. 207 */ 208 public ClientID getClientID() { 209 210 return clientID; 211 } 212 213 214 /** 215 * Gets the associated redirection URI. 216 * 217 * @return The redirection URI, {@code null} if redirection is not to 218 * be performed for this error. 219 */ 220 public URI getRedirectionURI() { 221 222 return redirectURI; 223 } 224 225 226 /** 227 * Gets the associated response mode. 228 * 229 * @return The response mode, {@code null} if not specified. 230 */ 231 public ResponseMode getResponseMode() { 232 233 return responseMode; 234 } 235 236 237 /** 238 * Gets the optional associated state parameter. 239 * 240 * @return The optional state parameter, {@code null} if not specified 241 * or redirection is not to be performed. 242 */ 243 public State getState() { 244 245 return state; 246 } 247}