2010년 5월 17일 월요일

Spring seucrity 2.0 태그 사용하기

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

<!-- 권한에 따라 페이지에서 보여주는 것을 달리하기 위해 authorize 태그를 사용할 수 있다. -->
<sec:authorize ifNotGranted="ROLE_USER">
<a href="<s:url value="/public/blog/login.jsp"/>">로그인</a>
</sec:authorize>
<sec:authorize ifAnyGranted="ROLE_USER, ROLE_ADMIN">
<b><sec:authentication property="principal.username"/></b>님 반갑습니다. <br>
<a href="<s:url value="/j_spring_security_logout"/>">로그아웃</a>
</sec:authorize>
 
수정 및 삭제 버튼도 위에서 사용한 authorize 태그를 사용해서 로그인 상태에 따라 보여주거나 보여주지 않을 수 있다.

authentication 태그를 사용하여 현재 로그인된 사용자의 정보를 확인할 수 있다.

* Spring Security Tag Library *
- authentication 태그
 property="principal.username" 설정으로 현재 로그인 된 사용자의 username을 확인 할 수 있다.
- authorize 태그
 현재 로그인 된 사용자가 해당되는 권한에 따라, 태그 안에 포함된 내용을 보여주거나 보여주지 않을 수 있다.
 
 ifAllGranted 속성: 사용자가 나열된 모든 권한에 해당할 경우 태그 안에 포함된 내용을 보여준다.
 ifAnyGranted 속성: 사용자가 나열된 권한 중 한가지에라도 해당할 경우 태그 안에 포함된 내용을 보여준다.
 ifNotGranted 속성: 사용자가 나열된 권한 중 한가지에라도 해당할 경우 태그 안에 포함된 내용을 보여주지 않는다.

댓글 없음:

댓글 쓰기