Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  /*
   * Gibt ACCESS_GRANTED zurueck, wenn der Benutzer eine Rolle hat, die ihm eine der
   * requestedAuthorizations auf die Baumassnahme erlaubt.
   *
   * <pre> requested: baumassnahme_bewerten, granted: baumassnahme_bewerten_alle oder
   * baumassnahme_bewerten_region, wenn die Region dem Benutzer zugeordnet ist </pre>
   */
  public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config) {
    int result = ACCESS_DENIED;

    User user = UserServiceImpl.getCurrentApplicationUser();
    Uebergabeblatt zvf = (Uebergabeblatt) object;
    Iterator iter = config.getConfigAttributes();
    while (iter.hasNext()) { // Schleife über erforderliche Berechtigungen
      ConfigAttribute attribute = (ConfigAttribute) iter.next();
      if (supports(attribute)) {
        GrantedAuthority[] authorities = authentication.getAuthorities();

        // Schleife über vorhandene Berechtigungen
        for (int i = 0; i < authorities.length; i++) {
          if (authorities[i].getAuthority().startsWith(attribute.getAttribute())) {
            if (logger.isDebugEnabled())
              logger.debug(String.format("Found authority %s", authorities[i]));

            // Zentral
            if (authorities[i].getAuthority().endsWith("_ALLE")) result = ACCESS_GRANTED;
            // Regional
            else if (authorities[i].getAuthority().endsWith("_REGIONALBEREICH")) {
              if (attribute.getAttribute().startsWith("ROLE_BBZR_ANLEGEN")) {
                result = ACCESS_GRANTED;
              } else if (user.getRegionalbereich() != null) {
                // MasterRB
                try {
                  String masterRB =
                      zvf.getMassnahmen().iterator().next().getMasterniederlassung().substring(3);
                  if (user.getRegionalbereich().getName().equalsIgnoreCase(masterRB))
                    result = ACCESS_GRANTED;
                } catch (NoSuchElementException e) {
                }
              }
            }
            if (result == ACCESS_GRANTED) break;
          }
        }
      }
    }

    return result;
  }
 public boolean supports(ConfigAttribute attribute) {
   if (attribute.getAttribute().equals("ROLE_BENUTZER_ROLLEN_VERGEBEN")) {
     return true;
   }
   return false;
 }