Can Spring Security use @PreAuthorize on Spring co

2019-01-04 09:14发布

Can Spring Security use @PreAuthorize on Spring controllers methods?

7条回答
相关推荐>>
2楼-- · 2019-01-04 09:35

If you're using Spring 3.1, you can do some pretty cool stuff with this. Take a look at https://github.com/mohchi/spring-security-request-mapping. It's a sample project that integrates @PreAuthorize with Spring MVC's RequestMappingHandlerMapping so that you can do something like:

@RequestMapping("/")
@PreAuthorize("isAuthenticated()")
public String authenticatedHomePage() {
    return "authenticatedHomePage";
}

@RequestMapping("/")
public String homePage() {
    return "homePage";
}

A request for "/" will call authenticatedHomePage() if the user is authenticated. Otherwise it will call homePage().

查看更多
登录 后发表回答