<type>xml</type>
<classifier>features</classifier>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>odl-restconf-nb-rfc8040-noauth</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>odl-restconf-nb-rfc8040</artifactId>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright © 2017 Pantheon Technologies s.r.o. and others.
-
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at http://www.eclipse.org/legal/epl-v10.html
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.opendaylight.odlparent</groupId>
- <artifactId>single-feature-parent</artifactId>
- <version>3.1.0</version>
- <relativePath/>
- </parent>
-
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>odl-restconf-nb-rfc8040-noauth</artifactId>
- <version>1.8.0-SNAPSHOT</version>
- <packaging>feature</packaging>
-
- <name>OpenDaylight :: RESTCONF :: RFC8040</name>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>restconf-artifacts</artifactId>
- <version>1.8.0-SNAPSHOT</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
- <dependency>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>odl-restconf-common</artifactId>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
-
- <dependency>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>restconf-nb-rfc8040</artifactId>
- </dependency>
- </dependencies>
-</project>
<name>OpenDaylight :: Restconf NB - RFC8040</name>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
+ <artifactId>restconf-artifacts</artifactId>
+ <version>1.8.0-SNAPSHOT</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
- <!-- Enables AAA through aaa-shiro-act -->
<dependency>
- <groupId>org.opendaylight.aaa</groupId>
- <artifactId>odl-aaa-shiro-act</artifactId>
- <version>0.8.0-SNAPSHOT</version>
+ <groupId>org.opendaylight.netconf</groupId>
+ <artifactId>odl-restconf-common</artifactId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
<dependency>
<groupId>org.opendaylight.netconf</groupId>
- <artifactId>odl-restconf-nb-rfc8040-noauth</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>features</classifier>
+ <artifactId>restconf-nb-rfc8040</artifactId>
</dependency>
</dependencies>
</project>
<module>odl-restconf-all</module>
<module>odl-restconf-common</module>
<module>odl-restconf-noauth</module>
- <module>odl-restconf-nb-rfc8040-noauth</module>
<module>odl-restconf-nb-rfc8040</module>
<module>odl-restconf-nb-rfc8040-all</module>
</modules>
<artifactId>stax-utils</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.aaa.web</groupId>
+ <artifactId>web-api</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.aaa</groupId>
- <artifactId>aaa-shiro-api</artifactId>
+ <artifactId>aaa-filterchain</artifactId>
</dependency>
<dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlets</artifactId>
</dependency>
<!-- Testing Dependencies -->
<configuration>
<instructions>
<Bundle-Name>MD SAL Restconf Connector</Bundle-Name>
- <Import-Package>
- !javax.annotation,
- javax.ws.rs.*;version="[1.1.0,2.0.0)",
- *,
- com.sun.jersey.spi.container.servlet,
- org.eclipse.jetty.servlets,
- org.opendaylight.aaa.shiro.filters,
- org.opendaylight.aaa.shiro.realm,
- org.opendaylight.aaa.shiro.web.env,
- org.opendaylight.aaa.filterchain.filters,
- org.opendaylight.aaa.api,
- org.apache.shiro.web.env
- </Import-Package>
- <Web-ContextPath>/rests</Web-ContextPath>
</instructions>
</configuration>
</plugin>
import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
public class RestconfApplication extends Application {
- private final SchemaContextHandler schemaContextHandler = SchemaContextHandler.instance();
- private final DOMMountPointServiceHandler mountPointServiceHandler = DOMMountPointServiceHandler.instance();
+ private final SchemaContextHandler schemaContextHandler;
+ private final DOMMountPointServiceHandler mountPointServiceHandler;
+ private final ServicesWrapper servicesWrapper;
+
+ public RestconfApplication(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler, ServicesWrapper servicesWrapper) {
+ this.schemaContextHandler = schemaContextHandler;
+ this.mountPointServiceHandler = mountPointServiceHandler;
+ this.servicesWrapper = servicesWrapper;
+ }
@Override
public Set<Class<?>> getClasses() {
@Override
public Set<Object> getSingletons() {
final Set<Object> singletons = new HashSet<>();
- singletons.add(ServicesWrapper.getInstance());
+ singletons.add(servicesWrapper);
singletons.add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
singletons.add(new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
singletons.add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
*
*/
public final class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
- private static final DOMMountPointServiceHandler INSTANCE = new DOMMountPointServiceHandler();
-
- private DOMMountPointService domMountPointService;
+ private final DOMMountPointService domMountPointService;
/**
* Prepare mount point service for Restconf services.
this.domMountPointService = Objects.requireNonNull(domMountPointService);
}
- @Deprecated
- private DOMMountPointServiceHandler() {
- }
-
- @Deprecated
- public static DOMMountPointServiceHandler instance() {
- return INSTANCE;
- }
-
public static DOMMountPointServiceHandler newInstance(DOMMountPointService domMountPointService) {
- INSTANCE.domMountPointService = domMountPointService;
- return INSTANCE;
+ return new DOMMountPointServiceHandler(domMountPointService);
}
@Override
private static final Logger LOG = LoggerFactory.getLogger(SchemaContextHandler.class);
- private static final SchemaContextHandler INSTANCE = new SchemaContextHandler();
-
private final AtomicInteger moduleSetId = new AtomicInteger(0);
- private TransactionChainHandler transactionChainHandler;
- private DOMSchemaService domSchemaService;
+ private final TransactionChainHandler transactionChainHandler;
+ private final DOMSchemaService domSchemaService;
private ListenerRegistration<SchemaContextListener> listenerRegistration;
private volatile SchemaContext schemaContext;
this.domSchemaService = domSchemaService;
}
- @Deprecated
- private SchemaContextHandler() {
- }
-
- @Deprecated
- public static SchemaContextHandler instance() {
- return INSTANCE;
- }
-
public static SchemaContextHandler newInstance(TransactionChainHandler transactionChainHandler,
DOMSchemaService domSchemaService) {
- INSTANCE.transactionChainHandler = transactionChainHandler;
- INSTANCE.domSchemaService = domSchemaService;
- return INSTANCE;
+ return new SchemaContextHandler(transactionChainHandler, domSchemaService);
}
public void init() {
@Path("/")
public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper {
- private RestconfDataService delegRestconfDataService;
- private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
- private RestconfStreamsSubscriptionService delegRestconfSubscrService;
- private RestconfOperationsService delegRestOpsService;
- private RestconfSchemaService delegRestSchService;
- private RestconfService delegRestService;
-
- @Deprecated
- private ServicesWrapper() {
- }
-
- private static class InstanceHolder {
- public static final ServicesWrapper INSTANCE = new ServicesWrapper();
- }
-
- @Deprecated
- public static ServicesWrapper getInstance() {
- return InstanceHolder.INSTANCE;
+ private final RestconfDataService delegRestconfDataService;
+ private final RestconfInvokeOperationsService delegRestconfInvokeOpsService;
+ private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
+ private final RestconfOperationsService delegRestOpsService;
+ private final RestconfSchemaService delegRestSchService;
+ private final RestconfService delegRestService;
+
+ private ServicesWrapper(RestconfDataService delegRestconfDataService,
+ RestconfInvokeOperationsService delegRestconfInvokeOpsService,
+ RestconfStreamsSubscriptionService delegRestconfSubscrService,
+ RestconfOperationsService delegRestOpsService, RestconfSchemaService delegRestSchService,
+ RestconfService delegRestService) {
+ this.delegRestconfDataService = delegRestconfDataService;
+ this.delegRestconfInvokeOpsService = delegRestconfInvokeOpsService;
+ this.delegRestconfSubscrService = delegRestconfSubscrService;
+ this.delegRestOpsService = delegRestOpsService;
+ this.delegRestSchService = delegRestSchService;
+ this.delegRestService = delegRestService;
}
public static ServicesWrapper newInstance(final SchemaContextHandler schemaCtxHandler,
final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
final DOMSchemaService domSchemaService) {
- InstanceHolder.INSTANCE.delegRestOpsService =
+ RestconfOperationsService restconfOpsService =
new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
final DOMYangTextSourceProvider yangTextSourceProvider =
(DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
.get(DOMYangTextSourceProvider.class);
- InstanceHolder.INSTANCE.delegRestSchService =
+ RestconfSchemaService restconfSchemaService =
new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
yangTextSourceProvider);
- InstanceHolder.INSTANCE.delegRestconfSubscrService =
+ RestconfStreamsSubscriptionService restconfSubscrService =
new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
- InstanceHolder.INSTANCE.delegRestconfDataService =
+ RestconfDataService restconfDataService =
new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler, domMountPointServiceHandler,
- InstanceHolder.INSTANCE.delegRestconfSubscrService);
- InstanceHolder.INSTANCE.delegRestconfInvokeOpsService =
+ restconfSubscrService);
+ RestconfInvokeOperationsService restconfInvokeOpsService =
new RestconfInvokeOperationsServiceImpl(rpcServiceHandler, schemaCtxHandler);
- InstanceHolder.INSTANCE.delegRestService = new RestconfImpl(schemaCtxHandler);
- return InstanceHolder.INSTANCE;
+ RestconfService restconfService = new RestconfImpl(schemaCtxHandler);
+ return new ServicesWrapper(restconfDataService, restconfInvokeOpsService,
+ restconfSubscrService, restconfOpsService, restconfSchemaService, restconfService);
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2018 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.nb.rfc8040.web;
+
+import javax.servlet.ServletException;
+import javax.ws.rs.core.Application;
+import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
+import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter;
+import org.opendaylight.aaa.web.FilterDetails;
+import org.opendaylight.aaa.web.ServletDetails;
+import org.opendaylight.aaa.web.WebContext;
+import org.opendaylight.aaa.web.WebContextBuilder;
+import org.opendaylight.aaa.web.WebContextRegistration;
+import org.opendaylight.aaa.web.WebContextSecurer;
+import org.opendaylight.aaa.web.WebServer;
+
+/**
+ * Initializes the rfc8040 web app endpoint.
+ *
+ * @author Thomas Pantelis
+ */
+public class WebInitializer {
+ private final WebContextRegistration registration;
+
+ public WebInitializer(WebServer webServer, WebContextSecurer webContextSecurer,
+ Application webApp, CustomFilterAdapterConfiguration customFilterAdapterConfig) throws ServletException {
+ WebContextBuilder webContextBuilder = WebContext.builder().contextPath("rests").supportsSessions(true)
+ .addServlet(ServletDetails.builder().servlet(
+ new com.sun.jersey.spi.container.servlet.ServletContainer(webApp))
+ .addUrlPattern("/*").build())
+
+ // Allows user to add javax.servlet.Filter(s) in front of REST services
+ .addFilter(FilterDetails.builder().filter(new CustomFilterAdapter(customFilterAdapterConfig))
+ .addUrlPattern("/*").build())
+
+ .addFilter(FilterDetails.builder().filter(new org.eclipse.jetty.servlets.GzipFilter())
+ .putInitParam("mimeTypes",
+ "application/xml,application/yang.data+xml,xml,application/json,application/yang.data+json")
+ .addUrlPattern("/*").build());
+
+ webContextSecurer.requireAuthentication(webContextBuilder, "/*");
+
+ registration = webServer.registerWebContext(webContextBuilder.build());
+ }
+
+ public void close() {
+ if (registration != null) {
+ registration.close();
+ }
+ }
+}
+++ /dev/null
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
-
- <servlet>
- <servlet-name>Restconf-rfc8040</servlet-name>
- <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
- <init-param>
- <param-name>javax.ws.rs.Application</param-name>
- <param-value>org.opendaylight.restconf.nb.rfc8040.RestconfApplication</param-value>
- </init-param>
- <load-on-startup>0</load-on-startup>
- </servlet>
-
- <context-param>
- <param-name>shiroEnvironmentClass</param-name>
- <param-value>org.opendaylight.aaa.shiro.web.env.KarafIniWebEnvironment</param-value>
- </context-param>
-
- <listener>
- <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
- </listener>
-
- <filter>
- <filter-name>ShiroFilter</filter-name>
- <filter-class>org.opendaylight.aaa.shiro.filters.AAAFilter</filter-class>
- </filter>
-
- <filter-mapping>
- <filter-name>ShiroFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
- <filter>
- <filter-name>DynamicFilterChain</filter-name>
- <filter-class>org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter</filter-class>
- </filter>
-
- <filter-mapping>
- <filter-name>DynamicFilterChain</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
- <servlet-mapping>
- <servlet-name>Restconf-rfc8040</servlet-name>
- <url-pattern>/*</url-pattern>
- </servlet-mapping>
-
- <filter>
- <filter-name>GzipFilter</filter-name>
- <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
- <init-param>
- <param-name>mimeTypes</param-name>
- <param-value>application/xml,application/yang.data+xml,xml,application/json,application/yang.data+json</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>GzipFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
- <filter>
- <filter-name>cross-origin-restconf</filter-name>
- <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
- <init-param>
- <param-name>allowedOrigins</param-name>
- <param-value>*</param-value>
- </init-param>
- <init-param>
- <param-name>allowedMethods</param-name>
- <param-value>GET,POST,OPTIONS,DELETE,PUT,HEAD</param-value>
- </init-param>
- <init-param>
- <param-name>allowedHeaders</param-name>
- <param-value>origin, content-type, accept, authorization</param-value>
- </init-param>
- <init-param>
- <param-name>exposedHeaders</param-name>
- <param-value>location</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>cross-origin-restconf</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>Restconf NB RFC api</web-resource-name>
- <url-pattern>/*</url-pattern>
- <http-method>POST</http-method>
- <http-method>GET</http-method>
- <http-method>PUT</http-method>
- <http-method>PATCH</http-method>
- <http-method>DELETE</http-method>
- <http-method>HEAD</http-method>
- </web-resource-collection>
- </security-constraint>
-
-</web-app>
</cm:default-properties>
</cm:property-placeholder>
- <!-- We need the AAAService available even though we don't use it -->
- <reference interface="org.opendaylight.aaa.api.AAAService"/>
-
<reference id="domRpcService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcService"/>
<reference id="domMountPointService" interface="org.opendaylight.controller.md.sal.dom.api.DOMMountPointService"/>
<reference id="domNotificationService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationService"/>
<argument ref="domSchemaService"/>
</bean>
+ <bean id="restconfApplication" class="org.opendaylight.restconf.nb.rfc8040.RestconfApplication">
+ <argument ref="schemaContextHandler"/>
+ <argument ref="mountPointServiceHandler"/>
+ <argument ref="servicesWrapper"/>
+ </bean>
+
<!-- JSONRestconfService -->
<bean id="jsonRestconfService"
class="org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl"
<service ref="jsonRestconfService" odl:type="rfc8040"
interface="org.opendaylight.restconf.nb.rfc8040.rests.services.api.JSONRestconfService" />
+ <!-- Web app registration -->
+
+ <reference id="customFilterAdapterConfig"
+ interface="org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration"/>
+
+ <reference id="webServer" interface="org.opendaylight.aaa.web.WebServer" />
+
+ <reference id="webContextSecurer" interface="org.opendaylight.aaa.web.WebContextSecurer" />
+
+ <bean id="webInitializer" class="org.opendaylight.restconf.nb.rfc8040.web.WebInitializer"
+ destroy-method="close">
+ <argument ref="webServer"/>
+ <argument ref="webContextSecurer"/>
+ <argument ref="restconfApplication"/>
+ <argument ref="customFilterAdapterConfig"/>
+ </bean>
+
</blueprint>