Search in sources :

Example 46 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException 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);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) Facility(cz.metacentrum.perun.core.api.Facility)

Example 47 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException 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);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) RichFacility(cz.metacentrum.perun.core.api.RichFacility)

Example 48 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException 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;
}
Also used : BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) RichFacility(cz.metacentrum.perun.core.api.RichFacility)

Example 49 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException 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);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) ArrayList(java.util.ArrayList) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) RichFacility(cz.metacentrum.perun.core.api.RichFacility)

Example 50 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.

the class MembersManagerEntry method getRichMemberById.

public RichMember getRichMemberById(PerunSession sess, int id) throws InternalErrorException, PrivilegeException, MemberNotExistsException {
    Utils.checkPerunSession(sess);
    Member member = getPerunBl().getMembersManagerBl().getMemberById(sess, id);
    Vo vo = getPerunBl().getMembersManagerBl().getMemberVo(sess, member);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, vo) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.SELF, member)) {
        throw new PrivilegeException(sess, "getRichMemberById");
    }
    return getPerunBl().getMembersManagerBl().getRichMember(sess, member);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member) RichMember(cz.metacentrum.perun.core.api.RichMember)

Aggregations

PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)66 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)22 Facility (cz.metacentrum.perun.core.api.Facility)18 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)13 Group (cz.metacentrum.perun.core.api.Group)13 RichFacility (cz.metacentrum.perun.core.api.RichFacility)13 Vo (cz.metacentrum.perun.core.api.Vo)8 RichGroup (cz.metacentrum.perun.core.api.RichGroup)7 ArrayList (java.util.ArrayList)7 User (cz.metacentrum.perun.core.api.User)6 Service (cz.metacentrum.perun.core.api.Service)5 FacilityNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException)5 ServiceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException)5 Member (cz.metacentrum.perun.core.api.Member)4 RichMember (cz.metacentrum.perun.core.api.RichMember)4 IllegalArgumentException (cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)4 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)4 Task (cz.metacentrum.perun.taskslib.model.Task)4 RichUser (cz.metacentrum.perun.core.api.RichUser)3 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)3