Convert bierman02 from web.xml to programmtic web API 61/71061/2
authorTom Pantelis <tompantelis@gmail.com>
Wed, 18 Apr 2018 01:39:22 +0000 (21:39 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Wed, 18 Apr 2018 02:26:15 +0000 (22:26 -0400)
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 <tompantelis@gmail.com>
22 files changed:
features/restconf/odl-restconf-base/pom.xml [new file with mode: 0644]
features/restconf/odl-restconf-noauth/pom.xml
features/restconf/odl-restconf/pom.xml
features/restconf/pom.xml
restconf/pom.xml
restconf/restconf-common/pom.xml
restconf/restconf-nb-bierman02-auth/pom.xml [new file with mode: 0644]
restconf/restconf-nb-bierman02-auth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/auth/WebInitializer.java [new file with mode: 0644]
restconf/restconf-nb-bierman02-auth/src/main/resources/org/opendaylight/blueprint/bierman02-auth.xml [new file with mode: 0644]
restconf/restconf-nb-bierman02-noauth/pom.xml [new file with mode: 0644]
restconf/restconf-nb-bierman02-noauth/src/main/java/org/opendaylight/restconf/nb/bierman02/web/noauth/WebInitializer.java [new file with mode: 0644]
restconf/restconf-nb-bierman02-noauth/src/main/resources/org/opendaylight/blueprint/bierman02-noauth.xml [new file with mode: 0644]
restconf/restconf-nb-bierman02/pom.xml
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrar.java [new file with mode: 0644]
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/web/Bierman02WebRegistrarImpl.java [new file with mode: 0644]
restconf/restconf-nb-bierman02/src/main/resources/WEB-INF/web.xml [deleted file]
restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java

diff --git a/features/restconf/odl-restconf-base/pom.xml b/features/restconf/odl-restconf-base/pom.xml
new file mode 100644 (file)
index 0000000..9dc1725
--- /dev/null
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright © 2017 Red Hat, Inc. 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-base</artifactId>
+    <version>1.8.0-SNAPSHOT</version>
+    <packaging>feature</packaging>
+
+    <name>OpenDaylight :: Restconf :: Base</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-bierman02</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.netconf</groupId>
+            <artifactId>sal-rest-connector-config</artifactId>
+            <version>${project.version}</version>
+            <type>cfg</type>
+            <classifier>restconf</classifier>
+        </dependency>
+    </dependencies>
+</project>
index f63beb8a647dddb7024ccdc9c25f89e867dd60b2..a4940392f4326e3015e29ca83dbfdc495c0f8060 100644 (file)
     <dependencies>
         <dependency>
             <groupId>org.opendaylight.netconf</groupId>
-            <artifactId>odl-restconf-common</artifactId>
+            <artifactId>odl-restconf-base</artifactId>
+            <version>${project.version}</version>
             <type>xml</type>
             <classifier>features</classifier>
         </dependency>
-
-        <dependency>
-            <groupId>org.opendaylight.netconf</groupId>
-            <artifactId>restconf-nb-bierman02</artifactId>
-            <version>${project.version}</version>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.netconf</groupId>
-            <artifactId>sal-rest-connector-config</artifactId>
+            <artifactId>restconf-nb-bierman02-noauth</artifactId>
             <version>${project.version}</version>
-            <type>cfg</type>
-            <classifier>restconf</classifier>
         </dependency>
     </dependencies>
 </project>
index f190f1a54c8ada5146da754b2eb89554393e4720..003d60c814424288f76e1d839e4bd381fc067b8b 100644 (file)
     <name>OpenDaylight :: Restconf</name>
 
     <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>
-            <type>xml</type>
-            <classifier>features</classifier>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.netconf</groupId>
-            <artifactId>odl-restconf-noauth</artifactId>
+            <artifactId>odl-restconf-base</artifactId>
             <version>${project.version}</version>
             <type>xml</type>
             <classifier>features</classifier>
         </dependency>
-
         <dependency>
-            <groupId>org.opendaylight.odlparent</groupId>
-            <artifactId>odl-jackson-2.8</artifactId>
-            <version>3.1.0</version>
-            <type>xml</type>
-            <classifier>features</classifier>
+            <groupId>org.opendaylight.netconf</groupId>
+            <artifactId>restconf-nb-bierman02-auth</artifactId>
+            <version>${project.version}</version>
         </dependency>
     </dependencies>
 </project>
index 0f47d805b3427a302b86b9f68b0d512637fd17f2..7c8334478ca87321572b6882edc8658d4c46cb77 100644 (file)
@@ -23,6 +23,7 @@
         <module>features-restconf</module>
         <module>odl-mdsal-apidocs</module>
         <module>odl-restconf</module>
+        <module>odl-restconf-base</module>
         <module>odl-restconf-all</module>
         <module>odl-restconf-common</module>
         <module>odl-restconf-noauth</module>
index 4d3a097b4101d742288d1415b61f93da17600add..945e966c4b0aa6d6d300ed7211f192cdce6a048c 100644 (file)
@@ -29,6 +29,8 @@
         <module>restconf-common-models</module>
         <module>restconf-common</module>
         <module>restconf-nb-bierman02</module>
+        <module>restconf-nb-bierman02-auth</module>
+        <module>restconf-nb-bierman02-noauth</module>
         <module>restconf-nb-rfc8040</module>
         <module>sal-rest-connector-config</module>
         <module>sal-rest-docgen</module>
index ccbeb2dd1a4b44b90600a6a2b3e973b7f041a8fb..724c2cf673702b41986858c4d574d3de950df4fc 100644 (file)
       <scope>test</scope>
     </dependency>
   </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <extensions>true</extensions>
-        <configuration>
-          <instructions>
-            <Import-Package>
-              !javax.annotation,
-              javax.ws.rs.*;version="[1.1.0,2.0.0)",
-              *
-            </Import-Package>
-          </instructions>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
 </project>
diff --git a/restconf/restconf-nb-bierman02-auth/pom.xml b/restconf/restconf-nb-bierman02-auth/pom.xml
new file mode 100644 (file)
index 0000000..18f6100
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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
+-->
+<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.netconf</groupId>
+    <artifactId>restconf-parent</artifactId>
+    <version>1.8.0-SNAPSHOT</version>
+    <relativePath>../restconf-parent</relativePath>
+  </parent>
+
+  <groupId>org.opendaylight.netconf</groupId>
+  <artifactId>restconf-nb-bierman02-auth</artifactId>
+  <packaging>bundle</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.netconf</groupId>
+      <artifactId>restconf-nb-bierman02</artifactId>
+    </dependency>
+  </dependencies>
+</project>
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 (file)
index 0000000..4f1af41
--- /dev/null
@@ -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 (file)
index 0000000..0a0b21f
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2018 Inocybe Technologies Inc. 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
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+  <reference id="webRegistrar" interface="org.opendaylight.netconf.sal.restconf.web.Bierman02WebRegistrar"/>
+
+  <bean class="org.opendaylight.restconf.nb.bierman02.web.auth.WebInitializer">
+    <argument ref="webRegistrar"/>
+  </bean>
+
+</blueprint>
diff --git a/restconf/restconf-nb-bierman02-noauth/pom.xml b/restconf/restconf-nb-bierman02-noauth/pom.xml
new file mode 100644 (file)
index 0000000..079e98f
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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
+-->
+<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.netconf</groupId>
+    <artifactId>restconf-parent</artifactId>
+    <version>1.8.0-SNAPSHOT</version>
+    <relativePath>../restconf-parent</relativePath>
+  </parent>
+
+  <groupId>org.opendaylight.netconf</groupId>
+  <artifactId>restconf-nb-bierman02-noauth</artifactId>
+  <packaging>bundle</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.netconf</groupId>
+      <artifactId>restconf-nb-bierman02</artifactId>
+    </dependency>
+  </dependencies>
+</project>
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 (file)
index 0000000..de8b97a
--- /dev/null
@@ -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 (file)
index 0000000..e31df8e
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2018 Inocybe Technologies Inc. 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
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+  <reference id="webRegistrar" interface="org.opendaylight.netconf.sal.restconf.web.Bierman02WebRegistrar"/>
+
+  <bean class="org.opendaylight.restconf.nb.bierman02.web.noauth.WebInitializer">
+    <argument ref="webRegistrar"/>
+  </bean>
+
+</blueprint>
index f10ee72d51f10b01a7fbbb584e2849c0d6fc033f..55bc5aab277517e28515ef14ac96197f7ce9ca7a 100644 (file)
       <artifactId>logback-classic</artifactId>
       <scope>test</scope>
     </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-filterchain</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.sun.jersey</groupId>
+      <artifactId>jersey-servlet</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-servlets</artifactId>
+    </dependency>
 
     <!-- Testing Dependencies -->
     <dependency>
               org.opendaylight.netconf.md.sal.rest.common.*,
               org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.rest.connector.rev140724.*,
             </Private-Package>
-            <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>/restconf</Web-ContextPath>
           </instructions>
         </configuration>
       </plugin>
index 9dd5a59ddae62d96fa245afa3bc354ed46d94bd2..54a81d6b9871f4cf7925865b932837fe0013ecd0 100644 (file)
@@ -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<Class<?>> getClasses() {
@@ -35,13 +45,11 @@ public class RestconfApplication extends Application {
     @Override
     public Set<Object> getSingletons() {
         final Set<Object> 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));
index 8c1299e0cd50a072854d624391e716a8fa8c6c82..a5ea3e00eea510014a5943ba2bd8ab8a1131cd45 100644 (file)
@@ -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<Void, TransactionCommitFailedException> 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<Void, TransactionCommitFailedException> commitConfigurationDataDelete(
             final YangInstanceIdentifier path) {
-        checkPreconditions();
         return deleteDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path);
     }
 
@@ -518,7 +489,6 @@ public class BrokerFacade implements Closeable {
     // RPC
     public CheckedFuture<DOMRpcResult, DOMRpcException> 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;
         }
index 866eb0ccf488380570202bff478238efc8651a9e..c8e6adcc968f730d5f660dd90b94dfd99652e37e 100644 (file)
@@ -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<Map<QName, RpcDefinition>> qnameToRpc = new AtomicReference<>(Collections.emptyMap());
 
-    private DOMMountPointService mountService;
-    private DOMYangTextSourceProvider yangTextSourceProvider;
-    private ListenerRegistration<SchemaContextListener> listenerRegistration;
+    private final DOMMountPointService mountService;
+    private final DOMYangTextSourceProvider yangTextSourceProvider;
+    private final ListenerRegistration<SchemaContextListener> 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) {
index e6f2839344eb2949fc3e86201e1729f75d7e495a..885d187485accc7bff28ada9e3dcc86cf0597e65 100644 (file)
@@ -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 (file)
index 0000000..7e441e9
--- /dev/null
@@ -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 (file)
index 0000000..034e268
--- /dev/null
@@ -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 (file)
index c555bd2..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-<?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>JAXRSRestconf</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.netconf.sal.rest.impl.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>JAXRSRestconf</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>NB 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>
index aeb2b6f21bd17d503fdad420db05d4e5cd26f05b..afdc803d770f5185dd9cc6fc2e262f2caa1727f2 100644 (file)
@@ -34,9 +34,6 @@
     </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="schemaService" interface="org.opendaylight.controller.sal.core.api.model.SchemaService"/>
   <reference id="domRpcService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcService"/>
   <reference id="domMountPointService" interface="org.opendaylight.controller.md.sal.dom.api.DOMMountPointService"/>
     <argument ref="webSocketPort"/>
   </bean>
 
+  <bean id="restconfApplication" class="org.opendaylight.netconf.sal.rest.impl.RestconfApplication">
+    <argument ref="controllerContext"/>
+    <argument ref="brokerFacade"/>
+    <argument ref="statsServiceWrapper"/>
+  </bean>
+
   <!-- JSONRestconfService -->
   <bean id="jsonRestconfServiceDraft02"
       class="org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl"
   <service ref="jsonRestconfServiceDraft02" odl:type="default"
       interface="org.opendaylight.netconf.sal.restconf.api.JSONRestconfService" />
 
+  <!-- Bierman02WebRegistrar -->
+
+  <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="webRegistrar" class="org.opendaylight.netconf.sal.restconf.web.Bierman02WebRegistrarImpl"
+          destroy-method="close">
+    <argument ref="webServer"/>
+    <argument ref="webContextSecurer"/>
+    <argument ref="restconfApplication"/>
+    <argument ref="customFilterAdapterConfig"/>
+  </bean>
+
+  <service ref="webRegistrar"
+      interface="org.opendaylight.netconf.sal.restconf.web.Bierman02WebRegistrar" />
+
 </blueprint>
index 286db87835b6f57fb30a00dd5e3ab831e24ea72a..a05387008820df13e61bf000c332804a0025abe5 100644 (file)
@@ -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")