I'm developing a web application using Spring MVC + Spring Security, and I have the following URLs:
/*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
and I need them to be secured as previously described.
My configure method goes as follows:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.regexMatchers("/users/[\\w]+/profile").authenticated()
.antMatchers("/users/[\\w]/**").access("principal.name == regexGroupMatch")
.anyRequest().authenticated()
.and()
.jee().mappableRoles("Admin", "User");
}
I want to know if it's possible to achieve something like that:
.antMatchers("/heroes/[\\w]/**").access("principal.name == regexGroupMatch")
By doing this, I'm willing only the user user1 to be able to access the URLs:
/users/user1/profile/edit
/users/user1/picture/edit
/users/user1/notifications
So, user2 must not be able to access the previously mentioned URLs, but must be able to access: /users/user1/profile/edit /users/user1/picture/edit /users/user1/notifications
As well as:
/users/user1/profile
/users/user2/profile
/users/user3/profile
etc...
Is it possible to achieve that using Spring Security?
.antMatcher(url), but I don't know how which method should I use in order to allow only the current user to see his own profile. - fvdalcin