Update gra ms to use CadiFilter instead of shiro 71/120571/4
authorDan Timoney <dtimoney@att.com>
Thu, 15 Apr 2021 13:58:19 +0000 (09:58 -0400)
committerDan Timoney <dtimoney@att.com>
Tue, 20 Apr 2021 18:32:59 +0000 (14:32 -0400)
Update code to use CadiFilter to integrate with AAF instead of
shiro plugin, which is no longer supported (also, shiro has known,
unresolved security vulnerabilities)

Change-Id: Icaa922ac833f0a44c310847740f6745624242a2b
Issue-ID: SDNC-1523
Signed-off-by: Dan Timoney <dtimoney@att.com>
ms/generic-resource-api/pom.xml
ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/FilterConfiguration.java [new file with mode: 0644]
ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/GenericResourceMsApp.java
ms/generic-resource-api/src/main/resources/shiro-users.properties [deleted file]
ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/GenericResourceMsAppTest.java [deleted file]

index a851a14..416eaca 100644 (file)
@@ -19,8 +19,7 @@
 
     <properties>
         <start-class>org.onap.sdnc.apps.ms.gra.GenericResourceMsApp</start-class>
-        <shiro.version>1.5.0</shiro.version>
-        <aaf-shiro-bundle.version>2.1.13</aaf-shiro-bundle.version>
+        <aaf.cadi.version>2.1.21</aaf.cadi.version>
         <ccsdk.apps.version>1.2.0-SNAPSHOT</ccsdk.apps.version>
         <ccsdk.docker.version>1.1-STAGING-latest</ccsdk.docker.version>
         <sdnc.northbound.version>2.2.0-SNAPSHOT</sdnc.northbound.version>
             <groupId>io.swagger</groupId>
             <artifactId>swagger-annotations</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.shiro</groupId>
-            <artifactId>shiro-spring-boot-web-starter</artifactId>
-            <version>${shiro.version}</version>
+               <dependency>
+                       <groupId>org.springframework.boot</groupId>
+                       <artifactId>spring-boot-starter-web</artifactId>
             <exclusions>
                 <exclusion>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-starter-logging</artifactId>
                 </exclusion>
             </exclusions>
-        </dependency>
+               </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-log4j2</artifactId>
             <artifactId>jackson-dataformat-xml</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.onap.aaf.cadi</groupId>
