X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fconfig%2FCldsSecurityConfigUsers.java;h=db99dbaf4fb59c9a24a5c9de01a1a7aaaceb4ee8;hb=2b15edd224cc6dcff90e170959102eb1a1bb1a50;hp=a187ac556918bc5df1ece602c0b94317dadbf319;hpb=78551555224bf3367c3635bf695978e903bcea14;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/config/CldsSecurityConfigUsers.java b/src/main/java/org/onap/clamp/clds/config/CldsSecurityConfigUsers.java index a187ac55..db99dbaf 100644 --- a/src/main/java/org/onap/clamp/clds/config/CldsSecurityConfigUsers.java +++ b/src/main/java/org/onap/clamp/clds/config/CldsSecurityConfigUsers.java @@ -23,6 +23,12 @@ 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); + } } }