aurelius
aurelius

Reputation: 4076

Manage Spring Security access page with specific role

I need to manage the access too different jsp pages based on the role of the user that accesses it.

So let's say that I wanna access adminPage. If this method is accesed having admin role then i should be able to return the page, otherwise not.

So I have this controller:

@Controller public class SpringSecurityController

inside this controller I have this method which return me the requested page:

@RequestMapping("admin") //this does not work
public String getAdminPage()
{
    return "adminPage";
}

The trick is that i want to be capable to set this level of authorization as annotation to the getAdminPage() method in the given controller without any web xml settings or any other xml settings involved.

Help is much needed!

Upvotes: 0

Views: 209

Answers (2)

sol4me
sol4me

Reputation: 15718

You can use Secured Annotation. Annotate getAdminPage() with @Secured ({"ROLE_ADMIN"}) , If you want multiple roles then seprate them via comma like this

@Secured ({"ROLE_USER", "ROLE_ADMIN"}) 
public String getAdminPage()
{
    return "adminPage";
}

Upvotes: 1

sven.kwiotek
sven.kwiotek

Reputation: 1479

first try with slash

@RequestMapping("/admin")

Upvotes: 0

Related Questions