권한 처리
This commit is contained in:
@@ -2,6 +2,7 @@ package com.spring.security1.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
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;
|
||||
@@ -9,6 +10,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity // 스프링 시큐리티 필터(SecurityConfig)가 스프링 필터 체인에 등록
|
||||
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) // secured 어노테이션 활성화 , preAuthorized 활성화
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.spring.security1.controller;
|
||||
import com.spring.security1.model.User;
|
||||
import com.spring.security1.repository.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -63,4 +65,15 @@ public class IndexController {
|
||||
return "redirect:/loginForm";
|
||||
}
|
||||
|
||||
@Secured("ROLE_ADMIN")
|
||||
@GetMapping("/info")
|
||||
public @ResponseBody String info () {
|
||||
return "개인정보";
|
||||
}
|
||||
|
||||
@PreAuthorize("hasRole('ROLE_MANAGER') or hasRole('ROLE_ADMIN')")
|
||||
@GetMapping("/data")
|
||||
public @ResponseBody String data () {
|
||||
return "데이터정보";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user