move authN and authZ filter decission to enableCADI flag 95/86495/1
authorTomek Kaminski <tomasz.kaminski@nokia.com>
Mon, 29 Apr 2019 08:57:38 +0000 (10:57 +0200)
committerTomek Kaminski <tomasz.kaminski@nokia.com>
Mon, 29 Apr 2019 08:57:38 +0000 (10:57 +0200)
Change-Id: If4aa4fb58c0eb4431ec6a6377db12fa3da23682e
Issue-ID: DMAAP-1181
Signed-off-by: Tomek Kaminski <tomasz.kaminski@nokia.com>
src/main/java/org/onap/dmaap/dbcapi/resources/AAFAuthenticationFilter.java
src/main/java/org/onap/dmaap/dbcapi/resources/AAFAuthorizationFilter.java
src/main/java/org/onap/dmaap/dbcapi/resources/AuthorizationFilter.java
src/test/java/org/onap/dmaap/dbcapi/resources/AAFAuthenticationFilterTest.java
src/test/java/org/onap/dmaap/dbcapi/resources/AAFAuthorizationFilterTest.java

index c5c29fa..1c3a504 100644 (file)
@@ -42,16 +42,16 @@ public class AAFAuthenticationFilter implements Filter {
 
     private static final Logger LOGGER = Logger.getLogger(AAFAuthenticationFilter.class.getName());
     static final String CADI_PROPERTIES = "cadi.properties";
-    static final String AAF_AUTHN_FLAG = "UseAAF";
+    static final String CADI_AUTHN_FLAG = "enableCADI";
 
-    private boolean isAafEnabled;
+    private boolean isCadiEnabled;
     private CadiFilter cadiFilter;
 
     @Override
     public void init(FilterConfig filterConfig) throws ServletException {
         DmaapConfig dmaapConfig = getConfig();
-        String flag = dmaapConfig.getProperty(AAF_AUTHN_FLAG, "false");
-        isAafEnabled = "true".equalsIgnoreCase(flag);
+        String flag = dmaapConfig.getProperty(CADI_AUTHN_FLAG, "false");
+        isCadiEnabled = "true".equalsIgnoreCase(flag);
         initCadi(dmaapConfig);
     }
 
@@ -60,7 +60,7 @@ public class AAFAuthenticationFilter implements Filter {
     public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
         throws IOException, ServletException {
 
-        if(isAafEnabled) {
+        if(isCadiEnabled) {
             cadiFilter.doFilter(servletRequest, servletResponse, filterChain);
             updateResponseBody((HttpServletResponse)servletResponse);
         } else {
@@ -96,7 +96,7 @@ public class AAFAuthenticationFilter implements Filter {
     }
 
     private void initCadi(DmaapConfig dmaapConfig) throws ServletException {
-        if(isAafEnabled) {
+        if(isCadiEnabled) {
             try {
                 String cadiPropertiesFile = dmaapConfig.getProperty(CADI_PROPERTIES);
                 if(cadiPropertiesFile != null && !cadiPropertiesFile.isEmpty()) {
@@ -136,7 +136,7 @@ public class AAFAuthenticationFilter implements Filter {
         this.cadiFilter = cadiFilter;
     }
 
-    boolean isAafEnabled() {
-        return isAafEnabled;
+    boolean isCadiEnabled() {
+        return isCadiEnabled;
     }
 }
index 5bc3dec..602de85 100644 (file)
@@ -40,16 +40,16 @@ import org.onap.dmaap.dbcapi.util.PermissionBuilder;
 public class AAFAuthorizationFilter implements Filter{
 
     private static final Logger LOGGER = Logger.getLogger(AAFAuthenticationFilter.class.getName());
-    static final String AAF_AUTHZ_FLAG = "UseAAF";
-    private boolean isAafEnabled = false;
+    static final String CADI_AUTHZ_FLAG = "enableCADI";
+    private boolean isCadiEnabled = false;
 
     private PermissionBuilder permissionBuilder;
 
     @Override
     public void init(FilterConfig filterConfig) throws ServletException {
         DmaapConfig dmaapConfig = getConfig();
-        isAafEnabled = "true".equalsIgnoreCase(dmaapConfig.getProperty(AAF_AUTHZ_FLAG, "false"));
-        if(isAafEnabled) {
+        isCadiEnabled = "true".equalsIgnoreCase(dmaapConfig.getProperty(CADI_AUTHZ_FLAG, "false"));
+        if(isCadiEnabled) {
             permissionBuilder = new PermissionBuilder(dmaapConfig, getDmaapService());
         }
     }
@@ -58,7 +58,7 @@ public class AAFAuthorizationFilter implements Filter{
     public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
         throws IOException, ServletException {
 
-        if(isAafEnabled) {
+        if(isCadiEnabled) {
             HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
             permissionBuilder.updateDmaapInstance();
             String permission = permissionBuilder.buildPermission(httpRequest);
@@ -110,7 +110,7 @@ public class AAFAuthorizationFilter implements Filter{
         this.permissionBuilder = permissionBuilder;
     }
 
-    void setAafEnabled(boolean aafEnabled) {
-        isAafEnabled = aafEnabled;
+    void setCadiEnabled(boolean cadiEnabled) {
+        isCadiEnabled = cadiEnabled;
     }
 }
index 3ed5717..64aeea7 100644 (file)
@@ -32,22 +32,22 @@ import org.onap.dmaap.dbcapi.util.DmaapConfig;
 @Authorization
 public class AuthorizationFilter implements ContainerRequestFilter   {
 
-       private static final String AAF_FLAG = "UseAAF";
+       private static final String AAF_CADI_FLAG = "enableCADI";
        private final Logger logger = Logger.getLogger(AuthorizationFilter.class.getName());
        private final ResponseBuilder responseBuilder = new ResponseBuilder();
-       private final boolean isAafEnabled;
+       private final boolean isCadiEnabled;
 
 
        public AuthorizationFilter() {
                DmaapConfig dmaapConfig = (DmaapConfig) DmaapConfig.getConfig();
-               String flag = dmaapConfig.getProperty(AAF_FLAG, "false");
-               isAafEnabled = "true".equalsIgnoreCase(flag);
+               String flag = dmaapConfig.getProperty(AAF_CADI_FLAG, "false");
+               isCadiEnabled = "true".equalsIgnoreCase(flag);
        }
 
        @Override
        public void filter(ContainerRequestContext requestContext) {
 
-               if(!isAafEnabled) {
+               if(!isCadiEnabled) {
                        ApiService apiResp = new ApiService()
                                .setAuth(requestContext.getHeaderString("Authorization"))
                                .setUriPath(requestContext.getUriInfo().getPath())
index 53c8021..137c518 100644 (file)
@@ -78,20 +78,20 @@ public class AAFAuthenticationFilterTest {
     @Test
     public void init_shouldNotInitializeCADI_whenAafIsNotUsed() throws Exception {
         //given
-        doReturn("false").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+        doReturn("false").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
 
         //when
         filter.init(filterConfig);
 
         //then
-        assertFalse(filter.isAafEnabled());
+        assertFalse(filter.isCadiEnabled());
         assertNull(filter.getCadiFilter());
     }
 
     @Test
     public void doFilter_shouldSkipCADI_whenAafIsNotUsed() throws Exception {
         //given
-        doReturn("false").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+        doReturn("false").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
         filter.init(filterConfig);
         filter.setCadiFilter(cadiFilterMock);
 
@@ -106,7 +106,7 @@ public class AAFAuthenticationFilterTest {
     @Test
     public void init_shouldFail_whenAafIsUsed_andCadiPropertiesHasNotBeenSet() throws Exception {
         //given
-        doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+        doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
         doReturn("").when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
 
         //then
@@ -121,7 +121,7 @@ public class AAFAuthenticationFilterTest {
     public void init_shouldFail_whenAafIsUsed_andInvalidCadiPropertiesSet() throws Exception {
         //given
         String invalidFilePath = "src/test/resources/notExisting.properties";
-        doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+        doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
         doReturn(invalidFilePath).when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
 
         //then
@@ -135,14 +135,14 @@ public class AAFAuthenticationFilterTest {
     @Test
     public void init_shouldInitializeCADI_whenAafIsUsed_andValidCadiPropertiesSet() throws Exception {
         //given
-        doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+        doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
         doReturn("src/test/resources/cadi.properties").when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
 
         //when
         filter.init(filterConfig);
 
         //then
-        assertTrue(filter.isAafEnabled());
+        assertTrue(filter.isCadiEnabled());
         assertNotNull(filter.getCadiFilter());
     }
 
@@ -184,7 +184,7 @@ public class AAFAuthenticationFilterTest {
     }
 
     private void initCADIFilter() throws Exception{
-        doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.AAF_AUTHN_FLAG), anyString());
+        doReturn("true").when(dmaapConfig).getProperty(eq(AAFAuthenticationFilter.CADI_AUTHN_FLAG), anyString());
         doReturn("src/test/resources/cadi.properties").when(dmaapConfig).getProperty(AAFAuthenticationFilter.CADI_PROPERTIES);
         filter.init(filterConfig);
         filter.setCadiFilter(cadiFilterMock);
index 73794cd..a935bc2 100644 (file)
@@ -107,7 +107,7 @@ public class AAFAuthorizationFilterTest {
     @Test
     public void doFilter_shouldSkipAuthorization_whenAAFnotUsed() throws Exception {
         //given
-        filter.setAafEnabled(false);
+        filter.setCadiEnabled(false);
 
         //when
         filter.doFilter(servletRequest,servletResponse,filterChain);
@@ -125,7 +125,7 @@ public class AAFAuthorizationFilterTest {
         String permission = "org.onap.dmaap-bc.api.topics|mr|GET";
         when(permissionBuilder.buildPermission(servletRequest)).thenReturn(permission);
         configureServletRequest(permission, user, true);
-        filter.setAafEnabled(true);
+        filter.setCadiEnabled(true);
 
         //when
         filter.doFilter(servletRequest,servletResponse,filterChain);
@@ -143,7 +143,7 @@ public class AAFAuthorizationFilterTest {
         String permission = "org.onap.dmaap-bc.api.topics|mr|GET";
         when(permissionBuilder.buildPermission(servletRequest)).thenReturn(permission);
         configureServletRequest(permission, user, false);
-        filter.setAafEnabled(true);
+        filter.setCadiEnabled(true);
 
         String errorMsgJson = "{\"code\":403,\"message\":\"User "+user+" does not have permission "
             + permission +"\",\"fields\":\"Authorization\",\"2xx\":false}";
@@ -167,6 +167,6 @@ public class AAFAuthorizationFilterTest {
     }
 
     private void configureAAFUsage(Boolean isUsed) {
-        doReturn(isUsed.toString()).when(dmaapConfig).getProperty(eq(AAFAuthorizationFilter.AAF_AUTHZ_FLAG), anyString());
+        doReturn(isUsed.toString()).when(dmaapConfig).getProperty(eq(AAFAuthorizationFilter.CADI_AUTHZ_FLAG), anyString());
     }
 }
\ No newline at end of file