뷰 계층 보안
게시글 보기 화면에서 글 소유자가 아닌 사용자가 아래 그림에서 박스로 강조된 메뉴를 봐서는 안 된다.
/WEB-INF/views/bbs/view.jsp
<!-- 중간 생략 -->
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="security" %>
<!-- 중간 생략 -->
<div class="view-menu" .. >
<security:authorize access="#email == principal.username or hasRole('ROLE_ADMIN')">
<div class="fl">
<input type="button" value="수정" onclick="goModify();" />
<input type="button" value="삭제" onclick="goDelete()" />
</div>
</security:authorize>
<!-- 중간 생략 -->
<div id="detail">
<div id="date-writer-hit">edited ${regdate } by ${name } hit ${hit }</div>
<div id="article-content">${content }</div>
<div id="file-list" style="text-align: right;">
<div id="file-list" style="text-align: right;">
<c:forEach var="file" items="${attachFileList }" varStatus="status">
<div class="attach-file">
<a href="javascript:download('${file.filename }')">${file.filename }</a>
<security:authorize access="#email == principal.username or hasRole('ROLE_ADMIN')">
<a href="javascript:deleteAttachFile('${file.attachFileNo }')">삭제</a>
</security:authorize>
</div>
</c:forEach>
</div>
</div>
<!-- 댓글 반복 시작 -->
<c:forEach var="comment" items="${commentList }" varStatus="status">
<div class="comments">
<span class="writer">${comment.name }</span>
<span class="date">${comment.regdate }</span>
<security:authorize access="#comment.email == principal.username or hasRole('ROLE_ADMIN')">
<span class="modify-del">
<a href="javascript:updateComment('${comment.commentNo }')">수정</a> |
<a href="javascript:deleteComment('${comment.commentNo }')">삭제</a>
</span>
</security:authorize>
<!-- 중간 생략 -->
이미 수정한 header.jsp 파일 역시 스프링 시큐리티 태그를 사용하여 뷰가 선별적으로 랜더링된다.
/WEB-INF/views/inc/header.jsp
<!-- 중간 생략 -->
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="security" %>
<!-- 중간 생략 -->
<security:authorize access="hasAnyRole('ROLE_USER','ROLE_ADMIN')">
<security:authentication property="principal.username" var="check" />
</security:authorize>
<!-- 중간 생략 -->
참고
