Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring WEB security: list of accessible URLs

I'm migrating a WEB-application to Spring Security. Application uses Spring MVC for rendering JSPs, and controller methods are annotated with @Secured(...).

So, at some point after successful login and MVC servlet initialization some Spring internals have this information: what permissions the user has (aka granted authorities), controller URLs and permission set, required for each one of those.

What I want is to dynamically get a list of URLs accessible for the current user to generate a navbar.

Of course, I can override some Spring beans for that, but this approach seems too dirty. So, any suggestions on how to do that, maybe standard solutions?

like image 664
Andy Avatar asked Jun 24 '13 12:06

Andy


People also ask

What is the difference between hasRole () and hasAuthority ()?

hasRole. Determines if the getAuthentication() has a particular authority within Authentication. getAuthorities() . This is similar to hasAuthority(String) except that this method implies that the String passed in is a role.

What is anyRequest () authenticated ()?

anyRequest(). authenticated() is that any request must be authenticated otherwise my Spring app will return a 401 response.

What is hasRole and hasAnyRole?

Description. hasRole([role]) Returns true if the current principal has the specified role. hasAnyRole([role1,role2]) Returns true if the current principal has any of the supplied roles (given as a comma-separated list of strings)


1 Answers

You can try using spring security tag lib in the jsp, iterating over the list of controllers URLs

<sec:authorize url="/admin">
This content will only be visible to users who are authorized to send requests to the "/admin" URL.
</sec:authorize>
like image 104
Abel Pastur Avatar answered Nov 15 '22 00:11

Abel Pastur