Skip to content

Package: SelfManagedOnlyExceptionMapper

SelfManagedOnlyExceptionMapper

nameinstructionbranchcomplexitylinemethod
SelfManagedOnlyExceptionMapper()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toResponse(SelfManagedOnlyException)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.app.api.core.exception;
14:
15: import org.eclipse.kapua.app.api.core.exception.model.SelfManagedOnlyExceptionInfo;
16: import org.eclipse.kapua.service.authorization.shiro.exception.SelfManagedOnlyException;
17: import org.slf4j.Logger;
18: import org.slf4j.LoggerFactory;
19:
20: import javax.ws.rs.core.Response;
21: import javax.ws.rs.core.Response.Status;
22: import javax.ws.rs.ext.ExceptionMapper;
23: import javax.ws.rs.ext.Provider;
24:
25: @Provider
26: public class SelfManagedOnlyExceptionMapper implements ExceptionMapper<SelfManagedOnlyException> {
27:
28: private static final Logger LOG = LoggerFactory.getLogger(SelfManagedOnlyExceptionMapper.class);
29:
30: @Override
31: public Response toResponse(SelfManagedOnlyException exception) {
32: LOG.error("Only self managed allowed!", exception);
33: return Response//
34: .status(Status.FORBIDDEN) //
35: .entity(new SelfManagedOnlyExceptionInfo(Status.FORBIDDEN, exception)) //
36: .build();
37: }
38: }