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