+-

我是春天安全的新手.我怎么解释这个?
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI')") OpetussuunnitelmaDto addOpetussuunnitelma(OpetussuunnitelmaDto opetussuunnitelmaDto);
来自权限评估程序的哪种方法会被调用?我想在这种情况下会调用带有三个参数的那个.它正在检查当前用户是否对类型目标”opetussuunnitelma’具有’LUONTI’权限.我对吗?我们不能只包括“null”并且只传递两个参数.我读到没有提供第一个参数(Authentication对象).
+public class PermissionEvaluator implements org.springframework.security.access.PermissionEvaluator { + + @Override + public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) { + LOG.error(" *** ei toteutettu *** "); + return true; + } + + @Override + public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) { + LOG.error(" *** ei toteutettu *** "); + return true; + } + + private static final Logger LOG = LoggerFactory.getLogger(PermissionEvaluator.class); +}
最佳答案
Which method from the permission evaluator would get called?
public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission)会被叫到.
I read that the first argument ( the Authentication object) is not
supplied.
它没有在您的注释中明确提供,而是由Spring隐式提供.您的注释应该只是阅读
@PreAuthorize("hasPermission(#opetussuunnitelmaDto, 'LUONTI')")理想情况下,我会在执行授权之前检查它们是否经过身份验证.
@PreAuthorize("isAuthenticated() and hasPermission(#opetussuunnitelmaDto, 'LUONTI')")更新您的评论
基本上,您可以使用以下任一方法调用PermissionEvaluator:
hasPermission('#targetDomainObject', 'permission') // method1 hasPermission('targetId', 'targetType', 'permission') // method2身份验证将始终由Spring提供.在您的情况下,您通过以下方式调用hasPermission
hasPermission(null, ‘opetussuunnitelma’, ‘LUONTI’)”)
哪个会匹配method2,但是传入一个null id是没有意义的,你要将什么实体作为目标进行权限检查?根据您正在应用@PreAuthorize的方法,
OpetussuunnitelmaDto addOpetussuunnitelma(OpetussuunnitelmaDto
opetussuunnitelmaDto);
调用method1可能更有意义,因为你似乎有一些类似于目标域对象的东西.
点击查看更多相关文章
转载注明原文:java – 如何解释spring security中的hasPermission? - 乐贴网