From 00f83ee3a73d5ce5384ca3b18efd1a4acbc291b1 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Sat, 2 May 2015 00:19:04 +1200 Subject: [PATCH] Fix #169 - Add an exception for HTTP 403 Forbidden error --- .../ca/uhn/fhir/rest/server/Constants.java | 1 + .../BaseServerResponseException.java | 1 + .../ForbiddenOperationException.java | 59 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ForbiddenOperationException.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java index fcd5529d7b5..c381680c19e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java @@ -113,6 +113,7 @@ public class Constants { public static final int STATUS_HTTP_304_NOT_MODIFIED = 304; public static final int STATUS_HTTP_400_BAD_REQUEST = 400; public static final int STATUS_HTTP_401_CLIENT_UNAUTHORIZED = 401; + public static final int STATUS_HTTP_403_FORBIDDEN= 403; public static final int STATUS_HTTP_404_NOT_FOUND = 404; public static final int STATUS_HTTP_405_METHOD_NOT_ALLOWED = 405; public static final int STATUS_HTTP_409_CONFLICT = 409; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java index f63f8214d64..ce21d4d06aa 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java @@ -50,6 +50,7 @@ public abstract class BaseServerResponseException extends RuntimeException { registerExceptionType(PreconditionFailedException.STATUS_CODE, PreconditionFailedException.class); registerExceptionType(ResourceVersionConflictException.STATUS_CODE, ResourceVersionConflictException.class); registerExceptionType(UnprocessableEntityException.STATUS_CODE, UnprocessableEntityException.class); + registerExceptionType(ForbiddenOperationException.STATUS_CODE, ForbiddenOperationException.class); } private List myAdditionalMessages = null; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ForbiddenOperationException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ForbiddenOperationException.java new file mode 100644 index 00000000000..6696e8bbde2 --- /dev/null +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ForbiddenOperationException.java @@ -0,0 +1,59 @@ +package ca.uhn.fhir.rest.server.exceptions; + +import ca.uhn.fhir.model.base.resource.BaseOperationOutcome; +import ca.uhn.fhir.rest.server.Constants; + +/* + * #%L + * HAPI FHIR - Core Library + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * This Represents an HTTP 403 Forbidden response, which generally indicates one of two conditions: + * + * + *

+ * Note that a complete list of RESTful exceptions is available in the Package + * Summary. + *

+ */ +public class ForbiddenOperationException extends BaseServerResponseException { + + public static final int STATUS_CODE = Constants.STATUS_HTTP_403_FORBIDDEN; + private static final long serialVersionUID = 1L; + + public ForbiddenOperationException(String theMessage) { + super(STATUS_CODE, theMessage); + } + + /** + * Constructor + * + * @param theMessage + * The message + * @param theOperationOutcome + * The OperationOutcome resource to return to the client + */ + public ForbiddenOperationException(String theMessage, BaseOperationOutcome theOperationOutcome) { + super(STATUS_CODE, theMessage, theOperationOutcome); + } + +}