34ede37f7a23643d4638500b7084d8f2a946442d
[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.mdsal.binding.api.DataBroker;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.app.config.rev170619.ShiroConfiguration;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * Initializes shiro components for a web environment.
25  *
26  * @author Thomas Pantelis
27  */
28 // FIXME: @WebListener and CDI (or whatever) injection?
29 // FIXME: @Component with ServletContextListener
30 public final class ShiroWebEnvironmentLoaderListener extends EnvironmentLoaderListener {
31     private static final Logger LOG = LoggerFactory.getLogger(ShiroWebEnvironmentLoaderListener.class);
32
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;
40
41     // FIXME: @Inject for CDI, except we have ShiroConfiguration injected
42     // FIXME: @Activate for OSGi @Component
43     // Both of these have problem with how do we inject ShiroConfiguration?
44     public ShiroWebEnvironmentLoaderListener(final ShiroConfiguration shiroConfiguration, final DataBroker dataBroker,
45                                              final ICertificateManager certificateManager,
46                                              final AuthenticationService authenticationService,
47                                              final TokenAuthenticators tokenAuthenticators, final TokenStore tokenStore,
48                                              final PasswordHashService passwordHashService) {
49         this.shiroConfiguration = shiroConfiguration;
50         this.dataBroker = dataBroker;
51         this.certificateManager = certificateManager;
52         this.authenticationService = authenticationService;
53         this.tokenAuthenticators = tokenAuthenticators;
54         this.tokenStore = tokenStore;
55         this.passwordHashService = passwordHashService;
56         LOG.debug("ShiroWebEnvironmentLoaderListenerImpl created");
57     }
58
59     @Override
60     protected WebEnvironment determineWebEnvironment(final ServletContext servletContext) {
61         return new AAAIniWebEnvironment(shiroConfiguration, dataBroker, certificateManager, authenticationService,
62             tokenAuthenticators, tokenStore, passwordHashService);
63     }
64 }