Пример #1
0
  private Roles createDefaultAuthorizedRoles() {
    authorizedRoles = new Roles();
    authorizedRoles.add(UserRole.ROLE_PROJECTMANAGER);
    authorizedRoles.add(UserRole.ROLE_CONSULTANT);
    authorizedRoles.add(UserRole.ROLE_ADMIN);
    authorizedRoles.add(UserRole.ROLE_REPORT);

    return authorizedRoles;
  }
Пример #2
0
  public static Class<? extends Page> getHomepageForRole(Roles roles) {
    Class<? extends Page> homepage;

    if (roles.contains(WebUtils.ROLE_CONSULTANT)) {
      homepage = MonthOverviewPage.class;
    } else if (roles.contains(WebUtils.ROLE_ADMIN)) {
      homepage = MainConfigPage.class;
    } else if (roles.contains(WebUtils.ROLE_REPORT)) {
      homepage = ReportPage.class;
    } else {
      homepage = MonthOverviewPage.class;
    }

    return homepage;
  }
 /**
  * Utility method to check that the user owns one of the roles provided in input.
  *
  * @param roles the checked roles.
  * @return true if the user owns one of roles in input, false otherwise.
  */
 protected final boolean hasAny(Roles roles) {
   if (roles.isEmpty()) {
     return true;
   } else {
     return roleCheckingStrategy.hasAnyRole(roles);
   }
 }
Пример #4
0
  @Override
  public Roles getRoles() {
    if (isSignedIn()) {
      if (impersonatingAuthUser.isPresent()) {
        Roles roles = new Roles();

        Set<UserRole> userRoles = getAuthUser().getUser().getUserRoles();

        for (UserRole userRole : userRoles) {
          roles.add(userRole.getRole());
        }

        return roles;
      }

      return getRolesForSignedInUser();
    }
    return null;
  }
Пример #5
0
  private Roles getRolesForSignedInUser() {
    // Retrieve the granted authorities from the current authentication. These correspond one on
    // one with user roles.
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if (auth != null) {
      Roles roles = new Roles();

      Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();

      for (GrantedAuthority grantedAuthority : authorities) {
        roles.add(grantedAuthority.getAuthority());
      }

      if (roles.size() == 0) {
        LOGGER.warn("User " + auth.getPrincipal() + " logged in but no roles could be found!");
      }

      return roles;
    } else {
      LOGGER.warn("User is signed in but authentication is not set!");
      return null;
    }
  }
Пример #6
0
  /**
   * Check if the logged in user has the specified role
   *
   * @param role
   * @return
   */
  public static boolean hasRole(String role) {
    Roles roles = getRoles();

    return (roles != null) && roles.contains(role);
  }