use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class FacilitiesManagerEntry method setBan.
@Override
public BanOnFacility setBan(PerunSession sess, BanOnFacility banOnFacility) throws InternalErrorException, PrivilegeException, BanAlreadyExistsException, FacilityNotExistsException, UserNotExistsException {
Utils.checkPerunSession(sess);
Utils.notNull(banOnFacility, "banOnFacility");
User user = getPerunBl().getUsersManagerBl().getUserById(sess, banOnFacility.getUserId());
Facility facility = this.getFacilitiesManagerBl().getFacilityById(sess, banOnFacility.getFacilityId());
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(sess, "setBan");
}
return getFacilitiesManagerBl().setBan(sess, banOnFacility);
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class ServicesManagerEntry method addDestination.
public Destination addDestination(PerunSession perunSession, List<Service> services, Facility facility, Destination destination) throws PrivilegeException, InternalErrorException, ServiceNotExistsException, FacilityNotExistsException, DestinationAlreadyAssignedException, WrongPatternException {
Utils.checkPerunSession(perunSession);
Utils.notNull(services, "services");
Utils.checkDestinationType(destination);
getPerunBl().getFacilitiesManagerBl().checkFacilityExists(perunSession, facility);
// Authorization
if (!AuthzResolver.isAuthorized(perunSession, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(perunSession, "addDestination");
}
//prepare lists of facilities
List<Facility> facilitiesByHostname = new ArrayList<Facility>();
List<Facility> facilitiesByDestination = new ArrayList<Facility>();
if (destination.getType().equals(Destination.DESTINATIONHOSTTYPE) || destination.getType().equals(Destination.DESTINATIONUSERHOSTTYPE) || destination.getType().equals(Destination.DESTINATIONUSERHOSTPORTTYPE)) {
facilitiesByHostname = getPerunBl().getFacilitiesManagerBl().getFacilitiesByHostName(perunSession, destination.getHostNameFromDestination());
if (facilitiesByHostname.isEmpty())
facilitiesByDestination = getPerunBl().getFacilitiesManagerBl().getFacilitiesByDestination(perunSession, destination.getHostNameFromDestination());
if (!facilitiesByHostname.isEmpty()) {
boolean hasRight = false;
for (Facility facilityByHostname : facilitiesByHostname) {
if (AuthzResolver.isAuthorized(perunSession, Role.FACILITYADMIN, facilityByHostname)) {
hasRight = true;
break;
}
}
if (!hasRight)
throw new PrivilegeException("You have no right to add this destination.");
}
if (!facilitiesByDestination.isEmpty()) {
boolean hasRight = false;
for (Facility facilityByDestination : facilitiesByDestination) {
if (AuthzResolver.isAuthorized(perunSession, Role.FACILITYADMIN, facilityByDestination)) {
hasRight = true;
break;
}
}
if (!hasRight)
throw new PrivilegeException("You have no right to add this destination.");
}
}
for (Service s : services) {
getServicesManagerBl().checkServiceExists(perunSession, s);
}
Utils.notNull(destination, "destination");
Utils.notNull(destination.getDestination(), "destination.destination");
Utils.notNull(destination.getType(), "destination.type");
return getServicesManagerBl().addDestination(perunSession, services, facility, destination);
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class FacilitiesManagerEntry method removeHost.
public void removeHost(PerunSession sess, Host host) throws InternalErrorException, HostNotExistsException, PrivilegeException, HostAlreadyRemovedException {
Utils.checkPerunSession(sess);
getFacilitiesManagerBl().checkHostExists(sess, host);
Facility facility = getFacilitiesManagerBl().getFacilityForHost(sess, host);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(sess, "removeHost");
}
getFacilitiesManagerBl().removeHost(sess, host);
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class FacilitiesManagerEntry method getBanById.
@Override
public BanOnFacility getBanById(PerunSession sess, int banId) throws InternalErrorException, BanNotExistsException, PrivilegeException {
Utils.checkPerunSession(sess);
BanOnFacility ban = getFacilitiesManagerBl().getBanById(sess, banId);
Facility facility = new Facility();
facility.setId(ban.getId());
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(sess, "getBanById");
}
return ban;
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class FacilitiesManagerEntry method addHosts.
public List<Host> addHosts(PerunSession sess, Facility facility, List<String> hosts) throws FacilityNotExistsException, InternalErrorException, PrivilegeException, HostExistsException, WrongPatternException {
Utils.checkPerunSession(sess);
getFacilitiesManagerBl().checkFacilityExists(sess, facility);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(sess, "addHosts");
}
Utils.notNull(hosts, "hosts");
List<String> allHostnames = new ArrayList<>();
for (String host : hosts) {
allHostnames.addAll(Utils.generateStringsByPattern(host));
}
for (String hostname : allHostnames) {
List<Facility> facilitiesByHostname = getFacilitiesManagerBl().getFacilitiesByHostName(sess, hostname);
List<Facility> facilitiesByDestination = getFacilitiesManagerBl().getFacilitiesByDestination(sess, hostname);
if (facilitiesByHostname.isEmpty() && facilitiesByDestination.isEmpty()) {
continue;
}
if (!facilitiesByHostname.isEmpty()) {
boolean hasRight = false;
for (Facility facilityByHostname : facilitiesByHostname) {
if (AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facilityByHostname)) {
hasRight = true;
break;
}
}
if (hasRight)
continue;
}
if (!facilitiesByDestination.isEmpty()) {
boolean hasRight = false;
for (Facility facilityByDestination : facilitiesByDestination) {
if (AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facilityByDestination)) {
hasRight = true;
break;
}
}
if (hasRight)
continue;
}
throw new PrivilegeException(sess, "You can't add host " + hostname + ", because you don't have privileges to use this hostName");
}
return getFacilitiesManagerBl().addHosts(sess, facility, hosts);
}
Aggregations