접근 권한을 관리하는 annotation
@PreAuthorize, @PostAutorize, @Secured가 있다.
권한 설정이 필요한 위치에 @PreAuthorize("hasRole('ROLE_ADMIN')")이런식으로 어노테이션을 추가해 주면 권한 별로 접근을 통제한다.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping("/preRole1")
public @ResponseBody String preRole1() throws Exception {
return "@PreAuthorize : get role ROLE_ADMIN";
}
동작을 하지 않는다면 Configure 클래스 파일 상단에 아래 코드를 추가한다.
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
https://copycoding.tistory.com/278
Spring Security @PreAuthorize @Secured 사용법
Spring Security에서의 권한 별 접근은 아래 source 처럼 대부분 configure(HttpSecurity http)에 설정을 하여 관리를 하게 됩니다. @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic().and().author
copycoding.tistory.com
'JAVA > Spring' 카테고리의 다른 글
| 게시판 프로젝트 KPT (0) | 2023.01.06 |
|---|---|
| 2023.01.02 Spring Security...ing (0) | 2023.01.02 |
| 2022.12.21 Lombok (0) | 2022.12.22 |
| 2022.12.08 JPA 2 (0) | 2022.12.08 |
| 2022.12.07 JPA 기초 ...ing (0) | 2022.12.07 |