package com.chantha.jdbc.config; import org.springframework.beans.factory.annotation.Autowired; 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.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration @EnableWebSecurity public class WebConfig extends WebSecurityConfigurerAdapter { private final UserDetailsService userDetailsService; @Autowired public WebConfig(UserDetailsService userDetailsService){ this.userDetailsService=userDetailsService; } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService); } @Override protected void configure(HttpSecurity http) throws Exception { http.formLogin(); http.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")); http.authorizeRequests() .antMatchers("/**").hasAnyRole("ADMIN"); http.csrf().disable(); } }