87fe75cd491eeec9bb2564b367a153603aaa4ed9
[netconf.git] / netconf / yanglib / src / main / java / org / opendaylight / yanglib / impl / WebInitializer.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.yanglib.impl;
9
10 import javax.servlet.ServletException;
11 import javax.ws.rs.core.Application;
12 import org.opendaylight.aaa.web.ServletDetails;
13 import org.opendaylight.aaa.web.WebContext;
14 import org.opendaylight.aaa.web.WebContextBuilder;
15 import org.opendaylight.aaa.web.WebContextRegistration;
16 import org.opendaylight.aaa.web.WebContextSecurer;
17 import org.opendaylight.aaa.web.WebServer;
18 import org.opendaylight.aaa.web.servlet.ServletSupport;
19
20 /**
21  * Initializes the wep app.
22  *
23  * @author Thomas Pantelis
24  */
25 public class WebInitializer {
26     private final WebContextRegistration registration;
27
28     public WebInitializer(WebServer webServer,  WebContextSecurer webContextSecurer, ServletSupport servletSupport,
29             Application webApp) throws ServletException {
30         WebContextBuilder webContextBuilder = WebContext.builder().contextPath("yanglib").supportsSessions(true)
31             .addServlet(ServletDetails.builder().servlet(servletSupport.createHttpServletBuilder(webApp).build())
32                     .addUrlPattern("/*").build());
33
34         webContextSecurer.requireAuthentication(webContextBuilder, "/*");
35
36         registration = webServer.registerWebContext(webContextBuilder.build());
37     }
38
39     public void close() {
40         registration.close();
41     }
42 }