【问题标题】:seam 3 security and roles接缝 3 安全性和角色
【发布时间】:2012-01-22 06:27:09
【问题描述】:

我正在使用 seam 3 和 cdi 创建一个应用程序。我从一个例子开始,对于这样的安全部分:

public @ConversationScoped class UserAction {
  public @Admin void deleteUser(String userId) {
   // code
  }
}

它有效。如果我的用户具有管理员角色,则他具有访问权限。但是我怎样才能实现用户可能有一个或另一个规则的情况呢?例如:如果我的用户是@Admin 或@Student,他可以访问它,但如果他是@Teacher,他不能。

谢谢。

凯莉

【问题讨论】:

    标签: security seam3


    【解决方案1】:

    我认为您需要 create your own authorizer method 进行您需要的特定角色检查:

    import org.jboss.seam.security.annotations.Secures;
    
    public class Restrictions {      
      public @Secures @Admin boolean isAdmin(Identity identity) {
        return identity.hasRole("admin", "USERS", "GROUP");
        // Here, you would put in logic for "if my user is
        //     @Admin or @Student he can access this, but 
        //     if he is a @Teacher he cannot" instead.
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-22
      • 2014-02-10
      • 1970-01-01
      • 2016-06-21
      • 2011-03-26
      • 2012-09-06
      • 1970-01-01
      • 2011-05-30
      • 2013-03-21
      相关资源
      最近更新 更多