// Path: src/main/java/app/config/BeansFactory.java
// @Configuration
// @EnableConfigurationProperties(MyPropertyConfigHolder.class)
// public class BeansFactory {
// 
//     @Bean
//     public BeanFromConfigurationClass<Task> beanFromConfigurationClass() {
//         var task = new Task();
//         task.setTaskName("fromBeanConfiguration");
//         return new BeanFromConfigurationClass<>(Task.class, task);
//     }
// 
//     @Bean
//     public ServiceWithConfigurationProperties serviceWithConfigurationProperties(MyPropertyConfigHolder myProperty) {
//         return new ServiceWithConfigurationProperties(myProperty);
//     }
// 
//     @Bean
//     public ServiceWithProperties serviceWithProperties(@Value("${admin.username}") String valueFromConfig) {
//         return new ServiceWithProperties(valueFromConfig);
//     }
// 
//     @Bean
//     public AsyncEvent asyncEvent() {
//         return new AsyncEvent();
//     }
// 
//     @Bean
//     public AsyncLogger asyncLogger(ApplicationEventPublisher eventPublisher) {
//         return new AsyncLogger(eventPublisher);
//     }
// 
//     @Bean
//     public MyEventListener myEventListener() {
//         return new MyEventListener();
//     }
// 
//     @Bean
//     public ABeanIWantToMockInterface aBeanIWantToMock() {
//         return new ABeanIWantToMock();
//     }
// 
//     @Bean
//     public UselessBean uselessBean(ABeanIWantToMockInterface aBeanIWantToMock) {
//         return new UselessBean(aBeanIWantToMock);
//     }
// }
// 
// Path: src/main/java/app/config/WebSecurityConfig.java
// @Configuration
// @EnableWebSecurity
// @EnableConfigurationProperties(CredentialsProperties.class)
// public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// 
//     private static final String BASIC_AUTH_ENDPOINT = "/basicauth";
//     private static final String ADMIN_ROLE = "ADMIN";
//     private static final String ACTUATOR_ROLE = "ACTUATOR";
// 
//     private final CredentialsProperties credentialsProperties;
// 
//     public WebSecurityConfig(CredentialsProperties credentialsProperties) {
//         this.credentialsProperties = credentialsProperties;
//     }
// 
//     @Override
//     protected void configure(HttpSecurity http) throws Exception {
//         //We disable csrf protection for actuator endpoints so we can post with curl
//         //ex : the refresh endpoint
//         http.csrf().ignoringRequestMatchers(EndpointRequest.toAnyEndpoint());
// 
//         http.logout()
//                 .logoutSuccessUrl("/")
//                 .invalidateHttpSession(true)
//                 .clearAuthentication(true)
//                 .logoutSuccessHandler(logoutHandler())
//                 .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
// 
//         http.authorizeRequests()
//                 .antMatchers(BASIC_AUTH_ENDPOINT)
//                 .hasRole(ADMIN_ROLE)
//                 .requestMatchers(EndpointRequest.toAnyEndpoint())
//                 .hasRole(ACTUATOR_ROLE)
//                 .and()
//                 .httpBasic();
//     }
// 
//     @Bean
//     public InMemoryUserDetailsManager inMemoryUserDetailsManager() {
//         return new InMemoryUserDetailsManager(
//                 User.withDefaultPasswordEncoder()
//                         .username(credentialsProperties.getUsername())
//                         .password(credentialsProperties.getPassword())
//                         .roles(ADMIN_ROLE, ACTUATOR_ROLE)
//                         .build()
//         );
//     }
// 
//     private LogoutSuccessHandler logoutHandler() {
//         var logoutSuccessHandler = new SimpleUrlLogoutSuccessHandler();
//         var redirectStrategy = new DefaultRedirectStrategy();
// 
//         redirectStrategy.setContextRelative(false);
//         logoutSuccessHandler.setRedirectStrategy(redirectStrategy);
// 
//         return logoutSuccessHandler;
//     }
// }


