2011-09-24 6 views
9

मैं प्रमाणीकरण उद्देश्य के लिए स्प्रिंग 3.1 का उपयोग कर रहा हूं।एकाधिक लॉगिन पृष्ठों के लिए वसंत 3.x कॉन्फ़िगरेशन

मेरे आवश्यकता:

  • दो अलग प्रवेश पृष्ठों। एक ग्राहक के लिए और दूसरे कर्मचारी के लिए।
  • सफल प्रमाणीकरण के बाद प्रत्येक को संबंधित सफल यूआरएल में भेजा जाएगा।

मेरे वसंत सुरक्षा विन्यास:

<sec:http pattern="/resources/**" security="none" /> 
<sec:http auto-config="true"> 
    <sec:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
    <sec:intercept-url pattern="/customer/**" access="ROLE_CUSTOMER" /> 
    <sec:intercept-url pattern="/employee/**" access="ROLE_EMPLOYEE" /> 
</sec:http> 

<bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy"> 
    <sec:filter-chain-map path-type="ant"> 
     <sec:filter-chain pattern="/**" 
      filters="authenticationProcessingFilterForCustomer,authenticationProcessingFilterForEmployee" /> 
    </sec:filter-chain-map> 
</bean> 

<bean id="authenticationProcessingFilterForCustomer" 
    class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
    <property name="authenticationManager" ref="authenticationManagerForCustomer" /> 
    <property name="filterProcessesUrl" value="/j_spring_security_check_for_customer" /> 
    <property name="authenticationSuccessHandler" ref="customerSuccessHandler" /> 
    <property name="authenticationFailureHandler" ref="customerFailureHandler" /> 
</bean> 
<bean id="customerSuccessHandler" 
    class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> 
    <property name="defaultTargetUrl" value="/customer/index.html" /> 
</bean> 
<bean id="customerFailureHandler" 
    class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
    <property name="defaultFailureUrl" value="/customer.html?login_error=1" /> 
</bean> 
<bean id="authenticationManagerForCustomer" 
    class="org.springframework.security.authentication.ProviderManager"> 
    <property name="providers"> 
     <list> 
      <ref bean="customCustomerAuthenticationProvider" /> 
     </list> 
    </property> 
</bean> 
<bean id="customCustomerAuthenticationProvider" class="com.edu.CustomerCustomAuthenticationProvider"> 
    <property name="userDetailsService"> 
     <bean class="com.edu.CustomerUserDetailsService" /> 
    </property> 
</bean> 

<bean id="authenticationProcessingFilterForEmployee" 
    class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
    <property name="authenticationManager" ref="authenticationManagerForEmployee" /> 
    <property name="filterProcessesUrl" value="/j_spring_security_check_for_employee" /> 
    <property name="authenticationSuccessHandler" ref="employeeSuccessHandler" /> 
    <property name="authenticationFailureHandler" ref="employeeFailureHandler" /> 
</bean> 
<bean id="employeeSuccessHandler" 
    class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> 
    <property name="defaultTargetUrl" value="/employee/index.html" /> 
</bean> 
<bean id="employeeFailureHandler" 
    class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
    <property name="defaultFailureUrl" value="/employee.html?login_error=1" /> 
</bean> 
<bean id="authenticationManagerForEmployee" 
    class="org.springframework.security.authentication.ProviderManager"> 
    <property name="providers"> 
     <list> 
      <ref bean="customEmployeeAuthenticationProvider" /> 
     </list> 
    </property> 
</bean> 
<bean id="customEmployeeAuthenticationProvider" class="com.edu.EmployeeCustomAuthenticationProvider"> 
    <property name="userDetailsService"> 
     <bean class="com.edu.EmployeeUserDetailsService" /> 
    </property> 
</bean> 

<sec:authentication-manager alias="authenticationManager"> 
    <sec:authentication-provider ref="customCustomerAuthenticationProvider" /> 
    <sec:authentication-provider ref="customEmployeeAuthenticationProvider" /> 
