Develop/Spring
Spring Security에서 지원하는 표현식(Spring EL)
jaeyoungb
2022. 11. 22. 16:50
hasRole(String role)
- 현재 보안 주체(principal)가 지정된 역할을 갖고 있는지의 여부를 확인하고, 가지고 있다면 true를 리턴
- hasRole(’admin’)처럼 파라미터로 넘긴 role이 ROLE_ 로 시작하지 않으면, 기본적으로 추가
- DefaultWebSecurityExpressionHandler의 defaultRolePrefix를 수정하면 커스텀 가능
hasAnyRole(String… roles)
- 현재 보안 주체가 지정한 역할 중 1개라도 가지고 있으면 true를 리턴
- 문자열 리스트를 콤마로 구분해서 전달
ex) hasAnyRole(’admin’, ‘user’)
hasAuthority(String authority)
- 현재 보안 주체가 지정한 권한을 갖고 있는지 여부를 확인하고 가지고 있다면 true를 리턴
ex) hasAuthority(’read’)
hasAnyAuthority(String… authorities)
- 현재 보안 주체가 지정한 권한 중 하나라도 있으면 true를 리턴
ex) hasAnyAuthority(’read’, ‘write’)
principal
- 현재 사용자를 나타내는 principal 객체에 직접 접근 가능
authentication
- SecurityContext로 조회할 수 있는 현재 Authentication 객체에 직접 접근 가능
permitAll
- 항상 true로 평가
denyAll
- 항상 false로 평가
isAnonymous()
- 현재 보안 주체가 익명 사용자면 true를 리턴
isRememberMe()
- 현재 보안 주체가 remember-me 사용자면 true를 리턴
isAuthenticated()
- 사용자가 익명이 아닌 경우 true를 리턴
isFullyAuthenticated()
- 사용자가 익명 사용자나 remember-me 사용자가 아니면 true를 리턴
hasPermission(Object target, Object permission)
- 사용자가 target에 해당 permission 권한이 있으면 true를 리턴
ex) hasPermission(domainObject, ‘read’)
hasPermission(Object targetId, String targetType, Object permission)
- 사용자가 target에 해당 permission 권한이 있으면 true를 리턴
ex) hasPermission(1, ‘com.example.domain.Message’, ‘read’)
Ref)
- https://docs.spring.io/spring-security/reference/servlet/authorization/expression-based.html