사용법
- Configure class에 @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) 추가
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
public class ServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
private final LoginService loginService;
@Override
protected void configure(HttpSecurity http) throws Exception {
}
}
- 원하는 controller의 메소드에 애노테이션 설정
@PostAuthorize("isAuthenticated() and (( returnObject.name == principal.name ) or hasRole('ROLE_ADMIN'))")
@RequestMapping( value = "/{id}", method = RequestMethod.GET )
public Project getProject( @PathVariable("id") long id ){
return service.findOne(id);
}
-- 출처 https://joomn11.tistory.com/88