craftsman
craftsman

Reputation: 15653

Spring Security: User Authorization in Java Class

Does Spring Security provide any way to authorize a user in java class, the way it provides tags for authorization in JSPs (such as <sec:authorize ifAllGranted="ROLE_ADMIN"/>)?

I am expecting a static method of some class that I can use in my code like this:

if(SomeSpringSecurityClass.authorize("ROLE_ADMIN")){
...
}

Upvotes: 1

Views: 2818

Answers (1)

Paul Lysak
Paul Lysak

Reputation: 1294

You'd better do this check declaratively, but if you still need programmatic way - it has already been discussed on stackoverflow earlier: How to check "hasRole" in Java Code with Spring Security?

In short words, there's no such single ready-made method but you can start from SecurityContextHolder.getContext() to perform this check.

Upvotes: 1

Related Questions