| 1 | /** | |
| 2 |    Copyright 2018 Carlos Macasaet | |
| 3 | ||
| 4 |    Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 |    you may not use this file except in compliance with the License. | |
| 6 |    You may obtain a copy of the License at | |
| 7 | ||
| 8 |        https://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | ||
| 10 |    Unless required by applicable law or agreed to in writing, software | |
| 11 |    distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 |    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 |    See the License for the specific language governing permissions and | |
| 14 |    limitations under the License. | |
| 15 |  */ | |
| 16 | package com.macasaet.fernet.jaxrs.exception; | |
| 17 | ||
| 18 | import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE; | |
| 19 | import static javax.ws.rs.core.Response.status; | |
| 20 | import static javax.ws.rs.core.Response.Status.FORBIDDEN; | |
| 21 | ||
| 22 | import javax.ws.rs.NotAuthorizedException; | |
| 23 | import javax.ws.rs.core.Response; | |
| 24 | import javax.ws.rs.ext.ExceptionMapper; | |
| 25 | import javax.ws.rs.ext.Provider; | |
| 26 | ||
| 27 | import com.macasaet.fernet.PayloadValidationException; | |
| 28 | import com.macasaet.fernet.TokenValidationException; | |
| 29 | ||
| 30 | /** | |
| 31 |  * An {@link ExceptionMapper} that translates Fernet token validation exceptions into HTTP semantics. | |
| 32 |  * | |
| 33 |  * <p>Copyright © 2018 Carlos Macasaet.</p> | |
| 34 |  * | |
| 35 |  * @author Carlos Macasaet | |
| 36 |  */ | |
| 37 | @Provider | |
| 38 | @SuppressWarnings("PMD.LawOfDemeter") | |
| 39 | public class TokenValidationExceptionMapper implements ExceptionMapper<TokenValidationException> { | |
| 40 | ||
| 41 |     public Response toResponse(final TokenValidationException exception) { | |
| 42 | 
1
1. toResponse : negated conditional → KILLED | 
        if (exception instanceof PayloadValidationException) { | 
| 43 | 
1
1. toResponse : mutated return of Object value for com/macasaet/fernet/jaxrs/exception/TokenValidationExceptionMapper::toResponse to ( if (x != null) null else throw new RuntimeException ) → KILLED | 
            return status(FORBIDDEN).entity("Request could not be validated.").type(TEXT_PLAIN_TYPE).build(); | 
| 44 |         } | |
| 45 | 
1
1. toResponse : mutated return of Object value for com/macasaet/fernet/jaxrs/exception/TokenValidationExceptionMapper::toResponse to ( if (x != null) null else throw new RuntimeException ) → KILLED | 
        return new NotAuthorizedException("Bearer error=\"invalid_token\"").getResponse(); | 
| 46 |     } | |
| 47 | ||
| 48 | } | |
Mutations | ||
| 42 | 
 
 1.1  | 
|
| 43 | 
 
 1.1  | 
|
| 45 | 
 
 1.1  |