繁体   English   中英

CAS Spring Security Java-未授权用户详细信息服务未加载角色

[英]CAS Spring Security Java - Not Authorizing with User Details Service Not Loading Roles

我在Java 6中使用spring 3.2.5和spring security 3.1.4的最新版本,我已使用此页面上的说明设置了CAS服务器https://wiki.jasig.org/display/CASUM/Best+Practice+-设置+上载+ CAS +本地+使用+ Maven + WAR +叠加+方法

CAS服务器部分可以正常工作并进行身份验证。 我已经使用此页面和其他各个页面上的说明来设置客户端, https://wiki.jasig.org/display/CASC/Configuring+the+JA-SIG+CAS+Client+for+Java+using+Spring

当试图在应用程序中输入安全页面时,CAS会重定向到正确的登录页面,然后正确地进行身份验证,然后正确地重定向到调用的应用程序页面,但是没有调用提供的用户详细信息服务,也没有授权用户并且不使用以下方式加载角色用户详细信息服务。

身份验证后,用户将登陆此页面。 该页面正确,但是我不想在URL中看到ticket参数,也不想使用提供的用户详细信息服务bean来加载用户和角色。

http://localhost:8080/my/sports-life/schedule?ticket=ST-3-xklhdGJW6gZxieELGxo5-cas01.example.org

非常感谢获得我授权的任何指示。 提前致谢。

这是来自应用程序上下文的相关bean

<!--  Single sign on with CAS   -->


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

    <bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
        <property name="service" value="http://localhost:8080/my/sports-life/schedule/j_spring_cas_security_check"/>
        <property name="sendRenew" value="false"/>
    </bean>

    <bean id="casFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
        <property name="authenticationManager" ref="preAuthenticationManager"/>

        <property name="authenticationSuccessHandler">
            <bean class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
                <property name="defaultTargetUrl" value="/my"/>
                <property name="targetUrlParameter" value="spring-security-redirect" />
            </bean>
        </property>
    </bean>

    <bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">

        <property name="userDetailsService" ref="myAccountDetailsService" />
        <property name="serviceProperties" ref="serviceProperties" /> 
        <property name="ticketValidator">
            <bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
                <constructor-arg index="0" value="https://localhost:8443/cas" />
            </bean>
        </property>
        <property name="key" value="Vi9Pra88Si777"/> 
        <property name="authenticationUserDetailsService" ref="authenticationUserDetailsService"/>
     </bean> 

    <bean id="authenticationUserDetailsService" class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">    
        <property name="userDetailsService" ref="myAccountDetailsService"/>      
    </bean> 



    <bean name="authenticationFilter" class="org.jasig.cas.client.authentication.AuthenticationFilter">
        <property name="casServerLoginUrl" value="https://localhost:8443/cas/login" /> 
        <property name="renew" value="false" />
        <property name="gateway" value="false" />
        <property name="service" value="http://localhost:8080/my/sports-life/schedule" />
     </bean>

<!--  
<bean
    name="ticketValidationFilter"
    class="org.jasig.cas.client.validation.Cas10TicketValidationFilter">

    <property name="service" value="http://localhost:8080/my/sports-life/schedule" />
    <property name="ticketValidator">
            <bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
                <constructor-arg index="0" value="https://localhost:8443/cas" />
            </bean>
    </property>
</bean>
-->

  <bean id="preauthAuthProvider"
class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
    <property name="preAuthenticatedUserDetailsService">
      <bean id="userDetailsServiceWrapper"
          class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
        <property name="userDetailsService" ref="myAccountDetailsService"/>
      </bean>
    </property>
    </bean>

    <!--  
 <bean id="preAuthEntryPoint" class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint" />

    <bean id="j2eePreAuthFilter" class="org.springframework.security.web.authentication.preauth.j2ee.J2eePreAuthenticatedProcessingFilter">
        <property name="authenticationManager" ref="preAuthenticationManager"/>
        <property name="authenticationDetailsSource">
            <bean class="org.springframework.security.web.authentication.WebAuthenticationDetailsSource" />
        </property>
 </bean>
  -->

      <bean id="myAccountDetailsService" class="com.viprasi.security.AccountDetailsServiceImpl">        
     </bean> 

然后这是我的spring安全配置文件中的相关配置。

<http use-expressions="true" entry-point-ref="casEntryPoint">

        <intercept-url pattern="/app/j_spring_cas*" access="permitAll"
            requires-channel="https" />


        <!-- Member -->
        <intercept-url pattern="/app/**" access="isAuthenticated()" />


        <access-denied-handler error-page="/app/login/accessdenied" />

        <anonymous />

        <http-basic />

        <custom-filter position="CAS_FILTER" ref="casFilter" />

    </http>

     <authentication-manager alias="preAuthenticationManager">

      <authentication-provider ref="casAuthenticationProvider" />
      <!-- 
      <authentication-provider user-service-ref='accountDetailsService' />
      -->
    </authentication-manager>

我认为匿名标记将角色* IS_AUTHENTICATED_ANONYMOUSLY *应用于用户。 结果是用户isAuthenticated()并且没有调用其他过滤器(例如,调用UserDetailsS​​ervive的过滤器),将isAuthenticated()更改为hasRole('ROLE')

我有一个cas客户端示例您可以在cas-web-client中检查如何提供自己的授权

我们遇到了很多问题,最后的罪魁祸首是URL重写过滤器。 这个过滤器正在更改URL,然后spring security和cas无法处理更改的URL。 将url重写过滤器移动到安全过滤器下方后,所有这些都开始工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM