Source:
public Host addHost(PerunSession sess, Host host, Facility facility) throws InternalErrorException, FacilityNotExistsException, PrivilegeException { Utils.checkPerunSession(sess); Utils.notNull(host, "hosts"); getFacilitiesManagerBl().checkFacilityExists(sess, facility); if (!AuthzResolver.authorizedInternal(sess, "addHost_Host_Facility_policy", Collections.singletonList(facility))) { throw new PrivilegeException(sess, "addHost"); } List<Facility> facilitiesByHostname = getFacilitiesManagerBl().getFacilitiesByHostName(sess, host.getHostname()); List<Facility> facilitiesByDestination = getFacilitiesManagerBl().getFacilitiesByDestination(sess, host.getHostname()); if(facilitiesByHostname.isEmpty() && facilitiesByDestination.isEmpty()) { return getFacilitiesManagerBl().addHost(sess, host, facility); } if(!facilitiesByHostname.isEmpty()) { boolean hasRight = false; for(Facility facilityByHostname: facilitiesByHostname) { if(AuthzResolver.authorizedInternal(sess, "addHost_Host_Facility_policy", Collections.singletonList(facilityByHostname))) { hasRight = true; break; } } if(hasRight) return getFacilitiesManagerBl().addHost(sess, host, facility); } if(!facilitiesByDestination.isEmpty()) { boolean hasRight = false; for(Facility facilityByDestination: facilitiesByDestination) { if(AuthzResolver.authorizedInternal(sess, "addHost_Host_Facility_policy", Collections.singletonList(facilityByDestination))) { hasRight = true; break; } } if(hasRight) return getFacilitiesManagerBl().addHost(sess, host, facility); } throw new PrivilegeException(sess, "You can't add host " + host + ", because you don't have privileges to use this hostName"); }

Target:
public Host addHost(PerunSession sess, Host host, Facility facility) throws InternalErrorException, FacilityNotExistsException, PrivilegeException { Utils.checkPerunSession(sess); Utils.notNull(host, "host"); getFacilitiesManagerBl().checkFacilityExists(sess, facility); if (!AuthzResolver.authorizedInternal(sess, "addHost_Host_Facility_policy", Collections.singletonList(facility))) { throw new PrivilegeException(sess, "addHost"); } List<Facility> facilitiesByHostname = getFacilitiesManagerBl().getFacilitiesByHostName(sess, host.getHostname()); List<Facility> facilitiesByDestination = getFacilitiesManagerBl().getFacilitiesByDestination(sess, host.getHostname()); if(facilitiesByHostname.isEmpty() && facilitiesByDestination.isEmpty()) { return getFacilitiesManagerBl().addHost(sess, host, facility); } if(!facilitiesByHostname.isEmpty()) { boolean hasRight = false; for(Facility facilityByHostname: facilitiesByHostname) { if(AuthzResolver.authorizedInternal(sess, "addHost_Host_Facility_policy", Collections.singletonList(facilityByHostname))) { hasRight = true; break; } } if(hasRight) return getFacilitiesManagerBl().addHost(sess, host, facility); } if(!facilitiesByDestination.isEmpty()) { boolean hasRight = false; for(Facility facilityByDestination: facilitiesByDestination) { if(AuthzResolver.authorizedInternal(sess, "addHost_Host_Facility_policy", Collections.singletonList(facilityByDestination))) { hasRight = true; break; } } if(hasRight) return getFacilitiesManagerBl().addHost(sess, host, facility); } throw new PrivilegeException(sess, "You can't add host " + host + ", because you don't have privileges to use this hostName"); }