简体   繁体   English

Java:带有自定义批注的方法级授权检查

[英]Java: Method-level authorization check with custom annotation

Has anyone successfully used custom annotations in Java to implement security checks or authorization on method-level? 是否有人成功使用Java中的自定义批注在方法级别实现安全性检查或授权? Something like this: 像这样:

@AccessValidator(AccessLevel.ADMIN)
public void method(){...}

Or similar. 或类似。

Is this possible, preferably without using Spring etc? 是否可能(最好不使用Spring等)? Thanks! 谢谢!

This is AOP's job. 这是AOP的工作。

You can use either Spring AOP or plain AOP. 您可以使用Spring AOP或普通AOP。

Take a look at this: 看看这个:

https://en.wikipedia.org/wiki/Aspect-oriented_programming https://zh.wikipedia.org/wiki/面向方面的编程

All you have to do is create annotation, and write a @Before advice and handle that kind of security in that advice. 您要做的就是创建注释,并编写@Before建议并在该建议中处理这种安全性。 One code, work everywhere :D 一种代码,无处不在:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM