这有几种方法。
<security:http auto-config="true">
<security:intercept-url pattern="/admin/**" access="ROLE_ADMIN"/>
<security:intercept-url pattern="/userReged/**" access="ROLE_USER"/>
<security:form-login
login-page="/"
default-target-url="/somePage"
authentication-failure-url="/user/logfailed?error"
username-parameter="userName"
password-parameter="userPassword" />
<security:logout
logout-success-url="/?logout"/>
</security:http>
另一个:首先,你可以通过设置login-page
它会自动重定向未登陆用户达到安全的途径(如/ userReged/**)到某些登录页面使用Spring Security自动配置在applicationContext.xml
方法是检查用户正在登录在你的控制器手动具体路线:
@RequestMapping("/somePage")
public String getSomePage(Model model, HttpServletRequest request) {
Principal principal = request.getUserPrincipal();
if (principal != null) {
User activeUser = userService.getUserByPhone(principal.getName());
// ...
} else { // user is not authenticated
System.out.println("user is not authenticated to proceed the somePage!!!!!!!");
return "redirect:/";
}
}
为了设置超时时间为春季安全,你可以把这个在您的web.xml
:
<session-config>
<session-timeout>
1440
<!--mins-->
</session-timeout>
</session-config>
现在,如果您想要在确切的超时时间重定向客户端,则可以在某些时间间隔内自动刷新客户端的页面。
[如何使用Spring Security自动注销](https://stackoverflow.com/questions/27775651/how-to-make-automatically-log-out-with-spring-security) – Syroezhkin
I已经看到这个网址,但它不拦截超时。我的问题更多地集中在超时。 – user4906240
可能在spring security.xml中,我必须在中添加一些额外的标签,以便将SimpleUrlLogoutSuccessHandler注册到应用程序中? –
user4906240