Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 87ab01d4 authored by rodrfla's avatar rodrfla
Browse files

EDELIVERY-2301 Refactored ConfigFile class, used @Value annotation instead

parent 95edc56b
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.config;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Created by Flavio Santos
*/
@Configuration
@ComponentScan(basePackages = {
"eu.europa.ec"})
@PropertySources({
@PropertySource(value = "classpath:config.properties", ignoreResourceNotFound = true),
@PropertySource(value = "classpath:smp.config.properties", ignoreResourceNotFound = true)
})
public class CommonConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
......@@ -32,7 +32,7 @@ import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
/**
* Created by gutowpa on 12/07/2017.
* Created by Flavio Santos
*/
@Configuration
......
......@@ -15,7 +15,10 @@
package eu.europa.ec.edelivery.smp.config;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
/**
......@@ -30,15 +33,7 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
"eu.europa.ec.cipa.smp.server.hook",
"eu.europa.ec.cipa.smp.server.conversion",
"eu.europa.ec.cipa.smp.server.util"})
@PropertySources({
@PropertySource(value = "classpath:config.properties", ignoreResourceNotFound = true),
@PropertySource(value = "classpath:smp.config.properties", ignoreResourceNotFound = true)
})
@Import(DatabaseConfig.class)
@Import({CommonConfig.class, DatabaseConfig.class})
public class SmpAppConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.controllers;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
/**
* Created by gutowpa on 07/04/2017.
*/
@Controller
public class UsernameReturningTestController {
@RequestMapping("/getLoggedUsername")
@ResponseBody
public String getLoggedUsername(){
return SecurityContextHolder.getContext().getAuthentication().getName();
}
@RequestMapping("/error")
@ResponseBody
public ResponseEntity error(HttpServletRequest request, Throwable throwable){
return new ResponseEntity(HttpStatus.I_AM_A_TEAPOT);
}
}
......@@ -15,9 +15,10 @@
package eu.europa.ec.cipa.smp.server.security;
import eu.europa.ec.edelivery.smp.config.SmpAppConfig;
import eu.europa.ec.edelivery.smp.config.SmpWebAppConfig;
import eu.europa.ec.edelivery.smp.config.CommonConfig;
import eu.europa.ec.edelivery.smp.config.DatabaseConfig;
import eu.europa.ec.edelivery.smp.config.SpringSecurityConfig;
import eu.europa.ec.edelivery.smp.config.SpringSecurityTestConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -44,9 +45,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {
SmpAppConfig.class,
SmpWebAppConfig.class,
SpringSecurityConfig.class})
CommonConfig.class,
DatabaseConfig.class,
SpringSecurityConfig.class,
SpringSecurityTestConfig.class
})
@WebAppConfiguration
@Transactional
@Rollback(true)
......
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
/**
* Created by Flavio Santos
*/
@EnableWebSecurity
@ComponentScan(basePackages = {
"eu.europa.ec.cipa.smp.server.security"})
public class SpringSecurityTestConfig {
}
......@@ -45,6 +45,7 @@
package eu.europa.ec.edelivery.smp.validation;
import eu.europa.ec.cipa.smp.server.conversion.CaseSensitivityNormalizer;
import eu.europa.ec.edelivery.smp.error.exceptions.BadRequestException;
import org.junit.Before;
import org.junit.Test;
......@@ -53,6 +54,7 @@ import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup;
import org.springframework.beans.factory.annotation.Autowired;
import static eu.europa.ec.smp.api.Identifiers.asString;
import static java.util.Arrays.asList;
/**
* Created by gutowpa on 02/08/2017.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment