package org.fjorum;

import org.fjorum.model.entity.permission.BasicPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
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.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import static org.fjorum.model.entity.permission.BasicPermissions.BasicPermission.*;

@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserDetailsService userDetailsService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/admin").hasAuthority(ACCESS_ADMINISTRATION_PAGE.getName())
                .and()
                .formLogin()
                .loginPage("/login")
                .failureUrl("/login?error")
                .defaultSuccessUrl("/login?authenticated")
                .usernameParameter("emailOrName")
                .permitAll()
                .and()
                .logout()
                .logoutUrl("/logout")
                .logoutSuccessUrl("/loggedOut")
                .permitAll();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService)
                .passwordEncoder(new BCryptPasswordEncoder());
    }

}

@@ -18,68 +18,8 @@
 m;%0A%0A
-import org.fjorum.model.entity.permission.BasicPermissions;%0A
 impo
@@ -77,16 +77,16 @@
 owired;%0A
+
 import o
@@ -375,111 +375,8 @@
 er;%0A
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;%0A
 impo
@@ -787,9 +787,34 @@
 ion.
-*
+ACCESS_ADMINISTRATION_PAGE
 ;%0A%0A@
@@ -1118,16 +1118,16 @@
 uests()%0A
-
         
@@ -1154,16 +1154,19 @@
 (%22/admin
+/**
 %22).hasAu

fix antMatcher in SecurityConfig