首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CAS和Spring -通过身份验证但未授权,导致重定向循环

CAS和Spring -通过身份验证但未授权,导致重定向循环
EN

Stack Overflow用户
提问于 2015-03-18 01:51:14
回答 1查看 468关注 0票数 0

我使用CAS来确定针对LDAP的身份验证,但我无法将其添加到LDAP。因此,我使用MySQL来存储每个用户的角色。

我遇到的问题是,当一个人在LDAP中,但在MySQL中没有适当的角色时,我会得到一个重定向循环。应用程序尝试将用户发送回CAS登录,CAS登录(由于用户已通过身份验证并已被授予票证)尝试将其发送回页面,依此类推。

我的applicationContext.xml:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:sec="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">


        <sec:http entry-point-ref="casEntryPoint">
                <sec:intercept-url pattern="/**" access="ROLE_ODINUSERS,ROLE_ODINSUPERS,ROLE_ODINADMINS" />
                <sec:logout logout-success-url="/cas-logout.jsp" />
                <sec:custom-filter ref="casFilter" after="CAS_FILTER" />
        </sec:http>

        <sec:authentication-manager alias="authenticationManager">
                <sec:authentication-provider ref="casAuthenticationProvider" />
        </sec:authentication-manager>

        <bean id="casFilter"
                class="org.springframework.security.cas.web.CasAuthenticationFilter">
                <property name="authenticationManager" ref="authenticationManager" />
                <property name="authenticationFailureHandler">
                        <bean
                                class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
                                <property name="defaultFailureUrl" value="/cas-failed.jsp" />
                        </bean>
                </property>
                <property name="authenticationSuccessHandler">
                        <bean
                                class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
                                <property name="defaultTargetUrl" value="/" />
                        </bean>
                </property>
                <property name="proxyGrantingTicketStorage" ref="proxyGrantingTicketStorage" />
                <property name="proxyReceptorUrl" value="/secure/receptor" />
        </bean>

        <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="casAuthenticationProvider"
                class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
                <property name="userDetailsService" ref="userService" />
                <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" />
                                <property name="proxyGrantingTicketStorage" ref="proxyGrantingTicketStorage" />
                                <property name="proxyCallbackUrl"
                                        value="https://localhost:8443/cas/secure/receptor" />
                        </bean>
                </property>
                <property name="key" value="an_id_for_this_auth_provider_only" />
        </bean>

        <bean id="proxyGrantingTicketStorage"
                class="org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl" />

        <bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
                <property name="service" value="https://localhost:8443/CASTest/j_spring_cas_security_check" />
                <property name="sendRenew" value="false" />
        </bean>

    <sec:jdbc-user-service id="userService" data-source-ref="dataSource" 
        authorities-by-username-query="select username, role FROM user_authorization WHERE username = ?"
        users-by-username-query="SELECT username, password, enabled FROM user_authentication WHERE username = ?" />

      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName">
                <value>com.mysql.jdbc.Driver</value>
            </property>
            <property name="url">
                <value>jdbc:mysql://localhost:3306/user_mgt</value>
            </property>
            <property name="username"><value>root</value></property>
            <property name="password"><value>test</value></property>
        </bean>

        <bean class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>

</beans>

有没有一种优雅的方式绕过这个重定向循环?也许是一种定义一个页面的方法,如果用户未经授权就将其发送到该页面,而不是默认地将他们发送回登录页面?

EN

回答 1

Stack Overflow用户

发布于 2015-03-18 01:59:25

您可以通过使用

代码语言:javascript
运行
复制
 <sec:http entry-point-ref="casEntryPoint">
            <sec:intercept-url pattern="/**" access="ROLE_ODINUSERS,ROLE_ODINSUPERS,ROLE_ODINADMINS" />
            <sec:logout logout-success-url="/cas-logout.jsp" />
            <sec:custom-filter ref="casFilter" after="CAS_FILTER" />
            <sec:form-login login-page="/login" authentication-failure-url="/login?error"
        username-parameter="j_username" password-parameter="j_password"
        default-target-url="/somepageaction" />
    </sec:http>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29106271

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档