Inject ServletSupport into MoonRealm
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / shiro / web / env / ShiroWebEnvironmentLoaderListener.java
1 /*
2  * Copyright (c) 2018 Inocybe Technologies and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.aaa.shiro.web.env;
9
10 import javax.servlet.ServletContext;
11 import org.apache.shiro.web.env.EnvironmentLoaderListener;
12 import org.apache.shiro.web.env.WebEnvironment;
13 import org.opendaylight.aaa.api.AuthenticationService;
14 import org.opendaylight.aaa.api.TokenStore;
15 import org.opendaylight.aaa.api.password.service.PasswordHashService;
16 import org.opendaylight.aaa.cert.api.ICertificateManager;
17 import org.opendaylight.aaa.tokenauthrealm.auth.TokenAuthenticators;
18 import org.opendaylight.aaa.web.servlet.ServletSupport;
19 import org.opendaylight.mdsal.binding.api.DataBroker;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.app.config.rev170619.ShiroConfiguration;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Initializes shiro components for a web environment.
26  *
27  * @author Thomas Pantelis
28  */
29 // FIXME: @WebListener and CDI (or whatever) injection?
30 // FIXME: @Component with ServletContextListener
31 public final class ShiroWebEnvironmentLoaderListener extends EnvironmentLoaderListener {
32     private static final Logger LOG = LoggerFactory.getLogger(ShiroWebEnvironmentLoaderListener.class);
33
34     private final ShiroConfiguration shiroConfiguration;
35     private final DataBroker dataBroker;
36     private final ICertificateManager certificateManager;
37     private final AuthenticationService authenticationService;
38     private final TokenAuthenticators tokenAuthenticators;
39     private final TokenStore tokenStore;
40     private final PasswordHashService passwordHashService;
41     private final ServletSupport servletSupport;
42
43     // FIXME: @Inject for CDI, except we have ShiroConfiguration injected
44     // FIXME: @Activate for OSGi @Component
45     // Both of these have problem with how do we inject ShiroConfiguration?
46     public ShiroWebEnvironmentLoaderListener(final ShiroConfiguration shiroConfiguration, final DataBroker dataBroker,
47                                              final ICertificateManager certificateManager,
48                                              final AuthenticationService authenticationService,
49                                              final TokenAuthenticators tokenAuthenticators, final TokenStore tokenStore,
50                                              final PasswordHashService passwordHashService,
51                                              final ServletSupport servletSupport) {
52         this.shiroConfiguration = shiroConfiguration;
53         this.dataBroker = dataBroker;
54         this.certificateManager = certificateManager;
55         this.authenticationService = authenticationService;
56         this.tokenAuthenticators = tokenAuthenticators;
57         this.tokenStore = tokenStore;
58         this.passwordHashService = passwordHashService;
59         this.servletSupport = servletSupport;
60         LOG.debug("ShiroWebEnvironmentLoaderListenerImpl created");
61     }
62
63     @Override
64     protected WebEnvironment determineWebEnvironment(final ServletContext servletContext) {
65         return new AAAIniWebEnvironment(shiroConfiguration, dataBroker, certificateManager, authenticationService,
66             tokenAuthenticators, tokenStore, passwordHashService, servletSupport);
67     }
68 }