2 * Copyright (c) 2015 - 2017 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.aaa.shiro.web.env;
10 import java.util.concurrent.ExecutionException;
11 import java.util.function.Supplier;
12 import org.apache.shiro.config.Ini;
13 import org.apache.shiro.web.env.IniWebEnvironment;
14 import org.opendaylight.aaa.AAAShiroProvider;
15 import org.opendaylight.yangtools.util.ClassLoaderUtils;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Identical to <code>IniWebEnvironment</code> except the Ini is loaded from
21 * <code>${KARAF_HOME}/etc/shiro.ini</code>, and setting the TCCL (x2) so that
22 * loading of classes by name (from aaa-app-config.xml) works even with
23 * ShiroWebContextSecurer.
25 * @deprecated in favor of {@link AAAIniWebEnvironment}. This class is kept for compatibility for other projects that
26 * reference it in a web.xml file where it's instantiated via reflection and the dependencies must be
27 * accessed statically.
30 public class KarafIniWebEnvironment extends IniWebEnvironment {
32 private static final Logger LOG = LoggerFactory.getLogger(KarafIniWebEnvironment.class);
34 public KarafIniWebEnvironment() {
35 LOG.info("Initializing the Web Environment using {}", KarafIniWebEnvironment.class.getName());
41 AAAShiroProvider provider = AAAShiroProvider.INSTANCE_FUTURE.get();
43 ThreadLocals.DATABROKER_TL.set(provider.getDataBroker());
44 ThreadLocals.CERT_MANAGER_TL.set(provider.getCertificateManager());
45 ThreadLocals.AUTH_SETVICE_TL.set(provider.getAuthenticationService());
46 ThreadLocals.TOKEN_AUTHENICATORS_TL.set(provider.getTokenAuthenticators());
47 ThreadLocals.TOKEN_STORE_TL.set(provider.getTokenStore());
48 ThreadLocals.PASSWORD_HASH_SERVICE_TL.set(provider.getPasswordHashService());
50 // Initialize the Shiro environment from clustered-app-config
51 final Ini ini = AAAIniWebEnvironment.createIniFromClusteredAppConfig(provider.getShiroConfiguration());
53 ClassLoaderUtils.withClassLoader(KarafIniWebEnvironment.class.getClassLoader(), (Supplier<Void>) () -> {
57 } catch (InterruptedException | ExecutionException e) {
58 throw new RuntimeException("Error obtaining AAAShiroProvider", e);
60 ThreadLocals.DATABROKER_TL.remove();
61 ThreadLocals.CERT_MANAGER_TL.remove();
62 ThreadLocals.AUTH_SETVICE_TL.remove();
63 ThreadLocals.TOKEN_AUTHENICATORS_TL.remove();
64 ThreadLocals.TOKEN_STORE_TL.remove();
65 ThreadLocals.PASSWORD_HASH_SERVICE_TL.remove();