Spring

Spring Security 태그

91cm 2018. 9. 4. 22:43

pom.xml

1
2
3
4
5
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-taglibs</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>
cs



security-context.xml

1
2
    <!-- 스프링시큐리티 표현식 사용 여부 -->
    <http auto-config="true" use-expressions="true" > 
cs
use-expressions를 true로 준다



jsp

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



사용예제
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %> 
<html>
<head>
    <title>스프링시큐리티 </title>
</head>
 
 
<body>
    <sec:authorize access="isAuthenticated()">
        <a href="logout">[로그아웃]</a>
    </sec:authorize>
    
    <sec:authorize access="hasRole('ROLE_ADMIN')">
        <a href="/admin/main">[관리자 매뉴로 ㅇㅣ동]</a>
    </sec:authorize>
    
    <p> [<sec:authentication property="principal.userName"/>]님 안녕하세요</p>
    <p>메인입니다.</p>
</body>
 
</html>
 
cs



표현식

 표현식

설명 

 hasRole('권한')

 해당 권한을 가지고 있으면 TRUE

 hasAnyRole('권한1','권한2')

 해당 권한들을 가지고 있으면 TRUE

 principal

 현재 사용자를 나타내는 주요 객체에 대한 정보

 authentication

 Authentication객체에 직접 접근 가능

 permitAll

 모두 허용

 denyAll

 모두 불가

 isAnonymous()

 익명사용자라면 TRUE

 isRememberMe()

 remember-me 사용자라면 TRUE

 isAuthenticated()

 사용자가 익명이 아니라면 TRUE

 isFullyAuthenticated()

 사용자가 익명이 아니고, remember-me 기능이 비활성화된 경우 TRUE