아무거나

[spring] 보안 Security - 2 본문

Java/Spring Security

[spring] 보안 Security - 2

전봉근 2019. 12. 26. 01:08
반응형

[spring] 보안 Security - 2

 

1. 보안 관련 taglibs 추가

   [dependencies 추가 pom.xml] 

   이클립스 기준 pom.xml -> 하단 Dependencies탭 클릭 -> Add.. 클릭 -> Enter groupId, artifactId or sha1 prefix ... 에 security 검색

   -> org.springframework.security(spring-security-taglibs) 선택

 

   [선언부]

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

<%-- USER ID : ${pageContext.request.userPrincipal.name}<br/> --%> <!-- 기존 코드 -->

USER ID : <s:authentication property="name"/><br/>  <!-- taglibs 사용 코드 -->

<a href="${pageContext.request.contextPath}/j_spring_security_logout">Log Out</a> <br />

 

 

2. 보안 관련 taglibs 사용 방법

   [before]

<c:if test="${not empty pageContext.request.userPrincipal }">

<p> is Log-In</p>

</c:if>

 

<c:if test="${empty pageContext.request.userPrincipal }">

<p> is Log-Out</p>

</c:if>

   

   [after]

<s:authorize ifAnyGranted="ROLE_USER">

<p> is Log-In</p>

</s:authorize>

 

<s:authorize ifNotGranted="ROLE_USER">

<p> is Log-Out</p>

</s:authorize> 

 

 

참고: https://www.inflearn.com/course/%EC%9E%90%EB%B0%94-%EC%8A%A4%ED%94%84%EB%A7%81-%EA%B0%95%EC%A2%8C/dashboard

반응형
Comments