-            <artifactId>aaf-cadi-shiro</artifactId>
-            <version>${aaf-shiro-bundle.version}</version>
+            <groupId>org.onap.aaf.authz</groupId>
+            <artifactId>aaf-auth-client</artifactId>
+            <version>${aaf.cadi.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.aaf.authz</groupId>
+            <artifactId>aaf-misc-env</artifactId>
+            <version>${aaf.cadi.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.aaf.authz</groupId>
+            <artifactId>aaf-misc-rosetta</artifactId>
+            <version>${aaf.cadi.version}</version>
         </dependency>
-
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>2.19.1</version>
                 <configuration>
-                    <forkMode>always</forkMode>
                     <environmentVariables>
                         <SDNC_CONFIG_DIR>${basedir}/src/test/resources</SDNC_CONFIG_DIR>
                         <SVCLOGIC_PROPERTIES>${basedir}/src/test/resources/svclogic.properties</SVCLOGIC_PROPERTIES>
diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/FilterConfiguration.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/FilterConfiguration.java
new file mode 100644 (file)
index 0000000..6b96541
--- /dev/null
@@ -0,0 +1,35 @@
+package org.onap.sdnc.apps.ms.gra;\r
+\r
+import org.onap.aaf.cadi.filter.CadiFilter;\r
+import org.onap.ccsdk.apps.filters.ContentTypeFilter;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.springframework.boot.web.servlet.FilterRegistrationBean;\r
+import org.springframework.context.annotation.Bean;\r
+import org.springframework.context.annotation.Configuration;\r
+import org.springframework.core.annotation.Order;\r
+\r
+@Configuration\r
+public class FilterConfiguration {\r
+\r
+    private static final Logger log = LoggerFactory.getLogger(FilterConfiguration.class);\r
+\r
+       @Bean\r
+       @Order(1)\r
+       public FilterRegistrationBean<CadiFilter> cadiFilter() {\r
+               CadiFilter filter = new CadiFilter();\r
+\r
+               FilterRegistrationBean<CadiFilter> registrationBean = new FilterRegistrationBean<>();\r
+               registrationBean.setFilter(filter);\r
+               if ("none".equals(System.getProperty("cadi_prop_files", "none"))) {\r
+            log.info("cadi_prop_files undefined, AAF CADI disabled");\r
+                       registrationBean.addUrlPatterns("/xxxx/*");\r
+               } else {\r
+                       registrationBean.addUrlPatterns("/*");\r
+                       registrationBean.addInitParameter("cadi_prop_files", System.getProperty("cadi_prop_files"));\r
+               }\r
+\r
+               return registrationBean;\r
+       }\r
+\r
+}\r
index a0e9595..d436d21 100644 (file)
 
 package org.onap.sdnc.apps.ms.gra;
 
-import org.apache.shiro.realm.Realm;
-import org.apache.shiro.realm.text.PropertiesRealm;
-import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
-import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
-import org.onap.aaf.cadi.shiro.AAFRealm;
 import org.onap.ccsdk.apps.ms.sliboot.controllers.RestconfApiController;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
-import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Import;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
-@SpringBootApplication(scanBasePackages = { "org.onap.sdnc.apps.ms.gra", "org.onap.ccsdk.apps.services", "org.onap.ccsdk.apps.filters" })
+@SpringBootApplication(scanBasePackages = { "org.onap.sdnc.apps.ms.gra", "org.onap.ccsdk.apps.services" })
 @EnableJpaRepositories(basePackages = { "org.onap.sdnc.apps.ms.gra", "org.onap.ccsdk.apps.ms.sliboot" })
 @EntityScan(basePackages = { "org.onap.sdnc.apps.ms.gra", "org.onap.ccsdk.apps.ms.sliboot" })
 @EnableTransactionManagement
@@ -52,36 +46,4 @@ public class GenericResourceMsApp {
     public static void main(String[] args) throws Exception {
         SpringApplication.run(GenericResourceMsApp.class, args);
     }
-
-    @Bean
-    public Realm realm() {
-
-        // If cadi prop files is not defined use local properties realm
-        // src/main/resources/shiro-users.properties
-        if ("none".equals(System.getProperty("cadi_prop_files", "none"))) {
-            log.info("cadi_prop_files undefined, AAF Realm will not be set");
-            PropertiesRealm realm = new PropertiesRealm();
-            return realm;
-        } else {
-            AAFRealm realm = new AAFRealm();
-            return realm;
-        }
-
-    }
-
-    @Bean
-    public ShiroFilterChainDefinition shiroFilterChainDefinition() {
-        DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();
-
-        // if cadi prop files is not set disable authentication
-        if ("none".equals(System.getProperty("cadi_prop_files", "none"))) {
-            chainDefinition.addPathDefinition("/**", "anon");
-        } else {
-            log.info("Loaded property cadi_prop_files, AAF REALM set");
-            chainDefinition.addPathDefinition("/**", "authcBasic, rest[org.onap.sdnc.odl:odl-api]");
-        }
-
-        return chainDefinition;
-    }
-
 }
diff --git a/ms/generic-resource-api/src/main/resources/shiro-users.properties b/ms/generic-resource-api/src/main/resources/shiro-users.properties
deleted file mode 100644 (file)
index df4b1ae..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-user.admin = Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U,service
-role.service = odl-api:*
-
diff --git a/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/GenericResourceMsAppTest.java b/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/GenericResourceMsAppTest.java
deleted file mode 100644 (file)
index 166278a..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.onap.sdnc.apps.ms.gra.controllers;
-
-import org.apache.shiro.realm.Realm;
-import org.apache.shiro.realm.text.PropertiesRealm;
-import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.sdnc.apps.ms.gra.GenericResourceMsApp;
-
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-public class GenericResourceMsAppTest {
-
-    GenericResourceMsApp app;
-
-    @Before
-    public  void setUp() throws Exception {
-        app = new GenericResourceMsApp();
-        System.out.println("GenericResourceMsAppTest: Setting serviceLogicProperties, serviceLogicDirectory and sdnc.config.dir");
-        System.setProperty("serviceLogicProperties", "src/test/resources/svclogic.properties");
-        System.setProperty("serviceLogicDirectory", "src/test/resources/svclogic");
-        System.setProperty("sdnc.config.dir", "src/test/resources");
-   
-    }
-
-    @Test
-    public void realm() {
-        Realm realm = app.realm();
-        assertTrue(realm instanceof PropertiesRealm);
-
-
-    }
-
-    @Test
-    public void shiroFilterChainDefinition() {
-        ShiroFilterChainDefinition chainDefinition = app.shiroFilterChainDefinition();
-        Map<String, String> chainMap = chainDefinition.getFilterChainMap();
-        assertEquals("anon", chainMap.get("/**"));
-
-
-    }
-}
\ No newline at end of file