我有一个主页,上面有登录对话框。使用我当前的spring安全配置,每当我访问受保护资源(尚未登录)时,例如' / ticket / list',我被重定向到主页。我认为拦截器将我重定向到配置文件中定义的登录URL。
问题是:
这是我当前的spring security配置文件:
<?xml version="1.0" encoding="UTF-8" ?>
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/security"
xmlns:oauth="http://www.springframework.org/schema/security/oauth"
xsi:schemaLocation="http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd
http://www.springframework.org/schema/security/oauth
http://www.springframework.org/schema/security/spring-security-oauth.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<http pattern="/resources/**" security="none"/>
<!-- Form and Security Access Configuration -->
<http use-expressions="true" disable-url-rewriting="true" auto-config="false">
<!-- <form-login/> -->
<form-login login-page="/" login-processing-url="/login/perform"/>
<logout logout-success-url="/"/>
<remember-me/>
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/login" access="permitAll" />
<intercept-url pattern="/ticket/*" access="isAuthenticated()" />
</http>
<b:bean id="userDetailsService" class="vn.web.security.UserDetailsServiceImpl"/>
<b:bean id="serviceBaseAuthenticationProvider" class="vn.web.security.ServiceBaseAuthenticationProvider"/>
<authentication-manager alias="authenticationManager">
<authentication-provider ref="serviceBaseAuthenticationProvider"/>
</authentication-manager>
感谢。
答案 0 :(得分:2)
发生的情况是,Spring-Security接收登录详细信息并传递给您的身份验证提供程序或用户详细信息服务,该服务应尝试从您的数据库或您正在使用的任何其他解决方案中检索用户详细信息。这应返回允许用户访问和成为会话所需的任何信息,或告知Spring Security凭据不正确,或者即使用户帐户已被禁止。
如果出现否定的情况,则键在此行中:
<form-login login-page="/" login-processing-url="/login/perform"/>
这告诉Spring Security哪个url映射重定向到您的登录页面。目前,您已将此设置设置为根上下文,通常是您的主页。如果您想重定向到仅包含登录表单的网页,则必须为其创建jsp,在控制器中添加一个方法以进行映射,并更新spring-security配置以匹配您的方法url处理程序控制器,例如
<form-login login-page="/login" login-processing-url="/login/perform"/>