34 lines
1.3 KiB
Java
34 lines
1.3 KiB
Java
package com.spring.security1.config;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
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 // 스프링 시큐리티 필터(SecurityConfig)가 스프링 필터 체인에 등록
|
|
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
@Bean
|
|
public BCryptPasswordEncoder encodePwd() {
|
|
return new BCryptPasswordEncoder();
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void configure(HttpSecurity http) throws Exception {
|
|
http.csrf().disable();
|
|
http.authorizeRequests()
|
|
.antMatchers("/user/**").authenticated()
|
|
.antMatchers("/manager/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_MANAGER')")
|
|
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
|
|
.anyRequest().permitAll()
|
|
.and()
|
|
.formLogin()
|
|
.loginPage("/loginForm");
|
|
}
|
|
|
|
}
|