JAVAIARY

Spring Security - 7. 표현식과 동적 화면 구성 본문

lectureNote/SPRING

Spring Security - 7. 표현식과 동적 화면 구성

shiherlis 2022. 12. 21. 14:35
표현식 설명
hasRole( [role] )
hasAuthority( [authority] )
해당 권한이 있으면 true
hasAnyRole( [role,role2])
hasAnyAuthority([authority])
여러 권한들 중에서 하나라도 해당하는 권한이 있으면 true
principal 현재 사용자 정보를 의미
permitAll 모든 사용자에게 허용
denyAll 모든 사용자에게 거부
isAnomymous( ) 익명의 사용자의 경우(로그인을 하지 않은 경우도 해당)
isAuthenticated( ) 인증된 사용자면 true
isFullyAuthenticated( ) Remember-me로 인증된 것이 아닌 인증된 사용자인 경우 true
  • 대부분 true/false 리턴
  • 조건문 형식과 비슷
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Insert title here</title>
  </head>
  <body>
	  <h1>/sample/all page</h1>
	   
	<sec:authorize access="isAnonymous()">
	 
	  <a href="/customLogin">로그인</a>
	 
	</sec:authorize>
	 
	<sec:authorize access="isAuthenticated()">
	 
	  <a href="/springsecurity/logoutForm">로그아웃</a>
	 
	</sec:authorize>
	  
  </body>
</html>

all.jsp

  • 로그인 여부에 따라 다르게 보이도록 함

로그인 전 / 후