Apache shiro 隐含权限

发布于 2024-10-21 09:53:10 字数 290 浏览 4 评论 0原文

如果用户拥有权限 user:edit:1 并且我使用注释驱动的 @RequiresPermissions("user:edit") 为什么 shiro 会抛出异常?难道他们拥有 user:edit:1 的事实不应该暗示该权限吗?如果我放置 @RequriesPermissions("user:edit:1") 那么它工作正常,但在操作上下文中我还不知道 1 是什么,因此稍后将在方法中检查,但如果他们根本没有 user:edit 权限,我想完全避免进入该方法。

If a user has a permissions user:edit:1 and I'm using the annotation driven @RequiresPermissions("user:edit") why is shiro throwing an exception? Shouldn't that permission be implied by the fact that they have user:edit:1? If I put @RequriesPermissions("user:edit:1") then it works fine but during the context of operation I won't know what 1 is yet so that will be checked later in the method, but I'd like to avoid going into the method at all if they don't have the user:edit permission at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

可是我不能没有你 2024-10-28 09:53:10

我不认为,ascandrolis 的答案是正确的,因为 Shiro 文档指出:

但是,以下内容对于运行时检查来说不太理想:

if (SecurityUtils.getSubject().isPermission("printer:print")) {
//打印文档
<代码>}

为什么?因为第二个示例说“您必须能够打印到任何打印机才能执行以下代码块”。但请记住,“printer:print”相当于“printer:print:*”!

(Shiro 文档)

所以 @RequiresPermissions("user:edit: *") 与 @RequiresPermissions("user:edit") 含义相同,即主体需要能够编辑任何用户。

I don't think, ascandrolis answer is correct, since Shiro documentation states:

The following however is much less ideal for a runtime check:

if (SecurityUtils.getSubject().isPermitted("printer:print")) {
//print the document
}

Why? Because the second example says "You must be able to print to any printer for the following code block to execute". But remember that "printer:print" is equivalent to "printer:print:*"!

(Shiro Documentation)

So @RequiresPermissions("user:edit:*") means the same as @RequiresPermissions("user:edit"), i.e. that the principal needs to be able to edit any user.

孤星 2024-10-28 09:53:10

“user:edit” 暗示 “user:edit:1”,但反之则不然。
您可以继续使用 @RequiresPermissions("user:edit"),然后检查方法中是否有 "1"。您还可以使用通配符 @RequiresPermissions("user:edit:*"),它完全相同,但我认为它更清晰。

"user:edit" implies "user:edit:1" but not the other way around.
You can keep using @RequiresPermissions("user:edit") and then check for the "1" in your method. You can also use a wildcard @RequiresPermissions("user:edit:*"), which is the exactly the same but I think it's clearer.

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