package bg.car_wash.configurations.security;

import bg.car_wash.areas.user.services.UserService;
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.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;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

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

	@Autowired
	private UserService userService;

	@Override
	protected void configure(AuthenticationManagerBuilder auth) throws Exception {
		auth.userDetailsService(this.userService).passwordEncoder(getBCryptPasswordEncoder());
	}

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http
				.authorizeRequests()
				.antMatchers("/", "/register", "/bootstrap/**", "/jquery/**").permitAll()
//                .antMatchers("/user/**").access("hasRole('ADMIN') OR hasRole('USER')")
//                .antMatchers("/admin/**").hasRole("ADMIN")
//                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/user/login").permitAll()
//                .usernameParameter("username")
//                .passwordParameter("password")
//                .and()
//                .rememberMe()
//                .rememberMeCookieName("RememberMeFromLecture")
//                .rememberMeParameter("rememberMe")
//                .key("GolqmTaina")
//                .tokenValiditySeconds(1000)
//                .and()
//                .logout().logoutSuccessUrl("/login?logout").permitAll()
//                .and()
//                .exceptionHandling().accessDeniedPage("/unauthorized")
				.and()
				.csrf().disable();
	}

	@Bean
	public BCryptPasswordEncoder getBCryptPasswordEncoder() {
		return new BCryptPasswordEncoder();
	}
}

@@ -1347,16 +1347,21 @@
 (%22/%22, %22/
+user/
 register
@@ -1410,73 +1410,236 @@
 l()%0A
-//                .antMatchers(%22/user/**%22).access(%22hasRole('ADMIN
+%09%09%09%09.antMatchers(%22/user/status%22).access(%22hasRole('ADMIN') OR hasRole('DIRECTOR')%22)%0A                .antMatchers(%22/user/**%22).access(%22hasRole('WORKER') OR hasRole('PAYMASTER')%22)%0A%09%09%09%09.antMatchers(%22/car/add%22).access(%22hasRole('WORKER
 ') O
@@ -1653,10 +1653,15 @@
 le('
-US
+PAYMAST
 ER')
@@ -1724,18 +1724,16 @@
 ADMIN%22)%0A
-//
         
@@ -1766,24 +1766,24 @@
 enticated()%0A
+
             
@@ -1851,34 +1851,32 @@
 n%22).permitAll()%0A
-//
                 
@@ -1899,21 +1899,16 @@
 er(%22
-username
+email
 %22)%0A
-//
     
@@ -2208,18 +2208,16 @@
 s(1000)%0A
-//
         
@@ -2223,34 +2223,32 @@
          .and()%0A
-//
                 
@@ -2280,14 +2280,13 @@
 l(%22/
-login?
+user/
 logo
@@ -2302,18 +2302,16 @@
 itAll()%0A
-//
         
@@ -2317,34 +2317,32 @@
          .and()%0A
-//
                 

update spring config security