/*
 * Copyright 2010-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sambrannen.spring.events.web;

import static org.springframework.http.HttpMethod.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * Web security configuration for the Spring Events application.
 *
 * @author Sam Brannen
 * @since 1.0
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {

	@Autowired
	public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
		auth.inMemoryAuthentication()
			.withUser("admin").password("test").roles("ADMIN");
	}

	@Configuration
	@Order(1)
	public static class HttpBasicWebSecurityConfig extends WebSecurityConfigurerAdapter {

		@Override
		protected void configure(HttpSecurity http) throws Exception {
			http
				.antMatcher("/events/**")
				.authorizeRequests()
					.antMatchers(GET, "/**").permitAll()
					.antMatchers(PUT, "/**").hasRole("ADMIN")
					.antMatchers(POST, "/**").hasRole("ADMIN")
					.antMatchers(DELETE, "/**").hasRole("ADMIN")
					.and()
				.csrf().disable()
				.httpBasic();
		}
	}

	@Configuration
	@Order(2)
	public static class FormLoginWebSecurityConfig extends WebSecurityConfigurerAdapter {

		@Override
		protected void configure(HttpSecurity http) throws Exception {
			http
				.authorizeRequests()
					.antMatchers("/", "/favicon.ico", "/css/**", "/images/**").permitAll()
					.antMatchers("/form**").hasRole("ADMIN")
					.antMatchers("/h2-console/**").hasRole("ADMIN")
					.and()
				.csrf().disable()
				.formLogin();
		}
	}

}

@@ -1067,32 +1067,112 @@
 s.HttpSecurity;%0A
+import org.springframework.security.config.annotation.web.builders.WebSecurity;%0A
 import org.sprin
@@ -2035,111 +2035,8 @@
 ers(
-PUT, %22/**%22).hasRole(%22ADMIN%22)%0A%09%09%09%09%09.antMatchers(POST, %22/**%22).hasRole(%22ADMIN%22)%0A%09%09%09%09%09.antMatchers(DELETE, 
 %22/**
@@ -2241,32 +2241,29 @@
 Override%0A%09%09p
-rotected
+ublic
  void config
@@ -2258,36 +2258,35 @@
  void configure(
-Http
+Web
 Security http) t
@@ -2270,36 +2270,35 @@
 ure(WebSecurity 
-http
+web
 ) throws Excepti
@@ -2309,43 +2309,22 @@
 %0A%09%09%09
-http%0A%09%09%09%09.authorizeRequests()%0A%09%09%09%09%09
+web.ignoring()
 .ant
@@ -2381,65 +2381,123 @@
 **%22)
-.permitAll()%0A%09%09%09%09%09.antMatchers(%22/form**%22).hasRole(%22ADMIN%22
+;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09protected void configure(HttpSecurity http) throws Exception %7B%0A%09%09%09http%0A%09%09%09%09.authorizeRequests(
 )%0A%09%09
@@ -2512,16 +2512,27 @@
 atchers(
+%22/form**%22, 
 %22/h2-con

Simplify web security config