</sec:authentication-manager> 

दोनों CustomAuthenticationProvider समर्थन विधि को लागू किया है इस प्रकार है:

public boolean supports(Class<? extends Object> authentication) { 
    return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication); 
} 

, ऐप्लिकेशन को लॉन्च करने प्रमाणित करने के प्रयास के बाद, संदेश प्रवेश पृष्ठों में दिखाया गया हैं :

आपका लॉगिन प्रयास एन था ओटी सफल, पुनः प्रयास करें।
कारण: नहीं AuthenticationProvider org.springframework.security.authentication.UsernamePasswordAuthenticationToken

मैं वसंत 3.1 उपयोग कर रहा हूँ के लिए मिल गया। किसी भी मदद की सराहना की।

धन्यवाद

+0

शायद http://stackoverflow.com/questions/4783063/configuring-spring-security-3-x-to-have-multiple-entry- पॉइंट्स से संबंधित या डुप्लिकेट से संबंधित है? – Raghuram

+0

"एकाधिक प्रविष्टि बिंदुओं के लिए स्प्रिंग सुरक्षा 3.x को कॉन्फ़िगर करने" के लिए हल समाधान, विभिन्न प्रकार के उपयोगकर्ता के लिए एकल प्रविष्टि बिंदु और एकल सफल पृष्ठ है। मुद्दा मेरे पास एकाधिक प्रविष्टि बिंदु है और प्रत्येक का अपना सफल पृष्ठ है। –

+0

@ManasSahu क्या आप अपने प्रश्न में अपने कस्टम प्रमाणीकरण प्रदाताओं के 'समर्थन()' विधियों का कोड जोड़ सकते हैं? – Ritesh

उत्तर

0

आप सेम जैसे 'authenticationManager' जो प्रदाताओं है सही करने के लिए 'authenticationProcessingFilterForCustomer' और 'authenticationProcessingFilterForEmployee' सेम में authenticationManager रेफरी इंगित करना चाहिए। 'प्रमाणीकरण प्रबंधक के लिए ग्राहक' और 'प्रमाणीकरण प्रबंधक के लिए कर्मचारी' बीन्स को परिभाषित करने की कोई आवश्यकता नहीं है।

1

मैं grails में इसी तरह के कार्य किए हैं, तुम क्या जरूरत है:

  1. विस्तार UsernamePasswordAuthenticationToken, दो उप-वर्ग बनाने कर्मचारी और ग्राहक के लिए, कर्मचारी उपयोगकर्ता नाम पासवर्डवर्ड प्रमाणीकरण टोकन और ग्राहक उपयोगकर्ता नाम पासवर्डवर्ड प्रमाणीकरण टोकन
  2. उपयोगकर्ता नाम पासवर्ड का प्रमाणीकरण फ़िल्टर का उपयोग करें उपयोगकर्ता नाम उपयोगकर्ता पासवर्ड के विभिन्न उदाहरण बनाने के लिए प्रमाणीकरण टी oken या CustomerUsernamePasswordAuthenticationToken वर्तमान प्रमाणन अनुरोध
  3. , कर्मचारी और custoner के लिए विस्तार AuthenticationProvider दो वर्ग बनाने के आधार पर कहते हैं कि EmployeeAuthenticationProvider और CustomerAuthenticationProvider, हर वर्ग के 'के ऊपर लिख अपने लक्ष्य UsernamePasswordAuthenticationToken
  4. आप केवल एक authenticationManager की जरूरत का समर्थन करने के विधि का समर्थन करता है, रजिस्टर दोनों में प्रदान करते हैं यह
  5. केवल एक AuthenticationSuccessHandler की जरूरत है, आप तय कर सकते हैं जो यूआरएल यह
  6. मैं भी बहु entrypoint समर्थन करने के लिए AuthenticationEntryPoint के अपने खुद के उदाहरण बनाने में जाना चाहता हूँ
संबंधित मुद्दे