Skip to content

Package: KapuaBrokerSecurityPlugin

KapuaBrokerSecurityPlugin

nameinstructionbranchcomplexitylinemethod
KapuaBrokerSecurityPlugin()
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%
installPlugin(Broker)
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 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%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 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: * Red Hat Inc
13: *******************************************************************************/
14: package org.eclipse.kapua.broker.core;
15:
16: import java.io.InputStream;
17: import java.net.URL;
18:
19: import org.eclipse.kapua.broker.core.plugin.KapuaSecurityBrokerFilter;
20:
21: import org.apache.activemq.broker.Broker;
22: import org.apache.activemq.broker.BrokerPlugin;
23: import org.apache.shiro.SecurityUtils;
24: import org.apache.shiro.config.Ini;
25: import org.apache.shiro.config.IniSecurityManagerFactory;
26: import org.apache.shiro.mgt.SecurityManager;
27: import org.slf4j.Logger;
28: import org.slf4j.LoggerFactory;
29:
30: /**
31: * Install {@link KapuaSecurityBrokerFilter} into activeMQ filter chain plugin.<BR>
32: * <p>
33: * Is called by activeMQ broker by configuring plugin tag inside broker tag into activemq.xml.<BR>
34: * <BR>
35: * <BR>
36: * <p>
37: * <pre>
38: * <plugins>
39: * <bean xmlns="http://www.springframework.org/schema/beans" id="kapuaFilter" class="org.eclipse.kapua.broker.core.KapuaSecurityBrokerFilter"/>
40: * </plugins>
41: * </pre>
42: *
43: * @since 1.0
44: */
45: public class KapuaBrokerSecurityPlugin implements BrokerPlugin {
46:
47: private static final Logger logger = LoggerFactory.getLogger(KapuaBrokerSecurityPlugin.class);
48:
49: @Override
50: public Broker installPlugin(final Broker broker) throws Exception {
51: logger.info("Installing Kapua broker plugin...");
52:
53: try {
54: // initialize shiro context for broker plugin from shiro ini file
55: final URL shiroIniUrl = getClass().getResource("/shiro.ini");
56: Ini shiroIni = new Ini();
57: try (final InputStream input = shiroIniUrl.openStream()) {
58: shiroIni.load(input);
59: }
60:
61: SecurityManager securityManager = new IniSecurityManagerFactory(shiroIni).getInstance();
62: SecurityUtils.setSecurityManager(securityManager);
63:
64: // install the filters
65: return new KapuaSecurityBrokerFilter(broker);
66: } catch (Exception e) {
67: logger.error("Error in plugin installation.", e);
68: throw new SecurityException(e);
69: }
70: }
71:
72: }