programming/spring_security

[Spring Security] JSP에서 userRealName 가져오기

labj 2017. 6. 9. 11:17

간단하게 로그인 소스를 보여드리면 다음과 같습니다.

로그인 처리가 끝난 후에 다음과 같이 jsp 페이지를 만들어서 테스트해보시면 될 것 같습니다.


1. JSP 페이지 상단에 추가
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>


2. JSP상에서

<sec:authorize access="isAnonymous() or hasRole('ROLE_ADMIN')">
로그인전:
</sec:authorize>
<sec:authorize access="hasRole('ROLE_USER')">
로그인 후 : <sec:authentication property="principal.userRealName" />
</sec:authorize>