2013-05-24 10 views
5

एच मैं वसंत सुरक्षास्प्रिंग सुरक्षा 3 http-बुनियादी प्रमाणीकरण-सफलता-हैंडलर

उपयोग कर रहा हूँ प्रपत्र: प्रवेश के लिए मेरे पास है

<http auto-config="true"> 
     <intercept-url pattern="/pages/**" access="ROLE_USER" /> 
     <form-login authentication-success-handler-ref="authenticationSuccessHandler" login-page="/login.html" default-target-url="/pages/index.html" 
      always-use-default-target="true" authentication-failure-url="/login.html" /> 
     <logout logout-success-url="/login.html" invalidate-session="true" /> 
     <anonymous enabled='false'/> 
</http> 

यहाँ मैं एक authentication-success-handler-ref सेट कर सकते हैं, मैं कैसे कर सकते हैं मेरी बुनियादी प्रमाणीकरण के लिए एक जोड़ें:

<http pattern="/REST/**" realm="REALM" entry-point-ref="authenticationEntryPoint"> 
    <intercept-url pattern="/**" access="ROLE_USER" /> 
    <http-basic /> 
    <logout logout-url="/REST/logout" success-handler-ref="restLogoutSuccessHandler" /> 
</http> 

मैं BasicAuthenticationFilter अधिभावी abour सोचा, लेकिन मैं कैसे 012 के लिए मेरे cutom वर्ग इंजेक्षन कर सकते हैं

उत्तर

5

आप बेसिक प्रमाणीकरण के लिए प्रमाणीकरण सफलता हैंडलर सेट नहीं कर सकते हैं। हालांकि, आप BasicAuthenticationFilter का विस्तार करने और विधि onSuccessfulAuthentication ओवरराइड कर सकते हैं:

@Component("customBasicAuthFilter") 
public class CustomBasicAuthFilter extends BasicAuthenticationFilter { 

    @Autowired 
    public CustomBasicAuthFilter(AuthenticationManager authenticationManager) { 
     super(authenticationManager); 
    } 

    protected void onSuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Authentication authResult) { 
     // Do what you want here 
    } 
} 

अपने सुरक्षा विन्यास में इसकी सुई की तरह कुछ के साथ:

<http entry-point-ref="basicEntryPoint"> 
    <custom-filter ref="customBasicAuthFilter" position="BASIC_AUTH_FILTER"/> 
</http> 
<authentication-manager alias="authenticationManager"> 
    ... 
</authentication-manager> 

अद्यतन: या XML की बजाय जावा config के साथ:

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
     .addFilterAt(customBasicAuthFilter, BasicAuthenticationFilter.class) 
     .exceptionHandling().authenticationEntryPoint(basicEntryPoint); 
} 
+0

क्या इस एक्सएमएल के लिए जावा कॉन्फ़िगरेशन प्रदान करना संभव होगा? –

+0

@Jadda हां, अद्यतन देखें। – holmis83

3

समाधान के लिए आप फार्म लॉगिन के साथ conjuction में http-बुनियादी उपयोग कर सकते हैं:

<http auto-config="true"> 
    ... 
    <http-basic /> 
    <form-login authentication-success-handler-ref="authenticationSuccessHandler" ... /> 
    ... 
</http> 

BasicAuthenticationFilter काम करेंगे।

संपादित करें। आप BasicAuthenticationFilter के अपने ओवरराइड संस्करण की स्थापना चाहते हैं मुझे तुम्हारी जरूरत है करने के लिए लगता है: BASIC_AUTH_FILTER स्थिति में श्रृंखला फिल्टर करने के लिए

  1. यह जोड़े के रूप में समझाया here
  2. इसी प्रवेश point- के माध्यम से BasicAuthenticationEntryPoint प्रवेश बिंदु सेट करें रेफरीhttp टैग की विशेषता।
+0

हाय इसके साथ मैं हमेशा लॉगिन प्रारूप प्राप्त करता हूं, और कोई प्रमाणीकरण challange – wutzebaer

+0

बिल्कुल नहीं, लेकिन मूल –

+0

सबमिट करने के बाद ऑथ का उपयोग किया जाना चाहिए, लेकिन मुझे अपने/REST यूआरएल – wutzebaer

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