package com.bayer.burp;

import org.springframework.context.annotation.Configuration;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

	@Override
	protected void configure(AuthenticationManagerBuilder auth) throws Exception {
		auth.inMemoryAuthentication()
			.withUser("Adam").password("test").roles("USER", "ADMIN").and()
			.withUser("Betty").password("test").roles("USER");
	}

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		// Basis-Schutz: Nur autorisierte Zugriffe (feingranulare Steuerung über Assertions)
		http.authorizeRequests()
			//.antMatchers(HttpMethod.GET, "/public/**").permitAll()
			.anyRequest().authenticated();
		
		http.httpBasic();
		//http.formLogin();
		
		http.csrf().disable();
	}
}
