Skip to content

Package: InitShiro

InitShiro

nameinstructionbranchcomplexitylinemethod
InitShiro()
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%
start()
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 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%
stop()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 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.qa.common.utils;
14:
15: import java.io.IOException;
16: import java.io.InputStream;
17: import java.net.URL;
18:
19: import org.apache.shiro.SecurityUtils;
20: import org.apache.shiro.UnavailableSecurityManagerException;
21: import org.apache.shiro.config.Ini;
22: import org.apache.shiro.config.IniSecurityManagerFactory;
23: import org.apache.shiro.mgt.SecurityManager;
24: import org.slf4j.Logger;
25: import org.slf4j.LoggerFactory;
26:
27: import cucumber.api.java.en.Given;
28: import cucumber.runtime.java.guice.ScenarioScoped;
29:
30: @ScenarioScoped
31: public class InitShiro {
32:
33: private static final Logger logger = LoggerFactory.getLogger(InitShiro.class);
34:
35: @Given("^Init Security Context$")
36: public void start() throws IOException {
37: try {
38: SecurityManager securityManager = SecurityUtils.getSecurityManager();
39: logger.info("Found Shiro security manager {}", securityManager);
40: }
41: catch (UnavailableSecurityManagerException e) {
42: logger.info("Init shiro security manager...");
43: final URL shiroIniUrl = getClass().getResource("/shiro.ini");
44: Ini shiroIni = new Ini();
45: try (final InputStream input = shiroIniUrl.openStream()) {
46: shiroIni.load(input);
47: }
48: SecurityManager securityManager = new IniSecurityManagerFactory(shiroIni).getInstance();
49: SecurityUtils.setSecurityManager(securityManager);
50: logger.info("Init shiro security manager... DONE");
51: }
52: }
53:
54: @Given("^Reset Security Context$")
55: public void stop() {
56: SecurityUtils.setSecurityManager(null);
57: }
58:
59: }