I am new to Spring security and CAS. The client web application is a Spring 3.0 mvc+(Tomcat6+apache2.2+jk_module) and there are no restricted pages or directory access. Each webpage has two sections protected(loggedin can see it) and unprotected(anonymous) and also there is a login link(to CAS remote server) at the top of page.The we application works fine and I do not get any errors but the authentication part does not work. The problem is when clicking the login link the page goes to the CAS server and after successful authentication the CAS remote server does not return the page to the web application page and remains at the CAS sever page with this message "Log In Successful". What is wrong with my security configuration? Thanks for helping, MK

web.xml

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    WEB-INF/security.xml
    </param-value>
    </context-param>  

  <listener>
     <listener-class>
      org.springframework.web.context.ContextLoaderListener
     </listener-class>
  </listener>     

   <filter>
     <filter-name>springSecurityFilterChain</filter-name>
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>    
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

  <servlet>
   <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
        </init-param>
      <load-on-startup>1</load-on-startup>
</servlet>

     <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>        
    </servlet-mapping>
      <session-config>
        <session-timeout>120</session-timeout>
    </session-config>   

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://remote-cas.com/cas/logout"/>
     </http>  


      <user-service id="userService">
        <user name="myapp_ca" 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://myIpaddress/myapp/homePage.htm"/>
          <property name="sendRenew" value="false"/>          

   </bean> 

<bean id="casEntryPoint"    class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
  <property name="loginUrl" value="https://remote-cas.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="/myapp/homePage.html" />
        </bean>
      </property>
    </bean>  

 <bean id="ticketValidator" class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
     <constructor-arg value="https://remote-cas.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="cas"></property>    
      </bean>
有帮助吗?

解决方案

When calling the CAS login URL you need to provide the URL where to you want to return to as a parameter. The parameter is also the name of the resource that you want to protect.

https://my.domain.com/cas/login?service=https://my.protected-service.com/path/to/page/

In order to make the ticket valid for all resources on my.protected-service.com you need to widen the scope of the ticket by setting the CAS scope to my.protected-service.com/

However, I don't know how to achieve that with your setup.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top