duzyoufh 2015-03-03 15:41 采纳率: 0%
浏览 7806

spring security和cas重定向问题

问题:spring security能请求到cas返回的用户,并且初始化了权限,但是又重定向回主页,在重定向的时候丢失了验证用户信息,导致变成游客。
如果设置自动重定向回请求页面,会导致循环重定向,游客请求--获取cas的用户信息---重定向--丢失userDetails--没有权限--重定向回cas--无限循环了。

下面贴代码。



<!-- 当前session -->


<!-- 上下文 -->


<!-- 注销 -->

<!-- rememberMe
-->
<!-- Session固化,并发保护 -->

<!-- 异常 -->

<!-- CAS单点过滤 -->


<!-- -->
<!-- 权限拦截过滤 -->

/sec:http

<!-- CAS provider,切点用到 -->
<bean id="serviceProperties"  class="org.springframework.security.cas.ServiceProperties">    
    <property name="service"  value="http://localhost:8880/edu/j_spring_cas_security_check"/>    
    <property name="sendRenew" value="false"/>    
</bean> 
<!-- 登陆切点 -->
<bean id="casAuthEntryPoint"  class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">    
    <property name="loginUrl" value="http://localhost:8880/cas/login"/>    
    <property name="serviceProperties" ref="serviceProperties"/>    
</bean>



<!-- 验证器 -->
<sec:authentication-manager alias="authenticationManager">    
    <sec:authentication-provider ref="casAuthenticationProvider"/>   
    <!--  <sec:authentication-provider ref="rememberMeAuthenticationProvider"/>-->
    <!--  <sec:authentication-provider ref="daoAuthenticationProvider"/>-->

</sec:authentication-manager>  
<!-- 过滤器 -->
 <bean id="casFilter"  class="org.springframework.security.cas.web.CasAuthenticationFilter">    
    <property name="authenticationManager" ref="authenticationManager"/>   
     <property name="authenticationSuccessHandler">
        <bean class="com.huihui.security.handler.LoginSuccessHandler">
            <property name="indexUrl" value="/edu/eduHome/index" />
            <property name="userService" ref="userService" />
        </bean>
    </property>
</bean>

<!-- provicder用到, 用自己的userService -->
 <bean id="casAuthenticationUserDetailsService" class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">    
    <property name="userDetailsService" >    
        <ref bean="userDetailsService" />    
    </property>    
</bean> 
<!-- cas验证 ,authen-manager用到-->
<bean id="casAuthenticationProvider"    
        class="org.springframework.security.cas.authentication.CasAuthenticationProvider">    
    <property name="authenticationUserDetailsService" ref="casAuthenticationUserDetailsService"/>    
    <property name="serviceProperties" ref="serviceProperties" />    
    <property name="ticketValidator">    
        <bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">    
            <constructor-arg index="0" value="http://localhost:8880/cas" />    
        </bean>    
    </property>    
    <property name="key" value="an_id_for_this_auth_provider_only"/>    
</bean>    

<!-- 注销客户端 --> 
<bean id="singleLogoutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter" /> 

<!-- 注销服务器端 --> 
<bean id="requestSingleLogoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter"> 
    <constructor-arg value="http://localhost:8880/cas/logout" /> 
    <constructor-arg> 
        <bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/> 
    </constructor-arg> 
    <property name="filterProcessesUrl" value="/logout.sec" /> 
</bean> 


<!-- 自定义UserDetailsService认证  -->
<bean id="userDetailsService" class="com.huihui.security.service.UserDetailsServiceImpl">
</bean>
<!-- 自定义资源权限关系认证 -->
<bean id="accessDecisionManager" class="com.huihui.security.service.AccessDecisionManagerImpl" />


<!-- 自定义资源权限关系集合 -->
<bean id="securityMetadataSource"
    class="com.huihui.security.service.SecurityMetadataSourceExtendImpl">
    <property name="matcher" value="regex" />
</bean>

<!-- 核心!=自定义认证管理,资源,权限  拦截-->
<bean id="filterSecurityInterceptor"
    class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
    <property name="authenticationManager" ref="authenticationManager" />
    <property name="accessDecisionManager" ref="accessDecisionManager" />
    <property name="securityMetadataSource" ref="securityMetadataSource" />
</bean>

我所查看的日志得到的信息:
1.能请求到cas返回的用户,并且能用userDetailService装配完整的权限。
2.重定向的url就是在casFilter那个里面设置的。
3.在重定向之前有2次CAS请求,一次springsecurity有用户信息,但是不知道为什么会删除。
然后最后一次没有,变成游客,然后如果重定向的url需要权限,那么无限重定向。
如果重定向的URL不需要权限,那么就编程游客访问。
我所尝试的解决办法:
1.取消casFileter的重定向URL,自动重定向回"/" 这个主页。
2.删除权限验证filter,没有用户信息,是游客。
3.删除所有filter,只留cas和权限,没用还是无限重定向。

  • 写回答

1条回答 默认 最新

  • devmiao 2015-03-05 16:10
    关注
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!