Removal of useless files & bugfix
[clamp.git] / src / main / java / org / onap / clamp / clds / config / CldsSecurityConfigUsers.java
index a187ac5..db99dba 100644 (file)
 
 package org.onap.clamp.clds.config;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.io.IOException;
+
+import org.onap.clamp.clds.exception.CldsUsersException;
 import org.onap.clamp.clds.service.CldsUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -34,9 +40,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
 /**
  * This class is used to enable the HTTP authentication to login. It requires a
  * specific JSON file containing the user definition
@@ -68,9 +71,14 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter {
      * This method configures on which URL the authorization will be enabled.
      */
     @Override
-    protected void configure(HttpSecurity http) throws Exception {
-        http.csrf().disable().httpBasic().and().authorizeRequests().antMatchers("/restservices/clds/v1/user/**")
-                .authenticated().anyRequest().permitAll().and().logout();
+    protected void configure(HttpSecurity http) {
+        try {
+            http.csrf().disable().httpBasic().and().authorizeRequests().antMatchers("/restservices/clds/v1/user/**")
+                    .authenticated().anyRequest().permitAll().and().logout();
+        } catch (Exception e) {
+            logger.error("Exception occurred during the setup of the Web users in memory", e);
+            throw new CldsUsersException("Exception occurred during the setup of the Web users in memory", e);
+        }
     }
 
     /**
@@ -79,21 +87,25 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter {
      * the application.properties).
      * 
      * @param auth
-     * @throws Exception
      */
     @Autowired
-    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
-        CldsUser[] usersList = loadUsers();
+    public void configureGlobal(AuthenticationManagerBuilder auth) {
+        try {
+            CldsUser[] usersList = loadUsers();
 
-        // no users defined
-        if (null == usersList) {
-            logger.warn("No users defined. Users should be defined under " + cldsUsersFile);
-            return;
-        }
+            // no users defined
+            if (null == usersList) {
+                logger.warn("No users defined. Users should be defined under " + cldsUsersFile);
+                return;
+            }
 
-        for (CldsUser user : usersList) {
-            auth.inMemoryAuthentication().withUser(user.getUser()).password(user.getPassword())
-                    .roles(user.getPermissionsString());
+            for (CldsUser user : usersList) {
+                auth.inMemoryAuthentication().withUser(user.getUser()).password(user.getPassword())
+                        .roles(user.getPermissionsString());
+            }
+        } catch (Exception e) {
+            logger.error("Exception occurred during the setup of the Web users in memory", e);
+            throw new CldsUsersException("Exception occurred during the setup of the Web users in memory", e);
         }
     }
 
@@ -102,10 +114,14 @@ public class CldsSecurityConfigUsers extends WebSecurityConfigurerAdapter {
      * CldsUser.
      * 
      * @return The array of CldsUser
-     * @throws Exception
      */
-    private CldsUser[] loadUsers() throws Exception {
-        logger.info("Load from clds-users.properties");
-        return CldsUserJsonDecoder.decodeJson(appContext.getResource(cldsUsersFile).getInputStream());
+    private CldsUser[] loadUsers() {
+        try {
+            logger.info("Load from clds-users.properties");
+            return CldsUserJsonDecoder.decodeJson(appContext.getResource(cldsUsersFile).getInputStream());
+        } catch (IOException e) {
+            logger.error("Unable to decode the User Json file", e);
+            throw new CldsUsersException("Load from clds-users.properties", e);
+        }
     }
 }