From: Tom Pantelis Date: Tue, 24 Apr 2018 18:48:30 +0000 (-0400) Subject: Convert rcf8040 from web.xml to programmtic web API X-Git-Tag: release/fluorine~86^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=3f61fe753299d330228e00bab6118070fedb006a;hp=73bc92edf590d470c6f5c7bfde33bdd79c572b6a;p=netconf.git Convert rcf8040 from web.xml to programmtic web API To simplify, the noauth feature was removed. Since this is a new API, it's been decided not to carry it forward. The noauth feature for the bierman02 implementation was put in and kept for legacy reasons. Change-Id: Ic432b175fae62caee8cc641bb77c19f38a5ab6f6 Signed-off-by: Tom Pantelis --- diff --git a/features/restconf/features-restconf/pom.xml b/features/restconf/features-restconf/pom.xml index 65fd339d1b..02c37c939f 100644 --- a/features/restconf/features-restconf/pom.xml +++ b/features/restconf/features-restconf/pom.xml @@ -50,13 +50,6 @@ xml features - - ${project.groupId} - odl-restconf-nb-rfc8040-noauth - ${project.version} - xml - features - ${project.groupId} odl-restconf-nb-rfc8040 diff --git a/features/restconf/odl-restconf-nb-rfc8040-noauth/pom.xml b/features/restconf/odl-restconf-nb-rfc8040-noauth/pom.xml deleted file mode 100644 index 85c16c680b..0000000000 --- a/features/restconf/odl-restconf-nb-rfc8040-noauth/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - 4.0.0 - - - org.opendaylight.odlparent - single-feature-parent - 3.1.0 - - - - org.opendaylight.netconf - odl-restconf-nb-rfc8040-noauth - 1.8.0-SNAPSHOT - feature - - OpenDaylight :: RESTCONF :: RFC8040 - - - - - org.opendaylight.netconf - restconf-artifacts - 1.8.0-SNAPSHOT - pom - import - - - - - - - org.opendaylight.netconf - odl-restconf-common - xml - features - - - - org.opendaylight.netconf - restconf-nb-rfc8040 - - - diff --git a/features/restconf/odl-restconf-nb-rfc8040/pom.xml b/features/restconf/odl-restconf-nb-rfc8040/pom.xml index 176486bd88..9fb62b3eb8 100644 --- a/features/restconf/odl-restconf-nb-rfc8040/pom.xml +++ b/features/restconf/odl-restconf-nb-rfc8040/pom.xml @@ -23,21 +23,28 @@ OpenDaylight :: Restconf NB - RFC8040 + + + + org.opendaylight.netconf + restconf-artifacts + 1.8.0-SNAPSHOT + pom + import + + + + - - org.opendaylight.aaa - odl-aaa-shiro-act - 0.8.0-SNAPSHOT + org.opendaylight.netconf + odl-restconf-common xml features org.opendaylight.netconf - odl-restconf-nb-rfc8040-noauth - ${project.version} - xml - features + restconf-nb-rfc8040 diff --git a/features/restconf/pom.xml b/features/restconf/pom.xml index 0f47d805b3..c8300f7f9d 100644 --- a/features/restconf/pom.xml +++ b/features/restconf/pom.xml @@ -26,7 +26,6 @@ odl-restconf-all odl-restconf-common odl-restconf-noauth - odl-restconf-nb-rfc8040-noauth odl-restconf-nb-rfc8040 odl-restconf-nb-rfc8040-all diff --git a/restconf/restconf-nb-rfc8040/pom.xml b/restconf/restconf-nb-rfc8040/pom.xml index a820477b60..9130a59986 100644 --- a/restconf/restconf-nb-rfc8040/pom.xml +++ b/restconf/restconf-nb-rfc8040/pom.xml @@ -117,14 +117,30 @@ stax-utils + + org.json + json + + + + org.opendaylight.aaa.web + web-api + 0.8.0-SNAPSHOT + + org.opendaylight.aaa - aaa-shiro-api + aaa-filterchain - org.json - json + com.sun.jersey + jersey-servlet + + + + org.eclipse.jetty + jetty-servlets @@ -170,20 +186,6 @@ MD SAL Restconf Connector - - !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 - - /rests diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java index 76b560c296..89c8587880 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java @@ -26,8 +26,16 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExport 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> getClasses() { @@ -41,7 +49,7 @@ public class RestconfApplication extends Application { @Override public Set getSingletons() { final Set 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)); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.java index e299fe0715..311dae724f 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.java @@ -15,9 +15,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; * */ public final class DOMMountPointServiceHandler implements Handler { - private static final DOMMountPointServiceHandler INSTANCE = new DOMMountPointServiceHandler(); - - private DOMMountPointService domMountPointService; + private final DOMMountPointService domMountPointService; /** * Prepare mount point service for Restconf services. @@ -29,18 +27,8 @@ public final class DOMMountPointServiceHandler implements Handler listenerRegistration; private volatile SchemaContext schemaContext; @@ -61,20 +59,9 @@ public class SchemaContextHandler implements SchemaContextListenerHandler, AutoC 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() { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java index 53c6aee39e..de38b6a75b 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java @@ -48,24 +48,24 @@ import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfSchemaS @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, @@ -73,24 +73,25 @@ public final class ServicesWrapper implements BaseServicesWrapper, TransactionSe 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 diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java new file mode 100644 index 0000000000..5339adc0ab --- /dev/null +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java @@ -0,0 +1,56 @@ +/* + * 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(); + } + } +} diff --git a/restconf/restconf-nb-rfc8040/src/main/resources/WEB-INF/web.xml b/restconf/restconf-nb-rfc8040/src/main/resources/WEB-INF/web.xml deleted file mode 100644 index 058ccb890a..0000000000 --- a/restconf/restconf-nb-rfc8040/src/main/resources/WEB-INF/web.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - Restconf-rfc8040 - com.sun.jersey.spi.container.servlet.ServletContainer - - javax.ws.rs.Application - org.opendaylight.restconf.nb.rfc8040.RestconfApplication - - 0 - - - - shiroEnvironmentClass - org.opendaylight.aaa.shiro.web.env.KarafIniWebEnvironment - - - - org.apache.shiro.web.env.EnvironmentLoaderListener - - - - ShiroFilter - org.opendaylight.aaa.shiro.filters.AAAFilter - - - - ShiroFilter - /* - - - - DynamicFilterChain - org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter - - - - DynamicFilterChain - /* - - - - Restconf-rfc8040 - /* - - - - GzipFilter - org.eclipse.jetty.servlets.GzipFilter - - mimeTypes - application/xml,application/yang.data+xml,xml,application/json,application/yang.data+json - - - - GzipFilter - /* - - - - cross-origin-restconf - org.eclipse.jetty.servlets.CrossOriginFilter - - allowedOrigins - * - - - allowedMethods - GET,POST,OPTIONS,DELETE,PUT,HEAD - - - allowedHeaders - origin, content-type, accept, authorization - - - exposedHeaders - location - - - - cross-origin-restconf - /* - - - - - Restconf NB RFC api - /* - POST - GET - PUT - PATCH - DELETE - HEAD - - - - diff --git a/restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml b/restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml index 022982962f..e7719c4fa9 100644 --- a/restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml +++ b/restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml @@ -26,9 +26,6 @@ - - - @@ -75,6 +72,12 @@ + + + + + + + + + + + + + + + + + + + + +