/* 
 * Athena Peacock Dolly - DataGrid based Clustering 
 * 
 * Copyright (C) 2014 Open Source Consulting, Inc. All rights reserved by Open Source Consulting, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Revision History
 * Author			Date				Description
 * ---------------	----------------	------------
 * Bong-Jin Kwon	2015. 1. 6.			First Draft.
 */
package com.athena.dolly.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Main class with Spring Boot
 * 
 * - required java option : -Dspring.config.name=dolly
 * -Dspring.profiles.active=[local|dev|prd]
 * 
 * @author BongJin Kwon
 * 
 */
@EnableAutoConfiguration
@ComponentScan(basePackages = { "com.athena.dolly.controller" })
// @PropertySource(value={"classpath:dolly.properties","classpath:dolly-${spring.profiles.active:local}.properties"})
@PropertySource(value = { "classpath:db.properties" })
public class DollyBoot extends WebMvcConfigurerAdapter {

	public static void main(String[] args) {
		SpringApplication.run(DollyBoot.class, args);
	}

	/**
	 * <pre>
	 * Spring Security Java Config
	 * </pre>
	 * 
	 * @author Bong-Jin Kwon
	 * @version 2.0
	 */
	@Configuration
	@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
	@EnableGlobalMethodSecurity(securedEnabled = true)
	protected static class ApplicationSecurity extends
			WebSecurityConfigurerAdapter {

		@Autowired
		private SecurityProperties security;

		@Override
		public void configure(WebSecurity web) throws Exception {
			web.ignoring().antMatchers("/", "/index.html", "/app.js",
					"/resources/**",

					"/getServerList", "/user/notLogin*", "/user/loginFail*",
					"/user/accessDenied*", "/user/onAfterLogout*");
		}

		@Override
		protected void configure(HttpSecurity http) throws Exception {
			http.anonymous().disable().authorizeRequests().anyRequest()
					.fullyAuthenticated().and().exceptionHandling()
					.accessDeniedPage("/user/accessDenied").and().formLogin()
					.loginPage("/user/notLogin")
					.loginProcessingUrl("/user/login")
					.defaultSuccessUrl("/user/onAfterLogin", true)
					.failureUrl("/user/loginFail").and().logout()
					.logoutUrl("/user/logout")
					.logoutSuccessUrl("/user/onAfterLogout").and().csrf()
					.disable();			
		}

		@Override
		public void configure(AuthenticationManagerBuilder auth)
				throws Exception {
			auth.inMemoryAuthentication().withUser("dolly").password("dolly")
					.roles("ADMIN");

		}

	}

}

@@ -2613,16 +2613,18 @@
 es%22 %7D)%0D%0A
+%0D%0A
 public c
@@ -3006,19 +3006,20 @@
 abled = 
-tru
+fals
 e)%0D%0A%09pro
@@ -3524,16 +3524,18 @@
 tion %7B%0D%0A
+//
 %09%09%09http.
@@ -3586,24 +3586,26 @@
 yRequest()%0D%0A
+//
 %09%09%09%09%09.fullyA
@@ -3642,24 +3642,26 @@
 Handling()%0D%0A
+//
 %09%09%09%09%09.access
@@ -3708,24 +3708,26 @@
 ormLogin()%0D%0A
+//
 %09%09%09%09%09.loginP
@@ -3745,24 +3745,26 @@
 notLogin%22)%0D%0A
+//
 %09%09%09%09%09.loginP
@@ -3788,24 +3788,26 @@
 er/login%22)%0D%0A
+//
 %09%09%09%09%09.defaul
@@ -3847,16 +3847,18 @@
  true)%0D%0A
+//
 %09%09%09%09%09.fa
@@ -3897,24 +3897,26 @@
 ).logout()%0D%0A
+//
 %09%09%09%09%09.logout
@@ -3932,24 +3932,26 @@
 r/logout%22)%0D%0A
+//
 %09%09%09%09%09.logout
@@ -3998,16 +3998,18 @@
 csrf()%0D%0A
+//
 %09%09%09%09%09.di
@@ -4017,18 +4017,61 @@
 able();%09
-%09%09
+%0D%0A%09%09%09http.anonymous().and().csrf().disable();
 %0D%0A%09%09%7D%0D%0A%0D

Disable security in testing phase