2010-03-03 5 views
5

मैं स्प्रिंग सिक्योरिटी 3.0.2 का उपयोग कर रहा हूं और मुझे डेटाबेस से अज्ञात उपयोगकर्ता की भूमिका लोड करने का कोई तरीका नहीं मिल रहा है (मुझे गतिशील भूमिकाएं मिली हैं जहां भूमिकाएं सभी को दी जा सकती हैं)।वसंत सुरक्षा 3 में अज्ञात उपयोगकर्ता के लिए डेटाबेस से भूमिका कैसे लोड करें?

मैंने एक कस्टम अनाम प्रमाणीकरण प्रदाता का उपयोग करने का प्रयास किया है लेकिन इस प्रदाता को कभी नहीं कहा जाता है।

<http auto-config="false"> 
    <logout invalidate-session="true" logout-success-url="/page/welcome" /> 
    <remember-me /> 
    <anonymous username="_GUEST_" granted-authority="ROLE_GUEST" key="anonymousKey" /> 
    <form-login login-page="/page/login" authentication-failure-url="/page/login?fail=1" default-target-url="/page/welcome" /> 
</http> 

<authentication-manager alias="authenticationManager"> 
    <authentication-provider ref="anonymousAuthenticationProvider"></authentication-provider> 
    <authentication-provider user-service-ref="accountDetails"> 
     <password-encoder ref="passwordEncoder"> 
      <salt-source user-property="xxxx" /> 
     </password-encoder> 
    </authentication-provider> 
</authentication-manager> 

<beans:bean id="accountDetails" class="com.mysite.AccountDetailsImpl" /> 

<beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"> 
    <beans:constructor-arg value="512" /> 
</beans:bean> 

<beans:bean id="anonymousAuthenticationProvider" class="com.my.site.security.CustomAnonymousAuthenticationProvider"> 
    <beans:property name="key" value="anonymousKey" /> 
</beans:bean> 

मेरे anonymousAuthenticationProvider कहा जाता है कभी नहीं है तो मैं डेटाबेस से कस्टम अधिकारियों को लोड नहीं कर सकते हैं: यहाँ मेरी config है। जब मैं लॉग इन करता हूं, तो मेरा सेवा खाता विवरण कहा जाता है और मैं उपयोगकर्ता के लिए डेटाबेस से भूमिका लोड कर सकता हूं, मुझे अनाम उपयोगकर्ता के लिए वही चीज़ चाहिए।

मैं यह कैसे कर सकता हूं? धन्यवाद

+0

दोस्तों, मैं एक ही समस्या में हूँ। खोज है, क्या मैं अपने कस्टम प्रमाणीकरण में उपयोग करने के लिए क्वेरीस्ट्रिंग से प्राप्त पैरामीटर भेज सकता हूं? यदि हां, तो कैसे? क्या आप अपना पूरा एक्सएमएल डाल सकते हैं? बहुत कुछ! रॉड्रिगो –

उत्तर

3

ऐसा नहीं है कि सबसे आसान तरीका प्राप्त करने के लिए हो रहा है यह एक कस्टम UserAttribute है, जो आवश्यक अधिकारियों का उत्पादन करेगा के साथ एक AnonymousAuthenticationFilter घोषित करने के लिए है:

<http auto-config = "false"> 
    <anonymous enabled = "false" /> 
    <custom-filter ref = "myFilter" position = "ANONYMOUS_FILTER" /> 
    ... 
</http> 

<beans:bean id = "myFilter" class = "org.springframework.security.web.authentication.AnonymousAuthenticationFilter"> 
    <beans:property name = "key" value = "anonymousKey" /> 
    <beans:property name = "userAttribute" ref = "myAttributes" /> 
</beans:bean> 

<beans:bean id = "myAttributes" class = "..." /> 
+0

स्प्रिंग सुरक्षा 4 AnonymousAuthenticationFilter में 'के रूप में यहाँ वर्णित खो userAttribute': http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3 -to-4-xml.html # m3to4-deprecations-web-aaf तो यह नए संस्करणों में मदद नहीं करेगा। – shobull

संबंधित मुद्दे