2 * Copyright (c) 2018 Inocybe Technologies 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.restconf.nb.rfc8040.web;
10 import java.util.List;
11 import javax.annotation.PreDestroy;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import javax.servlet.ServletException;
15 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
16 import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter;
17 import org.opendaylight.aaa.web.FilterDetails;
18 import org.opendaylight.aaa.web.ServletDetails;
19 import org.opendaylight.aaa.web.WebContext;
20 import org.opendaylight.aaa.web.WebContextBuilder;
21 import org.opendaylight.aaa.web.WebContextRegistration;
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.restconf.nb.rfc8040.DataStreamApplication;
26 import org.opendaylight.restconf.nb.rfc8040.RestconfApplication;
27 import org.opendaylight.restconf.nb.rfc8040.RootFoundApplication;
28 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
29 import org.opendaylight.restconf.nb.rfc8040.streams.WebSocketInitializer;
30 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
33 * Initializes the rfc8040 web app endpoint.
35 * @author Thomas Pantelis
38 public class WebInitializer {
39 private final WebContextRegistration registration;
42 public WebInitializer(final WebServer webServer, final WebContextSecurer webContextSecurer,
43 final ServletSupport servletSupport, final RestconfApplication webApp,
44 final DataStreamApplication webAppNotif,
45 final CustomFilterAdapterConfiguration customFilterAdapterConfig,
46 final WebSocketInitializer webSocketServlet) throws ServletException {
47 WebContextBuilder webContextBuilder = WebContext.builder()
49 .supportsSessions(false)
50 .addServlet(ServletDetails.builder()
51 .addUrlPattern(RestconfConstants.BASE_URI_PATTERN + "/*")
52 .servlet(servletSupport.createHttpServletBuilder(webApp).build())
55 .addServlet(ServletDetails.builder()
56 .addUrlPattern(RestconfConstants.BASE_URI_PATTERN + "/notif/*")
57 .servlet(servletSupport.createHttpServletBuilder(webAppNotif).build())
58 .name("notificationServlet")
61 .addServlet(ServletDetails.builder()
62 .addAllUrlPatterns(List.of(
63 RestconfConstants.BASE_URI_PATTERN + "/" + RestconfStreamsConstants.DATA_SUBSCRIPTION + "/*",
64 RestconfConstants.BASE_URI_PATTERN + "/" + RestconfStreamsConstants.NOTIFICATION_STREAM + "/*"))
65 .servlet(webSocketServlet)
67 .addServlet(ServletDetails.builder()
68 .addUrlPattern(".well-known/*")
69 .servlet(servletSupport.createHttpServletBuilder(
70 new RootFoundApplication(RestconfConstants.BASE_URI_PATTERN))
75 // Allows user to add javax.servlet.Filter(s) in front of REST services
76 .addFilter(FilterDetails.builder()
78 .filter(new CustomFilterAdapter(customFilterAdapterConfig))
82 webContextSecurer.requireAuthentication(webContextBuilder, true, RestconfConstants.BASE_URI_PATTERN + "/*");
84 registration = webServer.registerWebContext(webContextBuilder.build());
89 if (registration != null) {