我正在为 Spring 安全性编写自己的 PermissionEvaluator,我想做的事情之一就是找出它所保护的方法的名称。
例如,如果没有图片中的方法名称,我有类似的内容:
postAuthorize("hasPermission(returnObject,'read')")
Event getEvent(int evendId) {
...
}
Run Code Online (Sandbox Code Playgroud)
和
public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
if(targetDomainObject instanceof Event) {
return hasPermission(authentication, targetDomainObject, permission);
}
return targetDomainObject == null;
}
Run Code Online (Sandbox Code Playgroud)
但我还需要方法名称“getEvent”可供 hasPermission 使用。我可以通过在 hasPermission 调用中手动传递它来完成此操作,如下所示:
@PostAuthorize("hasPermission(new com.example.AuthZObject(returnObject,'getEvent'),'read')")
Event getEvent(int eventId);
Run Code Online (Sandbox Code Playgroud)
但有没有更自动化的方法来做到这一点?