Overload haspermission中的Pustermission evaluator

发布于 2025-02-03 04:37:56 字数 1975 浏览 2 评论 0原文

我试图在许可证中的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骷髅 2025-02-10 04:37:56

你能以这种方式检查吗?

@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} )")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文