我正在开发使用Spring MVC + Spring Security的Web应用程序,和我有以下网址:如何使用Spring安全保护URL?
/*this URL should be accessible by any User, i.e. users should be able to see other users' profiles*/
/users/someUserId/profile
/* all the following URLs should be accessed only by the current authenticated user */
/users/someUserId/profile/edit
/users/someUserId/picture/edit
/users/someUserId/notifications
/users/someUserId/friends
,我需要如前所述它们固定。
我的配置方法去如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.regexMatchers("https://stackoverflow.com/users/[\\w]+/profile").authenticated()
.antMatchers("https://stackoverflow.com/users/[\\w]/**").access("principal.name == regexGroupMatch")
.anyRequest().authenticated()
.and()
.jee().mappableRoles("Admin", "User");
}
我想知道是否有可能实现这样的事情:
.antMatchers("/heroes/[\\w]/**").access("principal.name == regexGroupMatch")
通过这样做,我愿意只有用户user1能够访问的网址:
/users/user1/profile/edit
/users/user1/picture/edit
/users/user1/notifications
所以,user2的必须不能访问前面提到的网址,但必须能够访问: /用户/用户1 /型材/编辑 /用户/用户1 /图片/编辑 /用户/用户1 /通知
除了:
/users/user1/profile
/users/user2/profile
/users/user3/profile
etc...
是否有可能实现,使用Spring Security的?
你是否阅读过文档? – chrylis
是@chrylis,我已阅读文档[此处](http://docs.spring.io/spring-security/site/docs/3.2.3.RELEASE/reference/htmlsingle/)。我相信我可以使用'.antMatcher(url)'实现,但我不知道如何使用哪种方法才能让当前用户看到他自己的配置文件。 – fvdalcin
顺便说一句,你读过[这个主题](http://meta.stackoverflow.com/questions/251758/why-is-stack-overflow-so-negative-of-late)? – fvdalcin