Spring MVC Authority loaded externally

0 投票
最新提问 用户: (120 分)

I'm using spring mvc 4 and I have some rest services. Some of these methods are annotated with:

@PreAuthorize("hasAnyAuthority('myAuth1', 'myAuth2', 'myAuth3')")

So do you know if is there a way to load my permissions ('myAuth1', 'myAuth2', 'myAuth3') from an external method (maybe it load that from DB)?

Something like this:


Thanks all Have a good day


发表于 用户: (140 分)
Rather than putting annotations on your methods, you can configure the permissions in a java Security Config, at the URL level, and in the Security Config you can retrieve the permissions from a DB.
发表于 用户: (120 分)
But I have to configure the permissions for all methods of all controllers.. it's not really "beautiful"
发表于 用户: (140 分)
you could divide the methods in your controllers based on their acccess. Then, if /controller1/method1 and /controller1/method2 require the same access, in the SecurityConfig you'll set the access on /controller1/*. In the end, you'll have N configs, where N is the number of controllers. If that's not possible, then you can just check the permissions inside the method and call a service for the rights it requires.

登录 或者 注册 后回答这个问题。

欢迎来到 Security Q&A ,有什么不懂的可以尽管在这里提问,你将会收到社区其他成员的回答。