如何在 Spring AOP 中使用 before 建议作为安全措施。
例如,我有这个之前的建议(带有伪代码):
@Before("trigger()")
public void beforeMethod(JoinPoint point){
Method[] a = point.getSignature().getClass().getDeclaredMethods();
for(int i=0; i < a.length; i++){
//if method has such arguments then
if(a[i] 'has args String name, String role, Int Money'){
//And if these arguments meets such requirements
if(a[i].argument(Int.class) > 1000 or a[i].argument(String role).equals("normal"))
//Stop executing this method
a[i].stop
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这只是伪代码,所以它看起来可能不正确,但我希望您能有所了解。如果满足或不满足某些要求,是否有一些 JoinPoint 方法可以停止扫描方法?
只抛出一个异常怎么样?
if (!isAllowed) {
throw new NotAuthorizedException(..)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4203 次 |
| 最近记录: |