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        /**
034         * The associated error, {@code null} if not specified.
035         */
036        private final ErrorObject error;
037
038
039        /**
040         * The associated client identifier, {@code null} if not specified.
041         */
042        private final ClientID clientID;
043
044
045        /**
046         * The redirection URI, {@code null} if not specified or redirection is
047         * not to be performed for this error. Implies a HTTP status code 302.
048         */
049        private final URI redirectURI;
050
051
052        /**
053         * Optional response mode parameter, {@code null} if not specified.
054         */
055        private final ResponseMode responseMode;
056
057
058        /**
059         * Optional state parameter, {@code null} if not specified.
060         */
061        private final State state;
062
063
064        /**
065         * Creates a new general exception.
066         *
067         * @param message The exception message. May be {@code null}.
068         */
069        public GeneralException(final String message) {
070        
071                this(message, null, null, null, null, null, null);
072        }
073        
074        
075        /**
076         * Creates a new general exception.
077         *
078         * @param message The exception message. May be {@code null}.
079         * @param cause   The exception cause, {@code null} if not specified.
080         */
081        public GeneralException(final String message, final Throwable cause) {
082        
083                this(message, null, null, null, null, null, cause);
084        }
085
086
087        /**
088         * Creates a new general exception.
089         *
090         * @param error The associated error. The error description, if
091         *              specified, is used to set the exception message. Must
092         *              not be {@code null}.
093         */
094        public GeneralException(final ErrorObject error) {
095
096                this(error.getDescription(), error, null, null, null, null, null);
097        }
098
099
100        /**
101         * Creates a new general exception.
102         *
103         * @param message The exception message. May be {@code null}.
104         * @param error   The associated error, {@code null} if not specified.
105         */
106        public GeneralException(final String message,
107                                final ErrorObject error) {
108
109                this(message, error, null, null, null, null, null);
110        }
111
112
113        /**
114         * Creates a new general exception.
115         *
116         * @param message The exception message. May be {@code null}.
117         * @param error   The associated error, {@code null} if not specified.
118         * @param cause   The exception cause, {@code null} if not specified.
119         */
120        public GeneralException(final String message, 
121                                final ErrorObject error,
122                                final Throwable cause) {
123        
124                this(message, error, null, null, null, null, cause);
125        }
126        
127        
128        /**
129         * Creates a new general exception.
130         *
131         * @param message      The exception message. May be {@code null}.
132         * @param error        The associated error, {@code null} if not
133         *                     specified.
134         * @param clientID     The associated client identifier, {@code null} if
135         *                     not specified.
136         * @param redirectURI  The associated redirection URI, {@code null} if
137         *                     not specified.
138         * @param responseMode The optional associated response mode,
139         *                     {@code null} if not specified.
140         * @param state        The optional associated state parameter,
141         *                     {@code null} if not specified.
142         */
143        public GeneralException(final String message, 
144                                final ErrorObject error,
145                                final ClientID clientID,
146                                final URI redirectURI,
147                                final ResponseMode responseMode,
148                                final State state) {
149        
150                this(message, error, clientID, redirectURI, responseMode, state, null);
151        }
152
153
154        /**
155         * Creates a new general exception.
156         *
157         * @param message      The exception message. May be {@code null}.
158         * @param error        The associated error, {@code null} if not
159         *                     specified.
160         * @param clientID     The associated client identifier, {@code null}
161         *                     if not specified.
162         * @param redirectURI  The associated redirection URI, {@code null} if
163         *                     not specified.
164         * @param state        The optional associated state parameter,
165         *                     {@code null} if not specified.
166         * @param responseMode The optional associated response mode,
167         *                     {@code null} if not specified.
168         * @param cause        The exception cause, {@code null} if not
169         *                     specified.
170         */
171        public GeneralException(final String message, 
172                                final ErrorObject error,
173                                final ClientID clientID,
174                                final URI redirectURI,
175                                final ResponseMode responseMode,
176                                final State state,
177                                final Throwable cause) {
178        
179                super(message, cause);
180
181                this.error = error;
182                this.clientID = clientID;
183                this.redirectURI = redirectURI;
184                this.responseMode = responseMode;
185                this.state = state;
186        }
187
188
189        /**
190         * Gets the associated error.
191         *
192         * @return The error, {@code null} if not specified.
193         */
194        public ErrorObject getErrorObject() {
195
196                return error;
197        }
198
199
200        /**
201         * Gets the associated client identifier.
202         *
203         * @return The client ID, {@code null} if not specified.
204         */
205        public ClientID getClientID() {
206
207                return clientID;
208        }
209
210
211        /**
212         * Gets the associated redirection URI.
213         *
214         * @return The redirection URI, {@code null} if redirection is not to
215         *         be performed for this error.
216         */
217        public URI getRedirectionURI() {
218
219                return redirectURI;
220        }
221
222
223        /**
224         * Gets the associated response mode.
225         *
226         * @return The response mode, {@code null} if not specified.
227         */
228        public ResponseMode getResponseMode() {
229
230                return responseMode;
231        }
232
233
234        /**
235         * Gets the optional associated state parameter.
236         *
237         * @return The optional state parameter, {@code null} if not specified 
238         *         or redirection is not to be performed.
239         */
240        public State getState() {
241
242                return state;
243        }
244}