1

seam 3 と cdi を使用してアプリケーションを作成しています。次のようなセキュリティ部分の例から始めました。

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

できます。私のユーザーが管理者の役割を持っている場合、彼はアクセスできます。しかし、ユーザーが 1 つのルールまたは別のルールを持っている可能性がある状況をどのように実装できますか? 例: 私のユーザーが @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 に答える