示例#1
0
  public boolean isMemberOf(List roleNames) {
    boolean result = false;
    Set possibleUsers = subject.getPrincipals(RealmRole.class);
    Iterator itr = possibleUsers.iterator();
    while (itr.hasNext()) {
      RealmRole role = (RealmRole) itr.next();
      Realm realm = role.getRealm();
      String realmFullName = realm.getFullName();
      String roleSimpleName = role.getName();
      if ((realmFullName.length() > 0) && roleSimpleName.startsWith(realmFullName)) {
        // Format is "<realm full name>\<role name>"
        roleSimpleName = roleSimpleName.substring(realmFullName.length() + 1);
      }

      if (roleNames.contains(roleSimpleName)) {
        result = true;
        break;
      }
    }
    return result;
  }
示例#2
0
 private Principal userPrincipal() {
   Set possibleUsers = subject.getPrincipals(RealmUser.class);
   return (Principal) possibleUsers.iterator().next();
 }