Bump upstream versions
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / WebInitializer.java
1 /*
2  * Copyright (c) 2018 Red Hat, Inc. 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.neutron.northbound.api;
9
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;
21
22 /**
23  * Initializer for web components.
24  *
25  * @author Michael Vorburger.ch
26  */
27 @Singleton
28 public class WebInitializer {
29
30     private final WebContextRegistration registraton;
31
32     @Inject
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
38
39             .addServlet(ServletDetails.builder()
40                     .servlet(servletSupport.createHttpServletBuilder(app).build())
41                     .addUrlPattern("/*").build());
42
43         webContextSecurer.requireAuthentication(webContextBuilder, "/*");
44
45         this.registraton = webServer.registerWebContext(webContextBuilder.build());
46     }
47
48     @PreDestroy
49     public void close() {
50         registraton.close();
51     }
52
53 }