차근차근/Spring Security

SpringSecurity 설정파일 - security-context.xml - 작성중

예쁜꽃이피었으면 2022. 2. 3. 17:49
스프링시큐리티 xsd ( XML 스키마 정의 : XML Schema Definition)
<beans:beans 
	xmlns="http://www.springframework.org/schema/security" 
	xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    					http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
                        http://www.springframework.org/schema/security 
                        http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 
<!-- 내용 작성 -->
</beans:beans>

 

security 인증 예외 설정
<http pattern="/admin/denied.do" security="none" /> 
<http pattern="/admin/login.do" security="none" /> 
<http pattern="/resources/**" security="none" /> 
<http auto-config="true" access-denied-page="/common/auth/denied" use-expressions="true"> 
	<intercept-url pattern="/*/**" access="isAuthenticated()" /> 

	<!-- 로그인 설정 --> 
	<form-login 
    	login-page="/admin/login.do" 
    	authentication-failure-url="/admin/login.do?login_error=auth" 
        authentication-success-handler-ref="authenticationSuccessHandler" /> 

	<!-- 로그아웃 설정 --> 
	<logout logout-success-url="/admin/login.do" /> 
	
    <!-- anonymous / --> 
	<http-basic /> 
	<remember-me use-secure-cookie="true" /> 
</http>

↑ xml 뜯어보기

security="none" security="none" 설정 앞의 패턴은 인증에서 제외 
* 하위 모든 경로에 대해 인증을 예외 
access-denied-page 인증이 끊어진 세션을 어느 페이지로 이동할지 결정
intercept-url 어떤 인증절차의 유저를 접근하게 할 것인지 결정
auto-config="true" https://hamait.tistory.com/325
true이면 기본 로그인페이지 / HTTP기본인증 / 로그아웃 기능 등을 제공한다.
use-expressions="true" https://hamait.tistory.com/325
true이면 SpEL을 사용한다는 의미이다.
* SpEL문법 : https://admm.tistory.com/107

form-login

login-page 로그인 페이지 주소를 지정
authentication-failure-url 인증 실패시 이동할 페이지
authenicationSuccessHandler 인증 후 어떤 로직으로 처리할 결정
logout-success-url 로그아웃 후 어떤 페이지로 이동할지 결정
login-processiong-url 로그인 페이지 form action에 입력한 주소 지정
username-parameter 로그인 페이지 form에 있는 username을 저장한 변수 이름 지정
password-parameter 로그인 페이지 form에 있는 password을 저장한 변수 이름 지정
default-target-url 로그인 성공인 경우 호출할 주소 지정

※ SpEL문법 

hasRole("admin") admin권한을 가지고 있어야 접근가능
hasAnyRole("admin","user") admin,user권한 중 한가지만 가지고 있으면 접근가능
permitAll 모두 접근 가능
denyAll 모두 접근 불가능
isAnonymous() 인증을 하지 않은 사용자일 경우(로그인하지 않은 사용자)
isRememberMe() Remember-me기능으로 로그인한 사용자일 경우 (자동로그인 사용자)
isAuthenticated() 인증을 한 사용자일 경우(로그인한 사용자)
isFullyAuthenticated() 인증을 한 사용자이면서 Remember-me기능으로 로그인하지 않은 사용자. 

※ url별 접근권한 설정 시 주의사항 

"순서"가 중요하다.

위에서 부터 설정이 되기 때문에  permitAll(전체접근 가능) 설정을 가장 위로 올릴 경우

밑에서 admin접근설정을 해도 적용되지 않는다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


[참조]

https://eongeuni.tistory.com/80

 

https://yakolla.tistory.com/48

https://yakolla.tistory.com/49

 

 

 

반응형

'차근차근 > Spring Security' 카테고리의 다른 글

알쏭달쏭 스프링 시큐리티 - 작성중  (0) 2022.02.04