Web&Spring2020. 11. 29. 21:14

 

 

 

스프링 시큐리티에서는 롤을 관리하고, URL에 대한 접근제어를 한다.

설정을 context-security.xml에 기술하고, 전자정부에서는

접근제어 URL 및 ROLE 정보를 데이터베이스에서 관리한다.

자바에서 권한 체크를 할때는 SecurityContext 객체를 쓰기도 하고,

객체를 사용해서 권한정보를 가져올 수도 있다.

전자정부프레임워크에서는 egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper라는 유틸 클래스를 친절히 만들어놓았다.

그러나 jsp에서도 권한체크를 바로바로 할 수 있는 방법이 있는데~그거슨 spring security tag를 사용해서 필요한 권한정보를 체크하는것~!

우선 context-security.xml 파일에 use-expressions 구문을 true로 놓는다.

 

<http auto-config="true" use-expressions="true">

 

 

그리고 JSP 최상단에 tag를 import해야한다.

 

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

 

 

이렇게 태그 정의가 포함되면, 권한을 체크하는 태그를 이용할 수 있다.

 

<!-- 로그인 되지 않았다면 참 --> 
<sec:authorize access="isAnonymous()"></sec:authorize>

<!-- 로그인 했다면 참 -->
<sec:authorize access="isAuthenticated()"></sec:authorize>

<!-- 인자로 주어진 롤을 가지고 있으면 참 -->
<sec:authorize access="hasRole('ROLE_ADMIN')"></sec:authorize>

<!-- 인자로 주어진 롤을 가지고 있지 않다면 참 -->
<sec:authorize access="!hasRole('ROLE_ADMIN')"></sec:authorize>

<!-- 인자로 주어진 롤들중 하나라도 가지고 있다면 참 -->
<sec:authorize access="hasAnyRole('ROLE_ADMIN','ROLE_MANAGER')"></sec:authorize>

 

 

자바 클래스 내에서도 다양한 방법이 있지만..

JSP 프론트엔드 단에서도 이렇게 다이나믹하게 화면을 컨트롤 할 수 있다'-'

 

Posted by 사슴영혼'-'