开发者

Spring Security: User Authorization in Java Class

开发者 https://www.devze.com 2023-03-11 01:03 出处:网络
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\"/>)?

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

精彩评论

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