开发者

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 s开发者_JAVA百科tatic method of some class that I can use in my code like this:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