2012-06-05 18 views
5

में मैं उसी टॉमकैट उदाहरण में तैनात दो अलग-अलग वेब एप्लिकेशन का उपयोग कर रहा हूं। वेब एप्लिकेशन में से एक और दूसरा एक आरईएसटी सेवाएं है। जब उपयोगकर्ता वेब एप्लिकेशन में लॉग इन होता है और आरईएसटी सेवा को कॉल करता है, तो आरईएसटी को वेब एप्लिकेशन का उपयोग करके लॉग इन किए गए उपयोगकर्ता के साथ प्रमाणीकृत होना चाहिए। मैं टोमकैट में एसएसओ कैसे कार्यान्वित कर सकता हूं> अगर किसी ने इसे लागू किया है, तो कृपया एमडब्ल्यू की मदद करें।वेब एप्लिकेशन और आरईएसटी सेवाएं एसएसओ टॉमकैट और वसंत-सुरक्षा

अद्यतन: मैंने अपने पहले वेब एप्लिकेशन में स्प्रिंग सुरक्षा और जे 2 ईईई प्रमाणीकरण तंत्र लागू किया है। यह एप्लिकेशन DOJO (जावास्क्रिप्ट फ्रेमवर्क) का उपयोग करके दूसरे एप्लिकेशन (आरईएसटी सेवाएं) को आमंत्रित करता है।

अद्यतन: मुझे समाधान मिला है। कृपया नीचे मेरा जवाब पढ़ें।

उत्तर

6

हम पारंपरिक वेब एप्लिकेशन और गैर वेब आधारित एप्लिकेशन जैसे रीस्टफुल वेब सेवाओं के बीच एसएसओ को कार्यान्वित कर सकते हैं। यह उदाहरण वेब एप्लिकेशन और रीस्टफुल वेब सेवाओं के बीच एसएसओ को लागू करने के लिए नमूना कोड दिखाता है। निम्नलिखित spring-security.xml फ़ाइल

<security:http create-session="never" use-expressions="true" 
        auto-config="false" 
        entry-point-ref="preAuthenticatedProcessingFilterEntryPoint" > 

     <security:intercept-url pattern="/**" access="permitAll"/> 
     <security:intercept-url pattern="/admin/**" access="hasRole('tomcat')"/> 
     <security:intercept-url pattern="/**" access="hasRole('tomcat')"/> 
     <security:custom-filter position="PRE_AUTH_FILTER" ref="preAuthFilter"/> 
     <!-- Required for Tomcat, will prompt for username/password twice otherwise --> 
     <security:session-management session-fixation-protection="none"/> 
    </security:http> 

    <bean id="preAuthenticatedProcessingFilterEntryPoint" 
       class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint"/> 

    <bean id="preAuthFilter" 
       class="org.springframework.security.web.authentication.preauth.j2ee.J2eePreAuthenticatedProcessingFilter"> 
     <property name="authenticationManager" ref="appControlAuthenticationManager"/> 
     <property name="authenticationDetailsSource" 
         ref="j2eeBasedPreAuthenticatedWebAuthenticationDetailsSource"/> 
    </bean> 

    <security:authentication-manager alias="appControlAuthenticationManager"> 
     <security:authentication-provider ref="preAuthenticatedAuthenticationProvider"/> 
    </security:authentication-manager> 

    <bean id="preAuthenticatedAuthenticationProvider" 
       class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider"> 
     <property name="preAuthenticatedUserDetailsService" ref="inMemoryAuthenticationUserDetailsService"/> 
    </bean> 

    <bean id="j2eeBasedPreAuthenticatedWebAuthenticationDetailsSource" 
       class="org.springframework.security.web.authentication.preauth.j2ee.J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource"> 
     <property name="mappableRolesRetriever" ref="webXmlMappableAttributesRetriever"/> 
     <property name="userRoles2GrantedAuthoritiesMapper" ref="simpleAttributes2GrantedAuthoritiesMapper"/> 
    </bean> 

    <bean id="webXmlMappableAttributesRetriever" 
       class="org.springframework.security.web.authentication.preauth.j2ee.WebXmlMappableAttributesRetriever"/> 

    <bean id="simpleAttributes2GrantedAuthoritiesMapper" 
       class="org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper"> 
     <property name="attributePrefix" value=""/> 
    </bean> 

    <bean id="inMemoryAuthenticationUserDetailsService" 
       class="com.org.InMemoryAuthenticationUserDetailsService"/> 

ऊपर कोड वेब अनुप्रयोग में है में विन्यास है। आरईएसटी प्रोजेक्ट की वसंत सुरक्षा एक्सएमएल फ़ाइल में भी वही कोड हो सकता है। web.xml फ़ाइल में निम्न कोड जोड़ें:

<security-constraint> 
     <web-resource-collection> 
      <web-resource-name>Wildcard means whole app requires authentication</web-resource-name> 
      <url-pattern>/*</url-pattern> 
      <http-method>GET</http-method> 
      <http-method>POST</http-method> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>tomcat</role-name> 
     </auth-constraint> 

     <user-data-constraint> 
      <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE --> 
      <transport-guarantee>NONE</transport-guarantee> 
     </user-data-constraint> 
    </security-constraint> 
    <login-config> 
     <auth-method>FORM</auth-method> 
     <form-login-config> 
      <form-login-page>/login.jsp</form-login-page> 
      <form-error-page>/error.jsp</form-error-page> 
     </form-login-config> 
    </login-config> 

ऊपर कोड केवल सामान्य वेब अनुप्रयोग में होना चाहिए। फिर टोमकैट की server.xml फ़ाइल में एसएसओ वाल्व सक्षम करें। टोमकैट कुकी आधारित एसएसओ लॉगिन का उपयोग करता है। सत्र आईडी कुकीज़ में संग्रहीत हैं। यदि आपके ब्राउज़र ने कुकी को अक्षम कर दिया है, तो एसएसओ काम नहीं करेगा।

आशा है कि यह स्पष्टीकरण मदद करता है।

1

टोमकैट एसएसओ क्षमताओं को बॉक्स (कॉन्फ़िगरेशन के साथ) प्रदान करता है लेकिन यह अपने प्रमाणीकरण तंत्र के साथ काम करता है। मुझे विश्वास नहीं है कि आप टॉमकैट के कंटेनर-प्रबंधित एसएसओ को एप्लिकेशन-प्रबंधित (इस मामले में वसंत) प्रमाणीकरण तंत्र के साथ मिश्रित कर सकते हैं।

यदि वे मौजूद हैं तो आपको स्प्रिंग की एसएसओ क्षमताओं में देखना चाहिए।

+0

हम J2EEPreAutenticationProvider का उपयोग कर वसंत के साथ टोमकैट प्रमाणीकरण को मिश्रित कर सकते हैं। मैं वह कर सकता था। लेकिन, मुझे आरईएसटी सेवाओं और एक और सामान्य वेब एप्लिकेशन के लिए एसएसओ कार्यान्वयन की आवश्यकता है – Krishna

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