From e7a2fe98883583c39f7b98945e91aa9bd5d0edb4 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Tue, 17 Apr 2018 21:39:22 -0400 Subject: [PATCH] Convert bierman02 from web.xml to programmtic web API To handle auth vs noauth, 2 new bundles were added that import a new Bierman02WebRegistrar service advertised by the restconf-nb-bierman02 bundle and simply invoke the appropriate register*Authentication method. The odl-restconf no longer installs odl-restconf-noauth nor the aaa-shiro-act bundle. Both bundles install a new odl-restconf-base feature and their respective restconf-nb-bierman02-auth/restconf-nb-bierman02-noauth bundle. Change-Id: I93f58e791d8b9666083bd379c99a548bff6e8971 Signed-off-by: Tom Pantelis --- features/restconf/odl-restconf-base/pom.xml | 58 ++++++++++ features/restconf/odl-restconf-noauth/pom.xml | 13 +-- features/restconf/odl-restconf/pom.xml | 19 +--- features/restconf/pom.xml | 1 + restconf/pom.xml | 2 + restconf/restconf-common/pom.xml | 19 ---- restconf/restconf-nb-bierman02-auth/pom.xml | 28 +++++ .../nb/bierman02/web/auth/WebInitializer.java | 21 ++++ .../opendaylight/blueprint/bierman02-auth.xml | 17 +++ restconf/restconf-nb-bierman02-noauth/pom.xml | 28 +++++ .../bierman02/web/noauth/WebInitializer.java | 21 ++++ .../blueprint/bierman02-noauth.xml | 17 +++ restconf/restconf-nb-bierman02/pom.xml | 31 +++--- .../sal/rest/impl/RestconfApplication.java | 14 ++- .../sal/restconf/impl/BrokerFacade.java | 52 ++------- .../sal/restconf/impl/ControllerContext.java | 30 +----- .../StatisticsRestconfServiceWrapper.java | 17 +-- .../restconf/web/Bierman02WebRegistrar.java | 20 ++++ .../web/Bierman02WebRegistrarImpl.java | 84 +++++++++++++++ .../src/main/resources/WEB-INF/web.xml | 102 ------------------ .../blueprint/restconf-config.xml | 29 ++++- .../restconf/impl/test/BrokerFacadeTest.java | 13 --- 22 files changed, 374 insertions(+), 262 deletions(-) create mode 100644 features/restconf/odl-restconf-base/pom.xml create mode 100644 restconf/restconf-nb-bierman02-auth/pom.xml create mode 100644 restconf/restconf-nb-bierman02-auth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/auth/WebInitializer.java create mode 100644 restconf/restconf-nb-bierman02-auth/src/main/resources/org/opendaylight/blueprint/bierman02-auth.xml create mode 100644 restconf/restconf-nb-bierman02-noauth/pom.xml create mode 100644 restconf/restconf-nb-bierman02-noauth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/noauth/WebInitializer.java create mode 100644 restconf/restconf-nb-bierman02-noauth/src/main/resources/org/opendaylight/blueprint/bierman02-noauth.xml create mode 100644 restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrar.java create mode 100644 restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrarImpl.java delete mode 100644 restconf/restconf-nb-bierman02/src/main/resources/WEB-INF/web.xml diff --git a/features/restconf/odl-restconf-base/pom.xml b/features/restconf/odl-restconf-base/pom.xml new file mode 100644 index 0000000000..9dc17251e0 --- /dev/null +++ b/features/restconf/odl-restconf-base/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + + org.opendaylight.odlparent + single-feature-parent + 3.1.0 + + + + org.opendaylight.netconf + odl-restconf-base + 1.8.0-SNAPSHOT + feature + + OpenDaylight :: Restconf :: Base + + + + + org.opendaylight.netconf + restconf-artifacts + 1.8.0-SNAPSHOT + pom + import + + + + + + + org.opendaylight.netconf + odl-restconf-common + xml + features + + + org.opendaylight.netconf + restconf-nb-bierman02 + ${project.version} + + + org.opendaylight.netconf + sal-rest-connector-config + ${project.version} + cfg + restconf + + + diff --git a/features/restconf/odl-restconf-noauth/pom.xml b/features/restconf/odl-restconf-noauth/pom.xml index f63beb8a64..a4940392f4 100644 --- a/features/restconf/odl-restconf-noauth/pom.xml +++ b/features/restconf/odl-restconf-noauth/pom.xml @@ -38,22 +38,15 @@ org.opendaylight.netconf - odl-restconf-common + odl-restconf-base + ${project.version} xml features - - - org.opendaylight.netconf - restconf-nb-bierman02 - ${project.version} - org.opendaylight.netconf - sal-rest-connector-config + restconf-nb-bierman02-noauth ${project.version} - cfg - restconf diff --git a/features/restconf/odl-restconf/pom.xml b/features/restconf/odl-restconf/pom.xml index f190f1a54c..003d60c814 100644 --- a/features/restconf/odl-restconf/pom.xml +++ b/features/restconf/odl-restconf/pom.xml @@ -24,28 +24,17 @@ OpenDaylight :: Restconf - - - org.opendaylight.aaa - odl-aaa-shiro-act - 0.8.0-SNAPSHOT - xml - features - org.opendaylight.netconf - odl-restconf-noauth + odl-restconf-base ${project.version} xml features - - org.opendaylight.odlparent - odl-jackson-2.8 - 3.1.0 - xml - features + org.opendaylight.netconf + restconf-nb-bierman02-auth + ${project.version} diff --git a/features/restconf/pom.xml b/features/restconf/pom.xml index 0f47d805b3..7c8334478c 100644 --- a/features/restconf/pom.xml +++ b/features/restconf/pom.xml @@ -23,6 +23,7 @@ features-restconf odl-mdsal-apidocs odl-restconf + odl-restconf-base odl-restconf-all odl-restconf-common odl-restconf-noauth diff --git a/restconf/pom.xml b/restconf/pom.xml index 4d3a097b41..945e966c4b 100644 --- a/restconf/pom.xml +++ b/restconf/pom.xml @@ -29,6 +29,8 @@ restconf-common-models restconf-common restconf-nb-bierman02 + restconf-nb-bierman02-auth + restconf-nb-bierman02-noauth restconf-nb-rfc8040 sal-rest-connector-config sal-rest-docgen diff --git a/restconf/restconf-common/pom.xml b/restconf/restconf-common/pom.xml index ccbeb2dd1a..724c2cf673 100644 --- a/restconf/restconf-common/pom.xml +++ b/restconf/restconf-common/pom.xml @@ -63,23 +63,4 @@ test - - - - - org.apache.felix - maven-bundle-plugin - true - - - - !javax.annotation, - javax.ws.rs.*;version="[1.1.0,2.0.0)", - * - - - - - - diff --git a/restconf/restconf-nb-bierman02-auth/pom.xml b/restconf/restconf-nb-bierman02-auth/pom.xml new file mode 100644 index 0000000000..18f6100af7 --- /dev/null +++ b/restconf/restconf-nb-bierman02-auth/pom.xml @@ -0,0 +1,28 @@ + + + + 4.0.0 + + org.opendaylight.netconf + restconf-parent + 1.8.0-SNAPSHOT + ../restconf-parent + + + org.opendaylight.netconf + restconf-nb-bierman02-auth + bundle + + + + org.opendaylight.netconf + restconf-nb-bierman02 + + + diff --git a/restconf/restconf-nb-bierman02-auth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/auth/WebInitializer.java b/restconf/restconf-nb-bierman02-auth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/auth/WebInitializer.java new file mode 100644 index 0000000000..4f1af41e6c --- /dev/null +++ b/restconf/restconf-nb-bierman02-auth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/auth/WebInitializer.java @@ -0,0 +1,21 @@ +/* + * 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.bierman02.web.auth; + +import org.opendaylight.netconf.sal.restconf.web.Bierman02WebRegistrar; + +/** + * Initializes the bierman-02 endpoint with authentication. + * + * @author Thomas Pantelis + */ +public class WebInitializer { + public WebInitializer(Bierman02WebRegistrar registrar) { + registrar.registerWithAuthentication(); + } +} diff --git a/restconf/restconf-nb-bierman02-auth/src/main/resources/org/opendaylight/blueprint/bierman02-auth.xml b/restconf/restconf-nb-bierman02-auth/src/main/resources/org/opendaylight/blueprint/bierman02-auth.xml new file mode 100644 index 0000000000..0a0b21fafd --- /dev/null +++ b/restconf/restconf-nb-bierman02-auth/src/main/resources/org/opendaylight/blueprint/bierman02-auth.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/restconf/restconf-nb-bierman02-noauth/pom.xml b/restconf/restconf-nb-bierman02-noauth/pom.xml new file mode 100644 index 0000000000..079e98f180 --- /dev/null +++ b/restconf/restconf-nb-bierman02-noauth/pom.xml @@ -0,0 +1,28 @@ + + + + 4.0.0 + + org.opendaylight.netconf + restconf-parent + 1.8.0-SNAPSHOT + ../restconf-parent + + + org.opendaylight.netconf + restconf-nb-bierman02-noauth + bundle + + + + org.opendaylight.netconf + restconf-nb-bierman02 + + + diff --git a/restconf/restconf-nb-bierman02-noauth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/noauth/WebInitializer.java b/restconf/restconf-nb-bierman02-noauth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/noauth/WebInitializer.java new file mode 100644 index 0000000000..de8b97a616 --- /dev/null +++ b/restconf/restconf-nb-bierman02-noauth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/noauth/WebInitializer.java @@ -0,0 +1,21 @@ +/* + * 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.bierman02.web.noauth; + +import org.opendaylight.netconf.sal.restconf.web.Bierman02WebRegistrar; + +/** + * Initializes the bierman-02 endpoint without authentication. + * + * @author Thomas Pantelis + */ +public class WebInitializer { + public WebInitializer(Bierman02WebRegistrar registrar) { + registrar.registerWithoutAuthentication(); + } +} diff --git a/restconf/restconf-nb-bierman02-noauth/src/main/resources/org/opendaylight/blueprint/bierman02-noauth.xml b/restconf/restconf-nb-bierman02-noauth/src/main/resources/org/opendaylight/blueprint/bierman02-noauth.xml new file mode 100644 index 0000000000..e31df8e506 --- /dev/null +++ b/restconf/restconf-nb-bierman02-noauth/src/main/resources/org/opendaylight/blueprint/bierman02-noauth.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/restconf/restconf-nb-bierman02/pom.xml b/restconf/restconf-nb-bierman02/pom.xml index f10ee72d51..55bc5aab27 100644 --- a/restconf/restconf-nb-bierman02/pom.xml +++ b/restconf/restconf-nb-bierman02/pom.xml @@ -154,6 +154,23 @@ logback-classic test + + org.opendaylight.aaa.web + web-api + 0.8.0-SNAPSHOT + + + org.opendaylight.aaa + aaa-filterchain + + + com.sun.jersey + jersey-servlet + + + org.eclipse.jetty + jetty-servlets + @@ -211,20 +228,6 @@ org.opendaylight.netconf.md.sal.rest.common.*, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.rest.connector.rev140724.*, - - !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 - - /restconf diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java index 9dd5a59dda..54a81d6b98 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java @@ -19,6 +19,16 @@ import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; import org.opendaylight.netconf.sal.restconf.impl.StatisticsRestconfServiceWrapper; public class RestconfApplication extends Application { + private final ControllerContext controllerContext; + private final BrokerFacade brokerFacade; + private final StatisticsRestconfServiceWrapper statsServiceWrapper; + + public RestconfApplication(ControllerContext controllerContext, BrokerFacade brokerFacade, + StatisticsRestconfServiceWrapper statsServiceWrapper) { + this.controllerContext = controllerContext; + this.brokerFacade = brokerFacade; + this.statsServiceWrapper = statsServiceWrapper; + } @Override public Set> getClasses() { @@ -35,13 +45,11 @@ public class RestconfApplication extends Application { @Override public Set getSingletons() { final Set singletons = new HashSet<>(); - final ControllerContext controllerContext = ControllerContext.getInstance(); - final BrokerFacade brokerFacade = BrokerFacade.getInstance(); final SchemaRetrievalServiceImpl schemaRetrieval = new SchemaRetrievalServiceImpl(controllerContext); singletons.add(controllerContext); singletons.add(brokerFacade); singletons.add(schemaRetrieval); - singletons.add(new RestconfCompositeWrapper(StatisticsRestconfServiceWrapper.getInstance(), schemaRetrieval)); + singletons.add(new RestconfCompositeWrapper(statsServiceWrapper, schemaRetrieval)); singletons.add(new RestconfDocumentedExceptionMapper(controllerContext)); singletons.add(new XmlNormalizedNodeBodyReader(controllerContext)); singletons.add(new JsonNormalizedNodeBodyReader(controllerContext)); diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java index 8c1299e0cd..a5ea3e00ee 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; +import java.util.Objects; import java.util.concurrent.CountDownLatch; import javax.annotation.Nullable; import javax.ws.rs.core.Response.Status; @@ -92,51 +93,28 @@ import org.slf4j.LoggerFactory; @SuppressWarnings("checkstyle:FinalClass") public class BrokerFacade implements Closeable { private static final Logger LOG = LoggerFactory.getLogger(BrokerFacade.class); - private static final BrokerFacade INSTANCE = new BrokerFacade(); private volatile DOMRpcService rpcService; - private DOMDataBroker domDataBroker; - private DOMNotificationService domNotification; - private ControllerContext controllerContext; - - // Temporary until the static instance is removed. - @Deprecated - private BrokerFacade() { - } + private final DOMDataBroker domDataBroker; + private final DOMNotificationService domNotification; + private final ControllerContext controllerContext; private BrokerFacade(DOMRpcService rpcService, DOMDataBroker domDataBroker, DOMNotificationService domNotification, ControllerContext controllerContext) { - this.rpcService = rpcService; - this.domDataBroker = domDataBroker; - this.domNotification = domNotification; - this.controllerContext = controllerContext; - } - - @Deprecated - public static BrokerFacade getInstance() { - return BrokerFacade.INSTANCE; + this.rpcService = Objects.requireNonNull(rpcService); + this.domDataBroker = Objects.requireNonNull(domDataBroker); + this.domNotification = Objects.requireNonNull(domNotification); + this.controllerContext = Objects.requireNonNull(controllerContext); } public static BrokerFacade newInstance(DOMRpcService rpcService, DOMDataBroker domDataBroker, DOMNotificationService domNotification, ControllerContext controllerContext) { - INSTANCE.rpcService = rpcService; - INSTANCE.domDataBroker = domDataBroker; - INSTANCE.controllerContext = controllerContext; - INSTANCE.domNotification = domNotification; - return INSTANCE; - //return new BrokerFacade(pcService, domDataBroker, controllerContext); + return new BrokerFacade(rpcService, domDataBroker, domNotification, controllerContext); } @Override public void close() { - domDataBroker = null; - } - - private void checkPreconditions() { - if (this.domDataBroker == null) { - throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE); - } } /** @@ -160,7 +138,6 @@ public class BrokerFacade implements Closeable { * @return read date */ public NormalizedNode readConfigurationData(final YangInstanceIdentifier path, final String withDefa) { - checkPreconditions(); try (DOMDataReadOnlyTransaction tx = this.domDataBroker.newReadOnlyTransaction()) { return readDataViaTransaction(tx, CONFIGURATION, path, withDefa); } @@ -212,8 +189,6 @@ public class BrokerFacade implements Closeable { * @return read data */ public NormalizedNode readOperationalData(final YangInstanceIdentifier path) { - checkPreconditions(); - try (DOMDataReadOnlyTransaction tx = this.domDataBroker.newReadOnlyTransaction()) { return readDataViaTransaction(tx, OPERATIONAL, path); } @@ -266,8 +241,6 @@ public class BrokerFacade implements Closeable { Preconditions.checkNotNull(path); Preconditions.checkNotNull(payload); - checkPreconditions(); - final DOMDataReadWriteTransaction newReadWriteTransaction = this.domDataBroker.newReadWriteTransaction(); final Status status = readDataViaTransaction(newReadWriteTransaction, CONFIGURATION, path) != null ? Status.OK : Status.CREATED; @@ -479,7 +452,6 @@ public class BrokerFacade implements Closeable { public CheckedFuture commitConfigurationDataPost( final SchemaContext globalSchema, final YangInstanceIdentifier path, final NormalizedNode payload, final String insert, final String point) { - checkPreconditions(); return postDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload, globalSchema, insert, point); } @@ -500,7 +472,6 @@ public class BrokerFacade implements Closeable { // DELETE configuration public CheckedFuture commitConfigurationDataDelete( final YangInstanceIdentifier path) { - checkPreconditions(); return deleteDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path); } @@ -518,7 +489,6 @@ public class BrokerFacade implements Closeable { // RPC public CheckedFuture invokeRpc(final SchemaPath type, final NormalizedNode input) { - checkPreconditions(); if (this.rpcService == null) { throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE); } @@ -528,8 +498,6 @@ public class BrokerFacade implements Closeable { public void registerToListenDataChanges(final LogicalDatastoreType datastore, final DataChangeScope scope, final ListenerAdapter listener) { - checkPreconditions(); - if (listener.isListening()) { return; } @@ -1227,8 +1195,6 @@ public class BrokerFacade implements Closeable { } public void registerToListenNotification(final NotificationListenerAdapter listener) { - checkPreconditions(); - if (listener.isListening()) { return; } diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java index 866eb0ccf4..c8e6adcc96 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java @@ -84,9 +84,6 @@ public final class ControllerContext implements SchemaContextListener, Closeable private static final Logger LOG = LoggerFactory.getLogger(ControllerContext.class); - // FIXME: this should be the current instance which is mutated - private static final ControllerContext INSTANCE = new ControllerContext(); - private static final String NULL_VALUE = "null"; private static final String MOUNT_MODULE = "yang-ext"; @@ -99,9 +96,9 @@ public final class ControllerContext implements SchemaContextListener, Closeable private final AtomicReference> qnameToRpc = new AtomicReference<>(Collections.emptyMap()); - private DOMMountPointService mountService; - private DOMYangTextSourceProvider yangTextSourceProvider; - private ListenerRegistration listenerRegistration; + private final DOMMountPointService mountService; + private final DOMYangTextSourceProvider yangTextSourceProvider; + private final ListenerRegistration listenerRegistration; private volatile SchemaContext globalSchema; private volatile DataNormalizer dataNormalizer; @@ -110,33 +107,16 @@ public final class ControllerContext implements SchemaContextListener, Closeable this.mountService = mountService; this.yangTextSourceProvider = yangTextSourceProvider; - setGlobalSchema(schemaService.getGlobalContext()); + onGlobalContextUpdated(schemaService.getGlobalContext()); listenerRegistration = schemaService.registerSchemaContextListener(this); } - // Temporary until the static instance is removed. - @Deprecated - private ControllerContext() { - } - public static ControllerContext newInstance(SchemaService schemaService, DOMMountPointService mountService, DOMSchemaService domSchemaService) { final DOMYangTextSourceProvider yangTextSourceProvider = (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions().get(DOMYangTextSourceProvider.class); - INSTANCE.mountService = mountService; - INSTANCE.yangTextSourceProvider = yangTextSourceProvider; - - INSTANCE.onGlobalContextUpdated(schemaService.getGlobalContext()); - INSTANCE.listenerRegistration = schemaService.registerSchemaContextListener(INSTANCE); - - return INSTANCE; - //return new ControllerContext(schemaService, mountService, domSchemaServiceExtension); - } - - @Deprecated - public static ControllerContext getInstance() { - return INSTANCE; + return new ControllerContext(schemaService, mountService, yangTextSourceProvider); } private void setGlobalSchema(final SchemaContext globalSchema) { diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java index e6f2839344..885d187485 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java @@ -36,27 +36,14 @@ public final class StatisticsRestconfServiceWrapper implements RestconfService { AtomicLong failurePut = new AtomicLong(); AtomicLong failureDelete = new AtomicLong(); - private static final StatisticsRestconfServiceWrapper INSTANCE = new StatisticsRestconfServiceWrapper(); - - private RestconfService delegate; - - @Deprecated - private StatisticsRestconfServiceWrapper() { - } + private final RestconfService delegate; private StatisticsRestconfServiceWrapper(final RestconfService delegate) { this.delegate = delegate; } - @Deprecated - public static StatisticsRestconfServiceWrapper getInstance() { - return INSTANCE; - } - public static StatisticsRestconfServiceWrapper newInstance(RestconfService delegate) { - INSTANCE.delegate = delegate; - return INSTANCE; - //return new StatisticsRestconfServiceWrapper(delegate); + return new StatisticsRestconfServiceWrapper(delegate); } @Override diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrar.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrar.java new file mode 100644 index 0000000000..7e441e9d19 --- /dev/null +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrar.java @@ -0,0 +1,20 @@ +/* + * 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.netconf.sal.restconf.web; + +/** + * Registers the web components for the restconf bierman-02 endpoint. + * + * @author Thomas Pantelis + */ +public interface Bierman02WebRegistrar { + + void registerWithAuthentication(); + + void registerWithoutAuthentication(); +} diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrarImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrarImpl.java new file mode 100644 index 0000000000..034e26869f --- /dev/null +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrarImpl.java @@ -0,0 +1,84 @@ +/* + * 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.netconf.sal.restconf.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; + +/** + * Implementation of Bierman02WebRegistrar. + * + * @author Thomas Pantelis + */ +public class Bierman02WebRegistrarImpl implements Bierman02WebRegistrar { + + private WebContextRegistration registraton; + private final WebServer webServer; + private final WebContextSecurer webContextSecurer; + private final Application webApp; + private final CustomFilterAdapterConfiguration customFilterAdapterConfig; + + public Bierman02WebRegistrarImpl(WebServer webServer, WebContextSecurer webContextSecurer, + Application webApp, CustomFilterAdapterConfiguration customFilterAdapterConfig) { + this.webServer = webServer; + this.webContextSecurer = webContextSecurer; + this.webApp = webApp; + this.customFilterAdapterConfig = customFilterAdapterConfig; + } + + public void close() { + if (registraton != null) { + registraton.close(); + } + } + + @Override + public void registerWithAuthentication() { + register(true); + } + + @Override + public void registerWithoutAuthentication() { + register(false); + } + + private void register(boolean authenticate) { + WebContextBuilder webContextBuilder = WebContext.builder().contextPath("restconf").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()); + + if (authenticate) { + webContextSecurer.requireAuthentication(webContextBuilder, "/*"); + } + + try { + registraton = webServer.registerWebContext(webContextBuilder.build()); + } catch (ServletException e) { + throw new RuntimeException("Failed to register the web context", e); + } + } +} diff --git a/restconf/restconf-nb-bierman02/src/main/resources/WEB-INF/web.xml b/restconf/restconf-nb-bierman02/src/main/resources/WEB-INF/web.xml deleted file mode 100644 index c555bd2b0d..0000000000 --- a/restconf/restconf-nb-bierman02/src/main/resources/WEB-INF/web.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - JAXRSRestconf - com.sun.jersey.spi.container.servlet.ServletContainer - - javax.ws.rs.Application - org.opendaylight.netconf.sal.rest.impl.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 - /* - - - - - JAXRSRestconf - /* - - - - 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 - /* - - - - - NB api - /* - POST - GET - PUT - PATCH - DELETE - HEAD - - - - diff --git a/restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml b/restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml index aeb2b6f21b..afdc803d77 100644 --- a/restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml +++ b/restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml @@ -34,9 +34,6 @@ - - - @@ -86,6 +83,12 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java index 286db87835..a053870088 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java @@ -164,13 +164,6 @@ public class BrokerFacadeTest { assertSame("readOperationalData", this.dummyNode, actualNode); } - @Test(expected = RestconfDocumentedException.class) - public void testReadOperationalDataWithNoDataBroker() { - this.brokerFacade.close(); - - this.brokerFacade.readOperationalData(this.instanceID); - } - @Test public void test503() throws Exception { final RpcError error = RpcResultBuilder.newError( @@ -204,12 +197,6 @@ public class BrokerFacadeTest { assertSame("invokeRpc", expResult, actualResult); } - @Test(expected = RestconfDocumentedException.class) - public void testInvokeRpcWithNoConsumerSession() { - brokerFacade.close(); - this.brokerFacade.invokeRpc(this.type, this.dummyNode); - } - @Test public void testCommitConfigurationDataPut() throws Exception { @SuppressWarnings("unchecked") -- 2.36.6