2 * Copyright (c) 2018 Inocybe Technologies 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 javax.servlet.ServletContext;
11 import org.apache.shiro.util.LifecycleUtils;
12 import org.apache.shiro.web.env.EnvironmentLoaderListener;
13 import org.apache.shiro.web.env.MutableWebEnvironment;
14 import org.apache.shiro.web.env.WebEnvironment;
15 import org.opendaylight.aaa.api.AuthenticationService;
16 import org.opendaylight.aaa.api.TokenStore;
17 import org.opendaylight.aaa.api.password.service.PasswordHashService;
18 import org.opendaylight.aaa.cert.api.ICertificateManager;
19 import org.opendaylight.aaa.shiro.tokenauthrealm.auth.TokenAuthenticators;
20 import org.opendaylight.mdsal.binding.api.DataBroker;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.app.config.rev170619.ShiroConfiguration;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Initializes shiro components for a web environment.
28 * @author Thomas Pantelis
30 public class ShiroWebEnvironmentLoaderListener extends EnvironmentLoaderListener {
31 private static final Logger LOG = LoggerFactory.getLogger(ShiroWebEnvironmentLoaderListener.class);
33 private final ShiroConfiguration shiroConfiguration;
34 private final DataBroker dataBroker;
35 private final ICertificateManager certificateManager;
36 private final AuthenticationService authenticationService;
37 private final TokenAuthenticators tokenAuthenticators;
38 private final TokenStore tokenStore;
39 private final PasswordHashService passwordHashService;
41 public ShiroWebEnvironmentLoaderListener(final ShiroConfiguration shiroConfiguration, final DataBroker dataBroker,
42 final ICertificateManager certificateManager,
43 final AuthenticationService authenticationService,
44 final TokenAuthenticators tokenAuthenticators, final TokenStore tokenStore,
45 final PasswordHashService passwordHashService) {
46 this.shiroConfiguration = shiroConfiguration;
47 this.dataBroker = dataBroker;
48 this.certificateManager = certificateManager;
49 this.authenticationService = authenticationService;
50 this.tokenAuthenticators = tokenAuthenticators;
51 this.tokenStore = tokenStore;
52 this.passwordHashService = passwordHashService;
53 LOG.debug("ShiroWebEnvironmentLoaderListenerImpl created");
57 protected WebEnvironment createEnvironment(final ServletContext sc) {
58 MutableWebEnvironment environment = new AAAIniWebEnvironment(shiroConfiguration, dataBroker,
59 certificateManager, authenticationService, tokenAuthenticators, tokenStore, passwordHashService);
61 // in newer Shiro version, there is a determineWebEnvironment() which should be
62 // used instead of createEnvironment() but for 1.3.x we just copy/paste from parent and do:
63 environment.setServletContext(sc);
64 customizeEnvironment(environment);
65 LifecycleUtils.init(environment);