package jp.ne.yohira.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter;
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.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@EnableWebSecurity
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

	@Override
	public void configure(WebSecurity web) {
		web.ignoring().antMatchers("/webjars/**", "/css/**");
	}

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http.authorizeRequests().antMatchers("/login/").permitAll().anyRequest()
				.authenticated();

		http.formLogin().loginProcessingUrl("/dologin").loginPage("/login/").failureUrl("/failure/")
				.defaultSuccessUrl("/aloneTwitter/", true).usernameParameter("username").passwordParameter("password");

		http.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout**")).logoutSuccessUrl("/login/");

	}

	@Configuration
	static class AuthenticationConfigration extends GlobalAuthenticationConfigurerAdapter {

		@Autowired
		private UserDetailsService service;

		@Bean
		public PasswordEncoder passwordEncoder() {
			return new BCryptPasswordEncoder();
		}

		@Override
		public void init(AuthenticationManagerBuilder auth) throws Exception {
			auth.userDetailsService(service).passwordEncoder(passwordEncoder());
		}

	}
}
@@ -1363,16 +1363,178 @@
 ption %7B%0A
+%09%09permitPagesConfigure(http);%0A%09%09loginConfigure(http);%0A%09%09logoutHandleConfigure(http);%0A%09%7D%0A%0A%09private void permitPagesConfigure(HttpSecurity http) throws Exception %7B%0A
 %09%09http.a
@@ -1571,17 +1571,16 @@
 (%22/login
-/
 %22).permi
@@ -1621,16 +1621,86 @@
 ated();%0A
+%09%7D%0A%0A%09private void loginConfigure(HttpSecurity http) throws Exception %7B
 %0A%09%09http.
@@ -1759,17 +1759,16 @@
 (%22/login
-/
 %22).failu
@@ -1894,16 +1894,93 @@
 word%22);%0A
+%09%7D%0A%0A%09private void logoutHandleConfigure(HttpSecurity http) throws Exception %7B
 %0A%09%09http.
@@ -2077,14 +2077,12 @@
 ogin
-/
 %22);%0A
-%0A
 %09%7D%0A%0A

refactor SecurityConfig