springsecurity登录后依然跳回登录页面的问题

一、环境:

spring-security 4.0

spring 4.1

二、问题描述:

今天在配置springsecurity时,无论登录密码是否正确均跳转至登录首页,原始配置如下

<http auto-config="true">
        <intercept-url pattern="/" access="hasRole('ROLE_USER')" />
        <intercept-url pattern="/home.do"
            access="hasRole('ROLE_USER')" />
        <intercept-url pattern="/admin**"
            access="hasRole('ROLE_ADMIN')" />
        <intercept-url pattern="/dba**"
            access="hasRole('ROLE_ADMIN') and hasRole('ROLE_DBA')" />
        <form-login login-page="/login.do"
            username-parameter="ssoId" password-parameter="password"
            authentication-success-handler-ref="customSuccessHandler"
            authentication-failure-url="/login.do" />
        <csrf />
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="yiibai" password="123456" authorities="ROLE_USER" />
                <user name="admin" password="123456" authorities="ROLE_ADMIN" />
                <user name="dba" password="123456"
                    authorities="ROLE_ADMIN,ROLE_DBA" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

    <beans:bean id="customSuccessHandler"
        class="com.pegatroncorp.springsecurity.configuration.CustomSuccessHandler" />

而且在上述配置中,也无法进入我配置的customSuccessHandler的实体中,后经过排查,发现springsecurity确实运行并进行了拦截,但是无论密码是否正确,其依然只会跳回login.jsp,而且不进入我配置的customSuccessHandler中。

最终发现是缺少了login-processing-url="/login.do",加上这句就可以了

以下为正确的配置xml

<http auto-config="true">
		<intercept-url pattern="/" access="hasRole('ROLE_USER')" />
		<intercept-url pattern="/home.do"
			access="hasRole('ROLE_USER')" />
		<intercept-url pattern="/admin**"
			access="hasRole('ROLE_ADMIN')" />
		<intercept-url pattern="/dba**"
			access="hasRole('ROLE_ADMIN') and hasRole('ROLE_DBA')" />

        <!-- 在form-login中添加login-processing-url="/login.do" -->
		<form-login login-page="/login.do"
		    login-processing-url="/login.do"
			username-parameter="ssoId" password-parameter="password"
			authentication-success-handler-ref="customSuccessHandler"
			authentication-failure-url="/login.do" />
		<csrf />
	</http>

	<authentication-manager>
		<authentication-provider>
			<user-service>
				<user name="yiibai" password="123456" authorities="ROLE_USER" />
				<user name="admin" password="123456" authorities="ROLE_ADMIN" />
				<user name="dba" password="123456"
					authorities="ROLE_ADMIN,ROLE_DBA" />
			</user-service>
		</authentication-provider>
	</authentication-manager>

	<beans:bean id="customSuccessHandler"
		class="com.pegatroncorp.springsecurity.configuration.CustomSuccessHandler" />

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值