Skip to content

Commit

Permalink
Authentication and Authorization exceptions (401 and 403)
Browse files Browse the repository at this point in the history
  • Loading branch information
revetkn committed May 24, 2015
1 parent 18a2899 commit 5a0fe0e
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2015 Transmogrify LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.soklet.web.exception;

/**
* Indicates that the requested URL requires authentication.
* <p>
* This normally corresponds to an HTTP {@code 401} response.
*
* @author <a href="http://revetkn.com">Mark Allen</a>
* @since 1.1.0
*/
public class AuthenticationException extends RuntimeException {
public AuthenticationException() {
super();
}

public AuthenticationException(String message) {
super(message);
}

public AuthenticationException(Throwable cause) {
super(cause);
}

public AuthenticationException(String message, Throwable cause) {
super(message, cause);
}
}
49 changes: 49 additions & 0 deletions src/main/java/com/soklet/web/exception/AuthorizationException.java
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2015 Transmogrify LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.soklet.web.exception;

/**
* Indicates that the requested URL requires authorization.
* <p>
* This normally corresponds to an HTTP {@code 403} response.
*
* @author <a href="http://revetkn.com">Mark Allen</a>
* @since 1.1.0
*/
public class AuthorizationException extends RuntimeException {
public AuthorizationException() {
super();
}

public AuthorizationException(String message) {
super(message);
}

public AuthorizationException(Throwable cause) {
super(cause);
}

public AuthorizationException(String message, Throwable cause) {
super(message, cause);
}
}
Expand Up @@ -35,6 +35,10 @@ public int statusForException(Exception exception) {

if (exception instanceof BadRequestException)
return 400;
if (exception instanceof AuthenticationException)
return 401;
if (exception instanceof AuthorizationException)
return 403;
if (exception instanceof NotFoundException)
return 404;
if (exception instanceof MethodNotAllowedException)
Expand Down
Expand Up @@ -28,7 +28,7 @@
* This normally corresponds to an HTTP {@code 404} response.
*
* @author <a href="http://revetkn.com">Mark Allen</a>
* @since 1.0.3
* @since 1.1.0
*/
public class NotFoundException extends RuntimeException {
public NotFoundException() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/soklet/web/request/RequestContext.java
Expand Up @@ -34,7 +34,7 @@

/**
* @author <a href="http://revetkn.com">Mark Allen</a>
* @since 1.0.3
* @since 1.1.0
*/
public class RequestContext {
private static final ThreadLocal<RequestContext> REQUEST_CONTEXT_HOLDER = new ThreadLocal<>();
Expand Down

0 comments on commit 5a0fe0e

Please sign in to comment.