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.netconf.sal.restconf.web;
10 import javax.servlet.ServletException;
11 import javax.ws.rs.core.Application;
12 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
13 import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter;
14 import org.opendaylight.aaa.web.FilterDetails;
15 import org.opendaylight.aaa.web.ServletDetails;
16 import org.opendaylight.aaa.web.WebContext;
17 import org.opendaylight.aaa.web.WebContextBuilder;
18 import org.opendaylight.aaa.web.WebContextRegistration;
19 import org.opendaylight.aaa.web.WebContextSecurer;
20 import org.opendaylight.aaa.web.WebServer;
23 * Implementation of Bierman02WebRegistrar.
25 * @author Thomas Pantelis
27 public class Bierman02WebRegistrarImpl implements Bierman02WebRegistrar {
29 private WebContextRegistration registraton;
30 private final WebServer webServer;
31 private final WebContextSecurer webContextSecurer;
32 private final Application webApp;
33 private final CustomFilterAdapterConfiguration customFilterAdapterConfig;
35 public Bierman02WebRegistrarImpl(WebServer webServer, WebContextSecurer webContextSecurer,
36 Application webApp, CustomFilterAdapterConfiguration customFilterAdapterConfig) {
37 this.webServer = webServer;
38 this.webContextSecurer = webContextSecurer;
40 this.customFilterAdapterConfig = customFilterAdapterConfig;
44 if (registraton != null) {
50 public void registerWithAuthentication() {
55 public void registerWithoutAuthentication() {
59 private void register(boolean authenticate) {
60 WebContextBuilder webContextBuilder = WebContext.builder().contextPath("restconf").supportsSessions(true)
61 .addServlet(ServletDetails.builder().servlet(
62 new com.sun.jersey.spi.container.servlet.ServletContainer(webApp))
63 .addUrlPattern("/*").build())
65 // Allows user to add javax.servlet.Filter(s) in front of REST services
66 .addFilter(FilterDetails.builder().filter(new CustomFilterAdapter(customFilterAdapterConfig))
67 .addUrlPattern("/*").build())
69 .addFilter(FilterDetails.builder().filter(new org.eclipse.jetty.servlets.GzipFilter())
70 .putInitParam("mimeTypes",
71 "application/xml,application/yang.data+xml,xml,application/json,application/yang.data+json")
72 .addUrlPattern("/*").build());
75 webContextSecurer.requireAuthentication(webContextBuilder, "/*");
79 registraton = webServer.registerWebContext(webContextBuilder.build());
80 } catch (ServletException e) {
81 throw new RuntimeException("Failed to register the web context", e);