2014-02-13 60 views
0

Spring安全3.0和CAS的新功能。 客戶端Web應用程序是一個Spring 3.0 mvc,它使用Spring安全篩選器(DelegatingFilterProxy)和CAS來驗證用戶身份,並且工作正常。 每個頁面頂部的登錄鏈接將用戶重定向到遠程CAS服務器,並且在成功登錄後,CAS遠程服務器將網頁發送回Spring Web應用程序而沒有任何錯誤。 問題是,我不知道如何從CAS獲取用戶數據?使用Spring Security從CAS Server成功完成登錄後獲取用戶數據

security.xml文件:

<http entry-point-ref="casEntryPoint" auto-config="true"> 
      <intercept-url pattern="/*.html" filters="none"/> 
      <intercept-url pattern="/login.jsp" filters="none"/>  
      <custom-filter ref="casFilter" position="CAS_FILTER" /> 
       <logout logout-success-url="https://CAS_server.com/cas/logout"/> 
    </http> 


     <user-service id="userService"> 
     <user name="myApp_auto" authorities="ROLE_USER"/> 
     </user-service> 

    <authentication-manager alias="authManager"> 
     <authentication-provider ref="casAuthProvider" /> 
    </authentication-manager> 


    <bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties"> 
      <property name="service" value="https://myIpAddrress/myapps/homePage.htm"/> 
      <property name="sendRenew" value="false"/>   

    </bean> 


<bean id="casEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint"> 
    <property name="loginUrl" value="https://CAS_server.com/cas/login"/> 
    <property name="serviceProperties" ref="serviceProperties"/> 
</bean> 

    <bean id="casFilter"  class="org.springframework.security.cas.web.CasAuthenticationFilter"> 
     <property name="authenticationManager" ref="authManager"/> 
    <property name="authenticationSuccessHandler"> 
     <bean class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> 
     <property name="defaultTargetUrl" value="/myapps/homePage.html" /> 
     </bean> 
    </property> 
    </bean> 

    <bean id="ticketValidator" class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator"> 
    <constructor-arg value="https://CAS_server.com/cas/login" />    
    </bean> 



    <bean id="casAuthProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider"> 
    <property name="ticketValidator" ref="ticketValidator"/> 
    <property name="serviceProperties" ref="serviceProperties"/> 
     <property name="authenticationUserDetailsService"> 
      <bean class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper"> 
       <constructor-arg ref="userService" /> 
      </bean> 
     </property> 
     <property name="key" value="empNumber"></property> 
     </bean> 
+0

你指的是什麼數據?通常情況下,唯一的信息CAS轉移到您的應用程序是用戶名。其餘部分從您配置的UserDetailsS​​ervice本地加載(Spring Security通過檢索的用戶名傳遞)。 –

+0

我的意思是用戶的employeeId和..,你能明確地給出一些使用UserDetailsS​​ervice.Thanks的代碼 – user2433850

回答

0

的認證過程中,CAS服務器一般檢索用戶ID,但也是他的屬性。所以你可以跳過應用程序這一步。 從CAS服務器的應用程序發送這些屬性的方法是使用後正確地配置CAS服務的SAML服務票證驗證,以允許發送這些屬性: http://jasig.github.io/cas/current/integration/Attribute-Release.html https://github.com/Jasig/java-cas-client/blob/master/cas-client-core/src/main/java/org/jasig/cas/client/validation/Saml11TicketValidator.java

相關問題