Overload haspermission中的Pustermission evaluator
我试图在许可证中的haspermission方法过载。但是,除了Java无法找到该方法。
CustomPermissionEvaluator.java:
public class CustomPermissionEvaluator implements PermissionEvaluator {
@Override
public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
...
}
@Override
public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType,
Object permission) {
...
}
// self overloading
public boolean hasPermission(Authentication authentication, Object permission) {
System.out.println("hasPermission with 1 variable");
return true;
}
}
控制器进入这里:
@Service
public class UserController implements UsersApiDelegate {
@Override
@org.springframework.security.access.prepost.PreAuthorize("hasPermission('users.read')")
public ResponseEntity<List<UserDto>> getUsers(Optional<String> acceptLanguage) {
//...
}
}
errormessage ist:
ERROR 26800 --- [nio-8000-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Failed to evaluate expression 'hasPermission('users.read')'] with root cause
也许有人可以帮助我。 我也尝试了:
@org.springframework.security.access.prepost.PreAuthorize("@CustomPermissionEvaluator .hasPermission('users.read')")
但
@org.springframework.security.access.prepost.PreAuthorize("@packages.to.the.class.CustomPermissionEvaluator.hasPermission('users.read')")
不幸的是
@org.springframework.security.access.prepost.PreAuthorize("packages.to.the.class.CustomPermissionEvaluator.hasPermission('users.read')")
,到目前为止什么都没有。
我想念什么?
Im trying to overload the hasPermission-method in a PermissionEvaluator. But in the exception java cant find the method.
CustomPermissionEvaluator.java:
public class CustomPermissionEvaluator implements PermissionEvaluator {
@Override
public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
...
}
@Override
public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType,
Object permission) {
...
}
// self overloading
public boolean hasPermission(Authentication authentication, Object permission) {
System.out.println("hasPermission with 1 variable");
return true;
}
}
The controller goes here:
@Service
public class UserController implements UsersApiDelegate {
@Override
@org.springframework.security.access.prepost.PreAuthorize("hasPermission('users.read')")
public ResponseEntity<List<UserDto>> getUsers(Optional<String> acceptLanguage) {
//...
}
}
The errormessage ist:
ERROR 26800 --- [nio-8000-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Failed to evaluate expression 'hasPermission('users.read')'] with root cause
Perhaps someone can help me.
I also tried:
@org.springframework.security.access.prepost.PreAuthorize("@CustomPermissionEvaluator .hasPermission('users.read')")
and
@org.springframework.security.access.prepost.PreAuthorize("@packages.to.the.class.CustomPermissionEvaluator.hasPermission('users.read')")
and
@org.springframework.security.access.prepost.PreAuthorize("packages.to.the.class.CustomPermissionEvaluator.hasPermission('users.read')")
But unfortunately nothing worked so far.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你能以这种方式检查吗?
@preauthorize(“@packages.to.class.class.custompermission evaluator.haspermission({t(package.to.class.users).read})”)
could you check that way?
@PreAuthorize("@packages.to.the.class.CustomPermissionEvaluator.hasPermission({ T(package.to.class.Users).READ} )")