webpage08_03.jsp

    <%@ page contentType="text/html; charset=utf-8" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
    <html>
    <head>
    <title>Security</title>
    </head>
    <body>
    <h2>스프링 시큐리티 태그 예</h2>
    <sec:authorize access="hasRole('ROLE_ADMIN')" var="isAdmin">
        <p><h3>관리자 권한 화면입니다.</h3>
    </sec:authorize>
    <c:choose>
        <c:when test="${isAdmin}">
            <p>로그인 중입니다.
            <p>비밀번호: <sec:authentication property="principal.password"/>
            <sec:authentication property="authorities" var="roles" scope="page"/>
            <p>권한 :
                <ul>
                    <c:forEach var="role" items="${roles}">
                        <li>${role}</li>
                    </c:forEach>
                </ul>
            <p>이름 : <sec:authentication property="principal.username"/>
            <p><a href="<c:url value='/exam03' />">[웹 요청 URL /exam03로 이동하기]</a>
        </c:when>
        <c:otherwise>
            <p>로그인이 아닙니다.
            <p><a href="<c:url value='/admin/tag' />">[웹 요청 URL /admin/tag로 이동하기]</a>
        </c:otherwise>
    </c:choose>
    </body>
    </html>

    다음은 앞의 코드를 실행한 결과입니다.

    ▲ 그림 8-3 실행 결과

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.