2 * Copyright (c) 2018 Red Hat, 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 javax.annotation.PreDestroy;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import javax.servlet.ServletException;
14 import org.opendaylight.aaa.api.ClaimCache;
15 import org.opendaylight.aaa.api.IIDMStore;
16 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
17 import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter;
18 import org.opendaylight.aaa.shiro.idm.IdmLightApplication;
19 import org.opendaylight.aaa.web.FilterDetails;
20 import org.opendaylight.aaa.web.ServletDetails;
21 import org.opendaylight.aaa.web.WebContext;
22 import org.opendaylight.aaa.web.WebContextSecurer;
23 import org.opendaylight.aaa.web.WebServer;
24 import org.opendaylight.aaa.web.servlet.ServletSupport;
25 import org.opendaylight.yangtools.concepts.Registration;
28 * Initializer for web components.
29 * This class is the equivalent of a declarative web.xml,
30 * and is not OSGi specific; it can also be used e.g. in standalone
31 * Java environments, such as tests.
33 * @author Michael Vorburger.ch
36 public class WebInitializer {
37 private final Registration registraton;
40 public WebInitializer(final WebServer webServer, final ClaimCache claimCache, final IIDMStore iidMStore,
41 final WebContextSecurer webContextSecurer, final ServletSupport servletSupport,
42 final CustomFilterAdapterConfiguration customFilterAdapterConfig) throws ServletException {
44 final var webContextBuilder = WebContext.builder()
45 .name("OpenDaylight IDM realm management")
47 .supportsSessions(true)
49 .addServlet(ServletDetails.builder()
50 .servlet(servletSupport.createHttpServletBuilder(new IdmLightApplication(iidMStore, claimCache))
55 // Allows user to add javax.servlet.Filter(s) in front of REST services
56 .addFilter(FilterDetails.builder()
57 .filter(new CustomFilterAdapter(customFilterAdapterConfig))
61 webContextSecurer.requireAuthentication(webContextBuilder, "/*", "/moon/*");
63 registraton = webServer.registerWebContext(webContextBuilder.build());