import app.config.BeansFactory;
import app.config.WebSecurityConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import java.util.Arrays;
/*
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.mpalourdio.springboottemplate;



@SpringBootApplication
@PropertySource(value = {
        "file:properties/global.properties",
        "file:properties/local.properties"
}, ignoreResourceNotFound = true)
@Import({
        WebSecurityConfig.class,
// Path: src/main/java/app/config/BeansFactory.java
// @Configuration
// @EnableConfigurationProperties(MyPropertyConfigHolder.class)
// public class BeansFactory {
// 
//     @Bean
//     public BeanFromConfigurationClass<Task> beanFromConfigurationClass() {
//         var task = new Task();
//         task.setTaskName("fromBeanConfiguration");
//         return new BeanFromConfigurationClass<>(Task.class, task);
//     }
// 
//     @Bean
//     public ServiceWithConfigurationProperties serviceWithConfigurationProperties(MyPropertyConfigHolder myProperty) {
//         return new ServiceWithConfigurationProperties(myProperty);
//     }
// 
//     @Bean
//     public ServiceWithProperties serviceWithProperties(@Value("${admin.username}") String valueFromConfig) {
//         return new ServiceWithProperties(valueFromConfig);
//     }
// 
//     @Bean
//     public AsyncEvent asyncEvent() {
//         return new AsyncEvent();
//     }
// 
//     @Bean
//     public AsyncLogger asyncLogger(ApplicationEventPublisher eventPublisher) {
//         return new AsyncLogger(eventPublisher);
//     }
// 
//     @Bean
//     public MyEventListener myEventListener() {
//         return new MyEventListener();
//     }
// 
//     @Bean
//     public ABeanIWantToMockInterface aBeanIWantToMock() {
//         return new ABeanIWantToMock();
//     }
// 
//     @Bean
//     public UselessBean uselessBean(ABeanIWantToMockInterface aBeanIWantToMock) {
//         return new UselessBean(aBeanIWantToMock);
//     }
// }
// 
// Path: src/main/java/app/config/WebSecurityConfig.java
// @Configuration
// @EnableWebSecurity
// @EnableConfigurationProperties(CredentialsProperties.class)
// public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// 
//     private static final String BASIC_AUTH_ENDPOINT = "/basicauth";
//     private static final String ADMIN_ROLE = "ADMIN";
//     private static final String ACTUATOR_ROLE = "ACTUATOR";
// 
//     private final CredentialsProperties credentialsProperties;
// 
//     public WebSecurityConfig(CredentialsProperties credentialsProperties) {
//         this.credentialsProperties = credentialsProperties;
//     }
// 
//     @Override
//     protected void configure(HttpSecurity http) throws Exception {
//         //We disable csrf protection for actuator endpoints so we can post with curl
//         //ex : the refresh endpoint
//         http.csrf().ignoringRequestMatchers(EndpointRequest.toAnyEndpoint());
// 
//         http.logout()
//                 .logoutSuccessUrl("/")
//                 .invalidateHttpSession(true)
//                 .clearAuthentication(true)
//                 .logoutSuccessHandler(logoutHandler())
//                 .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
// 
//         http.authorizeRequests()
//                 .antMatchers(BASIC_AUTH_ENDPOINT)
//                 .hasRole(ADMIN_ROLE)
//                 .requestMatchers(EndpointRequest.toAnyEndpoint())
//                 .hasRole(ACTUATOR_ROLE)
//                 .and()
//                 .httpBasic();
//     }
// 
//     @Bean
//     public InMemoryUserDetailsManager inMemoryUserDetailsManager() {
//         return new InMemoryUserDetailsManager(
//                 User.withDefaultPasswordEncoder()
//                         .username(credentialsProperties.getUsername())
//                         .password(credentialsProperties.getPassword())
//                         .roles(ADMIN_ROLE, ACTUATOR_ROLE)
//                         .build()
//         );
//     }
// 
//     private LogoutSuccessHandler logoutHandler() {
//         var logoutSuccessHandler = new SimpleUrlLogoutSuccessHandler();
//         var redirectStrategy = new DefaultRedirectStrategy();
// 
//         redirectStrategy.setContextRelative(false);
//         logoutSuccessHandler.setRedirectStrategy(redirectStrategy);
// 
//         return logoutSuccessHandler;
//     }
// }


// Path: src/main/java/com/mpalourdio/springboottemplate/SpringBootTemplateApplication.java
import app.config.BeansFactory;
import app.config.WebSecurityConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import java.util.Arrays;

/*
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.mpalourdio.springboottemplate;



@SpringBootApplication
@PropertySource(value = {
        "file:properties/global.properties",
        "file:properties/local.properties"
}, ignoreResourceNotFound = true)
@Import({
        WebSecurityConfig.class,
        BeansFactory.class,