package com.ryanpmartz.booktrackr.config;

import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
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;
import org.springframework.security.crypto.password.PasswordEncoder;

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

    @Bean
    public PasswordEncoder bcryptEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                // allow anonymous access access to Swagger docs
                .antMatchers("/v2/api-docs", "/**/swagger-ui.html", "/webjars/**", "/swagger-resources/**").permitAll()
                // anonymous users need to be able to log in
                .antMatchers("/authenticate").permitAll()
                // all other request paths are protected
                .anyRequest().authenticated()
                .and()
                .logout()
                .permitAll();
    }
}

@@ -36,16 +36,79 @@
 onfig;%0A%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -174,16 +174,16 @@
 erties;%0A
-
 import o
@@ -333,24 +333,132 @@
 tion.Order;%0A
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;%0A
 import org.s
@@ -715,24 +715,97 @@
 rerAdapter;%0A
+import org.springframework.security.core.userdetails.UserDetailsService;%0A
 import org.s
@@ -1086,16 +1086,83 @@
 pter %7B%0A%0A
+    @Autowired%0A    private UserDetailsService userDetailsService;%0A%0A
     @Bea
@@ -1880,16 +1880,16 @@
 ogout()%0A
-
         
@@ -1915,11 +1915,198 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void configure(AuthenticationManagerBuilder auth) throws Exception %7B%0A        auth.userDetailsService(userDetailsService).passwordEncoder(bcryptEncoder());%0A    %7D
 %0A%7D%0A

add user details service to security config