我有
Spring MVC
Spring Security项目.
<http auto-config="true" access-denied-page="/security/accessDenied" use-expressions="true" disable-url-rewriting="true"> ... <intercept-url pattern="/dashboard/myaccount/**" access="hasAnyRole('ROLE_PERSON','ROLE_DEALER')"/> ... <form-login login-page="/security/login" authentication-failure-url="/security/login?error=true" default-target-url="/security/success" username-parameter="email" password-parameter="secret"/> <logout invalidate-session="true" logout-success-url="/index" logout-url="/security/logout"/>
如果用户进入登录页面,如果成功将被重定向到“/ security / success”,我在控制器中使用会话对象(记录userID,…等)进行更多的操作,
我的问题是当一个GUEST用户正在/ dashboard / myaccount(需要AUTH)时,他被重定向到LOGIN页面(我不想要,我更喜欢404抛出).之后,Spring Security没有重定向到/ security / success.而是重定向到/ dashboard / myaccount.
在GUEST尝试访问AUTH页面的情况下,我更愿意找到一种完全禁用此重定向到登录页面的方法.
有办法做到吗
TNX
解决方法
我们添加一个新的authenticationEntryPoint:
<http auto-config="true" access-denied-page="/security/accessDenied" use-expressions="true" disable-url-rewriting="true" entry-point-ref="authenticationEntryPoint"/> <beans:bean id="authenticationEntryPoint" class="a.b.c..AuthenticationEntryPoint"> <beans:constructor-arg name="loginUrl" value="/security/login"/> </beans:bean> public class AuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint { public AuthenticationEntryPoint(String loginUrl) { super(loginUrl); } @Override public void commence(HttpServletRequest request,HttpServletResponse response,AuthenticationException authException) throws IOException,ServletException { response.sendError(403,"Forbidden"); } }