1

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

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

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

谢谢。

凯利

4

1 回答 1

0

我认为您需要创建自己的授权方方法来执行您需要的特定角色检查:

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.
  }
}
于 2011-12-18T17:41:28.630 回答