package springSecurity.demo.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.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration // IoC 빈(bean)을 등록
public class SecurityConfig {
// 해당 메서드의 리턴되는 오브젝트를 ioC로 등록해준다.
@Bean
public BCryptPasswordEncoder encodePwd(){
return new BCryptPasswordEncoder();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/user/**").authenticated()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
.antMatchers("/manager/**").access("hasRole('ROLE_ADMIN') and hasRole('ROLE_USER')")
.anyRequest().permitAll()
.and()
.formLogin()
.loginPage("/loginForm");
return http.build();
}
filterChain 함수는 user는 인증만 되면 들어갈 수 있다. admin과 manager은 역할이 admin과 user인 사람만이 들어갈 수 있도록 한것이다.
그리고 이것들이 아닌 모든요청은 허용된다는 것이고 기본 로그인페이지는 loginForm이다.
Timestamp를 사용하는 것이 좋은 것 같다.
https://sowon-dev.github.io/2021/05/02/210504Datetypediff/
[MySQL]날짜 데이터타입에서 Timestamp를 쓰는 경우
DB를 설계하면서 등록일자, 삭제날짜등의 날짜 데이터타입을 지정해야했다.날짜 데이터타입으로는 크게 Date, Datetime, Time, Timestamp 4가지가 있다.
sowon-dev.github.io
'백엔드 > 스프링시큐리티연습' 카테고리의 다른 글
스프링부트 시큐리티 8강 - Authentication객체가 가질수 있는 2가지 타입 (0) | 2023.05.11 |
---|---|
스프링부트 시큐리티 4강 - 시큐리티 로그인(다시 공부 해야함) (0) | 2023.04.26 |