sonar code issues addressed
[oam/tr069-adapter.git] / acs / cpe / src / main / java / org / commscope / tr069adapter / acs / cpe / handler / DeviceValidator.java
index 5caeb50..f0fb6bd 100644 (file)
@@ -18,6 +18,7 @@
 \r
 package org.commscope.tr069adapter.acs.cpe.handler;\r
 \r
+\r
 import java.nio.charset.StandardCharsets;\r
 import java.util.Base64;\r
 \r
@@ -27,6 +28,7 @@ import org.commscope.tr069adapter.acs.cpe.utils.FactorySrvcDependencyConfig;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.beans.factory.annotation.Value;\r
 import org.springframework.http.ResponseEntity;\r
 import org.springframework.stereotype.Component;\r
 import org.springframework.web.client.RestTemplate;\r
@@ -42,6 +44,9 @@ public class DeviceValidator {
   @Autowired\r
   RestTemplate restTemplate;\r
 \r
+  @Value("${config.isDeviceAuthorizationEnabled:true}")\r
+  private boolean isDeviceAuthorizationEnabled;\r
+\r
   public void setFactorySrvcDependencyConfig(\r
       FactorySrvcDependencyConfig factorySrvcDependencyConfig) {\r
     this.factorySrvcDependencyConfig = factorySrvcDependencyConfig;\r
@@ -53,6 +58,10 @@ public class DeviceValidator {
    * @return\r
    */\r
   public Boolean isDeviceAuthorized(Inform inform, String authorization) {\r
+    if(!isDeviceAuthorizationEnabled){\r
+      logger.debug("Device authentication is not needed here. Hence always authorizing.");\r
+      return true;\r
+    }\r
     if (authorization == null) {\r
       logger.debug("HTTP Challenge failed as Authorization header does not exist");\r
       return false;\r