Skip to content

Package: DefaultAuthorizer

DefaultAuthorizer

nameinstructionbranchcomplexitylinemethod
DefaultAuthorizer()
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%
isAdminAllowed(KapuaSecurityContext, ActiveMQDestination)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
isAllowed(Authorizer.ActionType, KapuaSecurityContext, ActiveMQDestination)
M: 22 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
isConsumeAllowed(KapuaSecurityContext, ActiveMQDestination)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
isSendAllowed(KapuaSecurityContext, ActiveMQDestination)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 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.broker.core.plugin.authorization;
14:
15: import java.util.Set;
16:
17: import org.apache.activemq.command.ActiveMQDestination;
18: import org.eclipse.kapua.KapuaException;
19: import org.eclipse.kapua.broker.core.plugin.KapuaSecurityContext;
20:
21: /**
22: * Default authorizer implementation.
23: *
24: */
25: public class DefaultAuthorizer implements Authorizer {
26:
27: @Override
28: public boolean isAllowed(ActionType actionType, KapuaSecurityContext kapuaSecurityContext, ActiveMQDestination destination) throws KapuaException {
29:• switch (actionType) {
30: case READ:
31: return isConsumeAllowed(kapuaSecurityContext, destination);
32: case WRITE:
33: return isSendAllowed(kapuaSecurityContext, destination);
34: case ADMIN:
35: return isAdminAllowed(kapuaSecurityContext, destination);
36: default:
37: return false;
38: }
39: }
40:
41: protected boolean isSendAllowed(KapuaSecurityContext kapuaSecurityContext, ActiveMQDestination destination) throws KapuaException {
42: Set<?> allowedACLs = kapuaSecurityContext.getAuthorizationMap().getWriteACLs(destination);
43:• if (allowedACLs != null && !kapuaSecurityContext.isInOneOf(allowedACLs)) {
44: return false;
45: }
46: return true;
47: }
48:
49: protected boolean isConsumeAllowed(KapuaSecurityContext kapuaSecurityContext, ActiveMQDestination destination) throws KapuaException {
50: Set<?> allowedACLs = kapuaSecurityContext.getAuthorizationMap().getReadACLs(destination);
51:• if (allowedACLs != null && !kapuaSecurityContext.isInOneOf(allowedACLs)) {
52: return false;
53: }
54: return true;
55: }
56:
57: protected boolean isAdminAllowed(KapuaSecurityContext kapuaSecurityContext, ActiveMQDestination destination) throws KapuaException {
58: Set<?> allowedACLs = kapuaSecurityContext.getAuthorizationMap().getAdminACLs(destination);
59:• if (allowedACLs != null && !kapuaSecurityContext.isInOneOf(allowedACLs)) {
60: return false;
61: }
62: return true;
63: }
64: }