【问题标题】:Spring security issue: Introducing more roles in security applicationSpring 安全问题:在安全应用中引入更多角色
【发布时间】:2012-03-21 16:11:14
【问题描述】:

我正在为我的 MVC 应用程序应用安全性,我现在正在为这些角色工作,它们的实现一切正常。我正在关注this tutorial。 Role.java 如下:

package com.heraclitus.domain;
public enum Role {

    ADMIN_ROLE("ROLE_ADMIN", 1), USER_ROLE("ROLE_USER", 0);

    private final int order;
    private final String roleName;

    private Role(final String roleName, final int order) {
        this.roleName = roleName;
        this.order = order;
    }

    public int order() {
        return order;
    }

    public String roleName() {
        return roleName;
    }
}

有人可以解释一下两个角色中的值 1 和 0 是什么ADMIN_ROLE("ROLE_ADMIN", 1), USER_ROLE("ROLE_USER", 0); 这是当我有一个管理员角色时,它还包含用户角色和一个用户角色。如果我有超过 2 个角色作为管理员角色,例如管理员,主管,用户等..?管理员角色中的 # 将是什么?

另一个问题是在applicationContext-security.xml中

<authentication-provider>
        <user-service id="userDetailsService">
            <user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" />
            <user name="username" password="password" authorities="ROLE_USER" />
            <user name="test" password="test" authorities="ROLE_USER" />
        </user-service>
    </authentication-provider>

现在,如果我想添加更多用户,例如1.Admin、2.Supervisor、3.Accountant 等,admin 对所有用户(主管、会计等)拥有所有权限我应该使用什么?什么是最好的方法?谢谢

【问题讨论】:

    标签: model-view-controller spring-security


    【解决方案1】:

    对我来说,使用 Spring Security 处理用户和角色的最佳方式是使用数据库(如果您愿意,可以使用属性文件)。

    检查点2.2.3:http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ns-config.html

    【讨论】:

    • 感谢您的建议,我也在努力。但我也想走这条路。
    猜你喜欢
    • 2011-01-01
    • 2012-04-08
    • 2014-07-23
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 2012-09-06
    相关资源
    最近更新 更多