로그인 ROLE에 따라 특정 메뉴 보이기/숨기기

 

 

1. pom.xml 확인

<dependency>

<groupId>egovframework.rte</groupId>

<artifactId>egovframework.rte.fdl.security</artifactId>

<version>${egovframework.rte.version}</version>

 

</dependency>

 

2. jsp 파일


<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %>



<!-- 관리자 로그인 중-->

<sec:authorize access="hasRole('ROLE_ADMIN')">

<button>관리자접속중</button>

</sec:authorize>  


<!-- 로그인 전 -->

<sec:authorize access="isAnonymous()">

<button>로그인하세요.</button>

</sec:authorize>


<!-- 사용자 로그인 중 -->

<sec:authorize access="isAuthenticated()">

<button>로그인하세요.</button>

</sec:authorize>




* 추가 표현들


hasRole([role])특정한 롤을 가지고 있는 경우 true
hasAnyRole([role1,role2])복수의 롤을 가지고 있는 경우 true
principalAllows direct access to the principal object representing the current user
authenticationAllows direct access to the current Authentication object obtained from the SecurityContext
permitAllAlways evaluates to true
denyAllAlways evaluates to false
isAnonymous()Returns true if the current principal is an anonymous user
isRememberMe()Returns true if the current principal is a remember-me user
isAuthenticated()Returns true if the user is not anonymous
isFullyAuthenticated()Returns true if the user is not an anonymous or a remember-me user



블로그 이미지

엘로드넷

,