SpringSecurity 3 설정 및 원리 안내
1. URL 필터 또는 방법 차단기: URL 이나 방법 자원 을 차단 하여 검증 하 는데 사용 되 며 추상 적 인 기본 클래스 는 AbstractSecurity Interceptor 입 니 다.
2. 자원 권한 취득 기: 특정한 URL 이나 방법 에 접근 하 는 데 필요 한 권한 을 얻 는 데 사 용 됩 니 다. 인 터 페 이 스 는 Security MetadataSource 입 니 다.
3. 접근 결정 기: 사용자 가 접근 권한 을 가지 고 있 는 지 여 부 를 결정 하 는 관건 적 인 유형 으로 인 터 페 이 스 는 AccessDecisionManager 입 니 다.
호출 순 서 는 AbstractSecurity Interceptor 에서 Security MetadataSource 를 호출 하여 자원 에 접근 할 수 있 는 모든 권한 을 얻 은 다음 에 AccessDecisionManager 를 호출 하여 결정 을 실현 하고 사용자 가 이 자원 에 접근 할 수 있 는 권한 이 있 는 지 확인 합 니 다.
Security MetadataSource 는 MethodSecurity MetadataSource 와 FilterInvocation Security MetadataSource 를 포함 하여 각각 대응 방법 과 URL 자원 을 포함한다.
필터, 자원 권한 취득 기, 접근 결정 기 를 완전히 사용자 정의 할 수 있 습 니 다. 다음은 완전한 springsecurity 3 설정 파일 을 보 여 줍 니 다.
<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<beans:bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener" />
<http auto-config="true" access-denied-page="/403.jsp">
<intercept-url pattern="/css/**" filters="none" />
<intercept-url pattern="/images/**" filters="none" />
<intercept-url pattern="/js/**" filters="none" />
<intercept-url pattern="/403.jsp" filters="none" />
<intercept-url pattern="/" filters="none" />
<intercept-url pattern="/login.jsp" filters="none" />
<form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?error=true" default-target-url="/finance/index.do?listId=CONSUMPTION&page.rowCount=10" />
<logout logout-success-url="/login.jsp"/>
<!-- , -->
<session-management>
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
</session-management>
<!-- filter, Acegi , filter , filter FILTER_SECURITY_INTERCEPTOR -->
<custom-filter before="FILTER_SECURITY_INTERCEPTOR" ref="urlSecurityFilter" />
</http>
<!-- filter, authenticationManager,accessDecisionManager,securityMetadataSource ,
, -->
<beans:bean id="urlSecurityFilter" class="com.maxjay.main.system.web.filter.UrlSecurityInterceptorFilter">
<beans:property name="authenticationManager" ref="authenticationManager" />
<beans:property name="accessDecisionManager" ref="securityAccessDecisionManager" />
<beans:property name="securityMetadataSource" ref="urlSecurityMetadataSource" />
</beans:bean>
<!-- , , UserDetailsService -->
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="userService">
<!-- , “ ”
<password-encoder hash="md5" />
-->
</authentication-provider>
</authentication-manager>
</beans:beans>
그 중에서 userService 는 UserDetails Service 를 자신의 사용자 표 와 적합 하 게 만 들 었 고 Url Security Interceptor Filter 는 AbstractSecurity Interceptor 를 계승 하여 Filter 인 터 페 이 스 를 실현 했다. url Security MetadataSource 는 FilterInvocation Security MetadataSource 인 터 페 이 스 를 실현 하고 security AccessDecisionManager 는 AccessDecisionManager 인 터 페 이 스 를 실현 했다.이들 은 모두 spring 의 주 해 를 통 해 용기 의 대상 으로 설명 되 기 때문에 설정 파일 에서 직접 참조 할 수 있 습 니 다.
springsecurity 3 은 이미 실 현 된 방문 결정 기 를 제공 합 니 다. 추상 적 인 종 류 는 AbstractAccessDecisionManager 입 니 다. 이 는 투표 체제 (AccessDecisionVoter) 를 사용 하여 사용자 가 특정한 자원 에 접근 할 수 있 는 권한 이 있 는 지 확인 합 니 다. 사실은 현 류 는 세 가지 가 있 습 니 다.
Affirmative Based: 투표 기 하나만 통과 하면 심사 통과
Consensus Based: 찬성 표 > 반대 표 가 있 을 때 만 심 사 를 통과 할 수 있 습 니 다.
Unanimous Based: 투표 기 하나 가 반대 하면 심 사 를 통과 하지 못 합 니 다.
당신 은 이 추상 류 의 실현 류 를 직접 사용 할 수 있 습 니 다. 그 설정 은 다음 과 같 습 니 다.
<beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
<!-- false , -->
<beans:property name="allowIfAllAbstainDecisions" value="false"/>
<!-- -->
<beans:property name="decisionVoters">
<beans:list>
<beans:bean class="org.springframework.security.access.vote.RoleVoter"/>
<beans:bean class="org.springframework.security.access.vote.AuthenticatedVoter"/>
</beans:list>
</beans:property>
</beans:bean>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
thymeleaf로 HTML 페이지를 동적으로 만듭니다 (spring + gradle)지난번에는 에서 화면에 HTML을 표시했습니다. 이번에는 화면을 동적으로 움직여보고 싶기 때문에 입력한 문자를 화면에 표시시키고 싶습니다. 초보자의 비망록이므로 이상한 점 등 있으면 지적 받을 수 있으면 기쁩니다! ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.