मैं वसंत सुरक्षा और SAML से संबंधित समस्या का पता लगाने की कोशिश कर रहा हूं। हम अपने उत्पाद को संशोधित करने के लिए स्प्रिंग सिक्योरिटी (वसंत-सुरक्षा-कोर-3.1.1.RELEASE.jar) और SAML (वसंत-सुरक्षा-saml2-core-1.0.0-RC1-SNAPSHOT.jar) का उपयोग करने का प्रयास कर रहे हैं। एसएएमएल एसपी संपादित करें: यहां (मुझे लगता है!) मेरे सुरक्षा से संबंधित संदर्भ xml का प्रासंगिक खंड है। जैसा कि आप देख सकते हैं, यह लगभग this sample XML के समान है।वसंत सुरक्षा और नेस्टेड फ़िल्टरChainProxy लेखन SAML सेवा प्रदाता
<!-- Entry point to initialize authentication, default values taken from properties file -->
<bean id="samlEntryPoint" class="com.myproduct.samlsp.impl.PSSAMLEntryPoint">
<property name="defaultProfileOptions">
<bean class="org.springframework.security.saml.websso.WebSSOProfileOptions">
<property name="includeScoping" value="false"/>
</bean>
</property>
</bean>
<!-- Unsecured pages -->
<security:http security="none" pattern="/saml/web/**"/>
<security:http security="none" pattern="/logout.jsp"/>
<security:http security="none" pattern="/favicon.ico"/>
<security:http security="none" pattern="/images/**"/>
<security:http security="none" pattern="/scripts/**"/>
<security:http security="none" pattern="/flash/**"/>
<security:http security="none" pattern="/loggedout.html"/>
<!-- Secured pages -->
<security:http entry-point-ref="samlEntryPoint">
<security:intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY"/>
<security:custom-filter before="FIRST" ref="metadataGeneratorFilter"/>
<security:custom-filter after="BASIC_AUTH_FILTER" ref="samlFilter"/>
</security:http>
<!-- IDP Discovery Service -->
<bean id="samlIDPDiscovery" class="org.springframework.security.saml.SAMLDiscovery">
<property name="idpSelectionPath" value="/WEB-INF/security/idpSelection.jsp"/>
</bean>
<bean id="samlFilter" class="org.springframework.security.web.FilterChainProxy">
<security:filter-chain-map request-matcher="ant">
<security:filter-chain pattern="/saml/login/**" filters="samlEntryPoint"/>
<security:filter-chain pattern="/saml/logout/**" filters="samlLogoutFilter"/>
<security:filter-chain pattern="/saml/metadata/**" filters="metadataDisplayFilter"/>
<security:filter-chain pattern="/saml/SSO/**" filters="samlWebSSOProcessingFilter"/>
<security:filter-chain pattern="/saml/SSOHoK/**" filters="samlWebSSOHoKProcessingFilter"/>
<security:filter-chain pattern="/saml/SingleLogout/**" filters="samlLogoutProcessingFilter"/>
<security:filter-chain pattern="/saml/discovery/**" filters="samlIDPDiscovery"/>
</security:filter-chain-map>
</bean>
लक्षण है कि, तुरंत आईडीपी के साथ प्रमाणीकरण के बाद, मेरे सपा के पृष्ठ ठीक से दिखाई देता है, हालांकि, यूआरएल को बदलना (उदा। किसी भी लिंक पर क्लिक करना) मुझे तुरंत आईडीपी पर भेजता है। मुझे लगता है कि मैंने क्यों पता लगाया है, लेकिन मुझे नहीं पता कि यह हमेशा ऐसा क्यों नहीं होता है।
वसंत सुरक्षा की मेरी समझ यह है कि प्राधिकरण जांच सभी सुरक्षा कॉन्टेक्स्टहोल्डर के आसपास आधारित है। अर्थात्, धारक पर एक प्रमाणीकरण ऑब्जेक्ट डालें, और सबकुछ इसके चारों ओर ऑथ चेक करता है। फिर सुरक्षा कॉन्टेक्स्ट पर्सिस्टेंसफिल्टर मिलान करने के लिए सत्र भंडार को बनाए रखने के लिए ज़िम्मेदार है।
तो, के रूप में मैं वसंत सुरक्षा कोड के माध्यम से पता लगाने, मैं SecurityContextPersistenceFilter निम्न कोड के साथ देखें:
SecurityContext contextBeforeChainExecution = repo.loadContext(holder);
try {
SecurityContextHolder.setContext(contextBeforeChainExecution);
chain.doFilter(holder.getRequest(), holder.getResponse());
} finally {
SecurityContext contextAfterChainExecution = SecurityContextHolder.getContext();
// Crucial removal of SecurityContextHolder contents - do this before anything else.
SecurityContextHolder.clearContext();
repo.saveContext(contextAfterChainExecution, holder.getRequest(), holder.getResponse());
....
}
अब तक तो अच्छा। फिर, मैं फ़िल्टरChainProxy को देखता हूं और पाते हैं:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
try {
doFilterInternal(request, response, chain);
} finally {
// SEC-1950
SecurityContextHolder.clearContext(); <------- Key line here
}
}
यह अभी भी ठीक लगता है। चूंकि फ़िल्टरचैनप्रॉक्सी को केवल एक बार वसंत सुरक्षा फ़िल्टर के आधार पर ही बुलाया जाना चाहिए, उस समय सुरक्षा कॉन्टेक्स्टहोल्डर को साफ़ करने में कोई समस्या नहीं है।
हालांकि, यह नहीं हो रहा है। वास्तव में क्या हो रहा है फ़िल्टरChainProxy में clearContext को सुरक्षा कॉन्टेक्स्ट पर्सिस्टेंसफिल्टर से पहले संदर्भ में संदर्भ से इसे पढ़ने का मौका मिलता है। इसके बाद संदर्भ में निष्पादन। ऐसा होने का कारण यह है कि फ़िल्टर चेनप्रॉक्सी वास्तव में कॉल श्रृंखला में दो बार होता है। मुझे यह पता है क्योंकि मैंने FilterChainProxy.doFilter में ब्रेकपॉइंट सेट किया है, और इसे दो बार बुलाया जाता है। इसे पहली बार बुलाया जाता है, इसमें फ़िल्टरचैन में फ़िल्टरChainProxy का एक और उदाहरण है। यहाँ FilterChainProxy के getFilters विधि द्वारा दिया फिल्टर के ढेर है:
org[email protected]78104d3c
org.spring[email protected]168c795e
FilterChainProxy[ Filter Chains: [ .... my patterns ] ],
org.sp[email protected]7fffde92
org.springframework.[email protected]e2d09d7
org.springfram[email protected]1c2b968f
o[email protected]395f222a
org[email protected]372e6f09
org.springfr[email protected]7dab91aa
फिल्टर के इस श्रृंखला के साथ
, मैं समझता हूँ नहीं कैसे SecurityContextPersistenceFilter कभी काम कर सकते हैं: ऐसा लगता है SecurityContextHolder हमेशा साफ कर दिया जाएगा इससे पहले कि यह एक मौका हो जाता है इसे जारी रखने के लिए।
क्या यहां कुछ स्पष्ट गलत है? क्या मैं वसंत सुरक्षा में कुछ गलत समझ रहा हूं (बहुत संभव है!)
समाधान पोस्ट करने के लिए धन्यवाद। मुझे आपके समाधान के लिए भी एक ही समस्या का सामना करना पड़ रहा था। –
सुनकर खुशी हुई कि मैं अकेला नहीं हूं जिसने इसे देखा है। पीछा करने के लिए धन्यवाद! – fool4jesus
वसंत सुरक्षा संस्करण को 3.1.4.RELEASE में अपग्रेड करने के बाद भी मुझे एक ही समस्या का सामना करना पड़ रहा है। – ManojP