2013-02-26 5 views
1

Jersey RESTful 애플리케이션 위에 스프링 보안을 사용하여 인증 레이어를 구축하고 있습니다. 저지 응용 프로그램은 Content-Type을 기반으로 올바른 버전 처리기로 라우팅하는 "버전 관리 된"API입니다.스프링 보안 및 API 버전 관리

내 질문은 : 다른 API 버전은 인증 메커니즘이 다르므로 스프링 보안에서 이것을 처리하는 가장 좋은 방법은 무엇입니까? 각 인증 메커니즘마다 다른 AuthenticationFilter을 사용해야합니까? 각 버전 (Content-Type)에 AuthenticationFilter을 적용해야하는 스프링 보안 레이어에서 지식을 구축해야합니까?

감사합니다.

답변

2

다른 API 버전에 대해 서로 다른 필터 체인을 정의하고 RequestMatcher을 사용하여 요청의 Content-Type 헤더를 기반으로 일치시킬 수 있습니다.

<bean id="apiV1Matcher" class="org.springframework.security.web.util.ELRequestMatcher"> 
    <constructor-arg value="hasHeader('Content-Type','<pattern for api v1>')"/> 
</bean> 

<bean id="apiV2Matcher" class="org.springframework.security.web.util.ELRequestMatcher"> 
    <constructor-arg value="hasHeader('Content-Type','<pattern for api v2>')"/> 
</bean> 

<security:http request-matcher-ref="apiV1Matcher" ...> 
    <!-- config for api v1 requests --> 
</security:http> 

<security:http request-matcher-ref="apiV2Matcher" ...> 
    <!-- config for api v2 requests --> 
</security:http> 

중복으로 인해 너무 많은 경우 네임 스페이스 구성을 사용하고 가능한 경우 필터 체인간에 빈을 공유하지 마십시오.

+0

니스! 네가 할 수 있다는 것을 몰랐어. – maxenglander