使用 Spring MVC 进行基于角色的访问控制
我想知道 Spring 基于角色的访问控制的最佳实践。
我的要求是,
我将分配给用户一组角色,
user1=管理员,user2=专家
user1 的访问权限如下
/admin/会员管理
/admin/项目管理
......
对于 user2....
/myproject1/*
因此,如果 user2 尝试访问该网址
/admin/会员管理
将重定向到授权失败页面。
I would like to know the best practices for the role based access control with spring.
My requirements are,
I will have set of roles assigned to users say,
user1=admin, user2=expert
user1 will have the accesses write like
/admin/member-management
/admin/project-management
......
for user2....
/myproject1/*
so if user2 tries to access the url
/admin/member-management
will be redirect to authorization failure page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与 Spring MVC 一起使用的标准框架是 Spring Security。虽然它可能非常复杂,但这是您需要的最小版本: 4.2.2 最小配置
在您的情况下,配置将如下所示:
The standard framework to use with Spring MVC is Spring Security. While it can be very complex, here's a minimal version of what you need: 4.2.2 A Minimal Configuration
In your case, the config would be something like this:
Spring Security 有角色的概念,但开箱即用,它没有权限的概念。它确实有一个 ACL 但此 ACL 比权限复杂得多,并且它们与对特定对象的操作相关,而不是一般授权操作。
看一下 Apache Shiro。它的角色和权限看起来与您给出的示例非常相似(使用通配符)。它也易于与 Spring 一起使用。
Spring Security has the concept of roles but out of the box it does not have a concept of permissions. It does have a concept of ACLs but this ACLs are a lot more complicated than permissions, and they are tied to acting on specific objects, versus authorizing actions in general.
Take a look at Apache Shiro. It has roles and permissions that look very similar to what you gave as an example (using wildcards). It is also easy to use with Spring.
}
}