관리 메뉴

제뉴어리의 모든것

html 태그에 sec 속성 넣어서 인증 (Authenticate) 여부에 따라 출력하기 본문

Spring Boot/Spring Security

html 태그에 sec 속성 넣어서 인증 (Authenticate) 여부에 따라 출력하기

제뉴어리맨 2021. 2. 27. 01:21

==> sec 속성 사용방법

maven 경우

 

1. pom.xml에 의존성 추가

 

<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>

 

2. xmlns 추가

 

sec 속성을 사용할 html문서 상단 html태그에 

xmlns:sec="http://www.thymeleaf.org/extras/spring-security" 추가

 

3. sec 속성 사용

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

 안녕하세요

</div>

 

위에 div 단락은 인증(로그인)이 된 경우에만 적용되므로 

로그인 된 경우에는 "안녕하세요" 가 출력되고

로그인 되지 않은 경우에는 아무것도 출력되지 않는다