package org.dionysus;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
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.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

	@Autowired
	@Qualifier("dionysus")
	private UserDetailsService securityUserService;

	@Override
	protected void configure(HttpSecurity http) throws Exception {
//	    http.csrf().disable()
//	    	.antMatcher("/api/v1/*")
//	    		.authorizeRequests()
//	    		.antMatchers("/*").hasAnyRole("USER", "ADMIN")
//	    		.anyRequest()
//	    		.authenticated();
	    http.csrf().disable()
	    	.antMatcher("/api/v1")
	    	.authorizeRequests()
	    	.antMatchers("/*")
	    	.anonymous();
//	    .and()
//	    	.formLogin()
//	    	.permitAll()
//	    .and()
//	    	.logout()
//            .permitAll();
	}

	@Override
	public void configure(WebSecurity web) throws Exception {
		web.ignoring().antMatchers("/");
	}

	@Override
	public void configure(AuthenticationManagerBuilder auth) throws Exception {
		auth.inMemoryAuthentication()
		    .withUser("admin")
		    .password("admin")
		    .roles("ADMIN", "USER")
		.and()
			.withUser("user")
			.password("password")
			.roles("USER");
//		auth.userDetailsService(securityUserService);
	}
}
@@ -307,24 +307,127 @@
 gerBuilder;%0A
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;%0A
 import org.s
@@ -647,16 +647,22 @@
 uration.
+Enable
 WebSecur
@@ -664,33 +664,16 @@
 Security
-ConfigurerAdapter
 ;%0Aimport
@@ -728,16 +728,8 @@
 web.
-servlet.
 conf
@@ -738,36 +738,44 @@
 uration.
-EnableWebMvcSecurity
+WebSecurityConfigurerAdapter
 ;%0Aimport
@@ -871,11 +871,8 @@
 eWeb
-Mvc
 Secu
@@ -876,16 +876,67 @@
 ecurity%0A
+@EnableGlobalMethodSecurity(securedEnabled = true)%0A
 public c
@@ -1083,16 +1083,17 @@
 ervice;%0A
+%09
 %0A%09@Overr
@@ -1126,277 +1126,309 @@
 ure(
-HttpSecurity http) throws Exception %7B%0A//%09    http.csrf().disable()%0A//
+AuthenticationManagerBuilder auth) throws Exception %7B%0A%09%09auth.inMemoryAuthentication()%0A%09
 %09    
-%09.antMatcher(%22/api/v1/*%22)%0A//%09    %09%09.authorizeRequests()%0A//%09    %09%09.antMatch
+.withUser(%22admin%22).password(%22admin%22).roles(%22ADMIN%22, %22USER%22).and()%0A%09%09%09.withUs
 er
-s
 (%22
-/*%22).hasAnyR
+user%22).password(%22password%22).r
 ole
+s
 (%22USER%22
-, %22ADMIN%22)%0A//%09    %09%09.anyRequest()%0A//%09    %09%09.authenticated();%0A%09    http.csrf().disable()%0A%09    %09
+);%0A%09%7D%0A%09%0A%09@Override%0A%09protected void configure(HttpSecurity http) throws Exception %7B%0A%09%09http
 .ant
@@ -1443,24 +1443,24 @@
 %22/api/v1
+/**
 %22)%0A%09
-    
+%09
 %09.author
@@ -1478,171 +1478,73 @@
 ()%0A%09
-    %09.antMatchers(%22/*%22)%0A%09    %09.anonymous();%0A//%09    .and()%0A//%09    %09.formLogin()%0A//%09    %09.permitAll()%0A//%09    .and()%0A//%09    %09.logout()%0A//            .permitAll
+%09%09%09.anyRequest().hasRole(%22USER%22)%0A%09%09%09%09.and()%0A%09%09%09.httpBasic
 ();%0A%09%7D%0A
+%09
 %0A%09@O
@@ -1626,16 +1626,20 @@
 noring()
+%0A%09%09%09
 .antMatc
@@ -1651,335 +1651,126 @@
 %22/%22)
-;
 %0A%09
-%7D%0A%0A%09@Override%0A%09public void configure(AuthenticationManagerBuilder auth) throws Exception %7B%0A%09%09auth.inMemoryAuthentication()%0A%09%09    .withUs
+%09%09.antMatchers(%22/font/**%22)%0A%09%09%09.antMatch
 er
+s
 (%22
-admin%22)%0A%09%09    .password(%22admin%22)%0A%09%09    .roles(%22ADMIN%22, %22USER
+/styles/**
 %22)%0A%09%09
+%09
 .an
-d()%0A%09%09%09.withUser(%22user%22)%0A%09%09%09.password(%22password%22)%0A%09%09%09.roles(%22USER%22);%0A//%09%09auth.userDetailsService(securityUserService
+tMatchers(%22/images/**%22)%0A%09%09%09.antMatchers(%22/scripts/**%22
 );%0A%09

enable spring security