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;
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
* 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);
+ }
}
/**
* 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);
}
}
* 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);
+ }
}
}