X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdbcapi%2Fresources%2FAAFAuthenticationFilter.java;h=1c3a504bc6356792f4702b0b8724f95d8ecf7699;hb=18eaae524174fac4f21d83c94bb8347a29d9f879;hp=8739511d311a5acd253534adb08981791cb63e31;hpb=4444a934c6ad97d0222abc351af4c392d42f654e;p=dmaap%2Fdbcapi.git diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/AAFAuthenticationFilter.java b/src/main/java/org/onap/dmaap/dbcapi/resources/AAFAuthenticationFilter.java index 8739511..1c3a504 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/resources/AAFAuthenticationFilter.java +++ b/src/main/java/org/onap/dmaap/dbcapi/resources/AAFAuthenticationFilter.java @@ -21,7 +21,9 @@ package org.onap.dmaap.dbcapi.resources; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.FileInputStream; import java.io.IOException; +import java.util.Properties; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -40,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); } @@ -58,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 { @@ -94,11 +96,11 @@ 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()) { - cadiFilter = new CadiFilter(new PropAccess(cadiPropertiesFile)); + cadiFilter = new CadiFilter(loadCadiProperties(cadiPropertiesFile)); } else { throw new ServletException("Cannot initialize CADI filter.CADI properties not available."); } @@ -109,6 +111,18 @@ public class AAFAuthenticationFilter implements Filter { } } + private PropAccess loadCadiProperties(String propertiesFilePath) throws ServletException { + try { + Properties props = new Properties(); + props.load(new FileInputStream(propertiesFilePath)); + return new PropAccess(props); + } catch (IOException e) { + String msg = "Could not load CADI properties file: " + propertiesFilePath; + LOGGER.error(msg, e); + throw new ServletException(msg); + } + } + DmaapConfig getConfig() { return (DmaapConfig) DmaapConfig.getConfig(); } @@ -122,7 +136,7 @@ public class AAFAuthenticationFilter implements Filter { this.cadiFilter = cadiFilter; } - boolean isAafEnabled() { - return isAafEnabled; + boolean isCadiEnabled() { + return isCadiEnabled; } }