hasRole([role])
→ 해당 롤이 있으면 true
hasAnyRole([role1, rol2])
→ 여러 롤들 중에서 하나라도 해당되는 롤이 있으면 true
principal
→인증된 사용자의 사용자 정보( UserDetails 인터페이스를 구현한 클래스의 객체 )를 의미
authentication
→ 인증된 사용자의 인증 정보(Authentication 인터페이스를 구현한 클래스의 객체)를 의미
permitAll
→ 모든 사용자에게 허용
denyAll
→ 모든 사용자에게 거부
isAnonymous()
→ 익명의 사용자의 경우 (로그인을 하지 않은 경우에도 해당)
isAuthenticated()
→ 인증된 사용자면 true
isFullyAuthenticated()
→ Remember-me로 인증된 것이 아닌 일반적인 방법으로 인증된 사용자인 경우 true
→ home.jsp를 수정한다.
→ 표현식을 이용한 내용을 추가합니다.
로그인 한 사용자 정보 보여주기
→ views/board/register.jsp 수정
→ views/notice/register.jsp 수정
board/register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="<http://www.springframework.org/security/tags>" prefix="sec" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Board Register</title>
</head>
<body>
<h2>BOARD REGISTER : access to member</h2>
<p>principal : <sec:authentication property="principal"/></p>
<p>member : <sec:authentication property="principal.member"/></p>
<p>사용자 이름 : <sec:authentication property="principal.member.userName"/></p>
<p>사용자 아이디 : <sec:authentication property="principal.member.userId"/></p>
<p>사용자 비밀번호 : <sec:authentication property="principal.member.userPw"/></p>
<p>사용자 권한 리스트 : <sec:authentication property="principal.member.authList"/></p>
<hr>
<sec:authorize access="hasRole('ROLE_MEMBER')">
역할명 : 일반회원 권한입니다.
</sec:authorize>
<sec:authorize access="hasRole('ROLE_ADMIN')">
역할명 : 관리자 권한입니다.
</sec:authorize>
</body>
</html>
notice/list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Notice List</title>
</head>
<body>
<h2>NOTICE LIST : access to all</h2>
<a href="/notice/register">등록</a>
</body>
</html>
notice/register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="<http://www.springframework.org/security/tags>" prefix="sec" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Notice Register</title>
</head>
<body>
<h2>NOTICE REGISTER : access to admin</h2>
<p>principal : <sec:authentication property="principal"/></p>
<p>member : <sec:authentication property="principal.member"/></p>
<p>사용자 이름 : <sec:authentication property="principal.member.userName"/></p>
<p>사용자 아이디 : <sec:authentication property="principal.member.userId"/></p>
<p>사용자 비밀번호 : <sec:authentication property="principal.member.userPw"/></p>
<p>사용자 권한 리스트 : <sec:authentication property="principal.member.authList"/></p>
<hr>
<sec:authorize access="hasRole('ROLE_MEMBER')">
역할명 : 일반회원 권한입니다.
</sec:authorize>
<sec:authorize access="hasRole('ROLE_ADMIN')">
역할명 : 관리자 권한입니다.
</sec:authorize>
</body>
</html>
아직 로그인을 하지 않은 home 화면이다. (board클릭)

등록 하러 가기 누르고

MEMBER 권한을 갖고 있는 아이디로 로그인하면

로그인이 잘 된것을 확인할 수 있다.

다시 home화면을 가면 이미 로그인(권한등록)을 하였기 때문에 로그아웃버튼으로 바뀌어 있고, notice를 다시 들어가자

등록 버튼을 눌러보면 이전에 MEMBER권한으로 로그인을 하여서 해당 ADMIN관한을 가져야만 들어갈 수 있는 notice/register.jsp 페이지로 가는걸 거부당한 것을 확인할 수 있다.

