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.neutron.northbound.api;
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.web.ServletDetails;
15 import org.opendaylight.aaa.web.WebContext;
16 import org.opendaylight.aaa.web.WebContextBuilder;
17 import org.opendaylight.aaa.web.WebContextRegistration;
18 import org.opendaylight.aaa.web.WebContextSecurer;
19 import org.opendaylight.aaa.web.WebServer;
20 import org.opendaylight.aaa.web.servlet.ServletSupport;
23 * Initializer for web components.
25 * @author Michael Vorburger.ch
28 public class WebInitializer {
30 private final WebContextRegistration registraton;
33 public WebInitializer(WebServer webServer, WebContextSecurer webContextSecurer, ServletSupport servletSupport,
34 NeutronNorthboundRSApplication app) throws ServletException {
35 WebContextBuilder webContextBuilder = WebContext.builder()
36 .contextPath("/controller/nb/v2/neutron").supportsSessions(true)
37 // TODO confirm through testing that Jersey & Neutron are fine without sessions, and false instead true
39 .addServlet(ServletDetails.builder()
40 .servlet(servletSupport.createHttpServletBuilder(app).build())
41 .addUrlPattern("/*").build());
43 webContextSecurer.requireAuthentication(webContextBuilder, "/*");
45 this.registraton = webServer.registerWebContext(webContextBuilder.build());