Search in sources :

Example 1 with BanNotExistsException

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

the class MembersManagerBlImpl method deleteMember.

public void deleteMember(PerunSession sess, Member member) throws InternalErrorException, MemberAlreadyRemovedException, GroupOperationsException {
    Vo vo = this.getMemberVo(sess, member);
    User user;
    try {
        user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
    } catch (UserNotExistsException e1) {
        throw new ConsistencyErrorException("Removing member who doesn't have corresponding user.", e1);
    }
    List<Facility> allowedFacilities = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
    Map<Facility, List<Attribute>> requiredAttributesBeforeMemberRemove = new HashMap<Facility, List<Attribute>>();
    for (Facility facility : allowedFacilities) {
        // Get actually required attributes, they will be later compared with list of required attributes when the member will be removed from all resources in this VO
        requiredAttributesBeforeMemberRemove.put(facility, getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, facility, user));
    }
    // Remove member from all groups
    List<Group> memberGroups = getPerunBl().getGroupsManagerBl().getMemberDirectGroups(sess, member);
    for (Group group : memberGroups) {
        // Member must be removed from the members group using separate method
        if (group.getName().equals(VosManager.MEMBERS_GROUP))
            continue;
        try {
            getPerunBl().getGroupsManagerBl().removeMember(sess, group, member);
        } catch (NotGroupMemberException e) {
            throw new ConsistencyErrorException("getMemberGroups return group where the member is not member", e);
        } catch (GroupNotExistsException e) {
            throw new ConsistencyErrorException(e);
        }
    }
    // Remove member from the VO members group
    try {
        Group g = getPerunBl().getGroupsManagerBl().getGroupByName(sess, vo, VosManager.MEMBERS_GROUP);
        try {
            getPerunBl().getGroupsManagerBl().removeMemberFromMembersOrAdministratorsGroup(sess, g, member);
        } catch (NotGroupMemberException e) {
            throw new ConsistencyErrorException("Member is not in the \"members\" group." + member + "  " + g, e);
        }
    } catch (GroupNotExistsException e) {
        throw new InternalErrorException(e);
    }
    // Remove member's  attributes (namespaces: member and resource-member)
    try {
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member);
        List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
        for (Resource resource : resources) {
            getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, resource, member);
        }
    } catch (AttributeValueException ex) {
        throw new ConsistencyErrorException("Member is removed from all groups. There are no required attribute for this member. Member's attributes can be removed without problem.", ex);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    // Remove user-facility attributes which are no longer required
    for (Facility facility : allowedFacilities) {
        List<Attribute> requiredAttributes = requiredAttributesBeforeMemberRemove.get(facility);
        //remove currently required attributes from requiredAttributesBeforeMemberRemove
        requiredAttributes.removeAll(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, facility, user));
        //remove attributes which are no longer required
        try {
            getPerunBl().getAttributesManagerBl().removeAttributes(sess, facility, user, requiredAttributes);
        } catch (AttributeValueException | WrongAttributeAssignmentException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
    //Remove all members bans
    List<BanOnResource> bansOnResource = getPerunBl().getResourcesManagerBl().getBansForMember(sess, member.getId());
    for (BanOnResource banOnResource : bansOnResource) {
        try {
            getPerunBl().getResourcesManagerBl().removeBan(sess, banOnResource.getId());
        } catch (BanNotExistsException ex) {
        //it is ok, we just want to remove it anyway
        }
    }
    /* TODO this can be used for future optimization. If the user is not asigned to the facility anymore all user-facility attributes (for this facility) can be safely removed.
			 for (Facility facility: facilitiesBeforeMemberRemove) {
		// Remove user-facility attributes
		try {
		getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility, user);
		log.debug("Removing user-facility attributes for facility {}", facility);
		} catch (AttributeValueException e) {
		throw new ConsistencyErrorException("Member is removed from all resources. There are no required attribute for this member. User-facility attributes can be removed without problem.", e);
		}
			 }
			 */
    // Remove member from the DB
    getMembersManagerImpl().deleteMember(sess, member);
    getPerunBl().getAuditer().log(sess, "{} deleted.", member);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) Vo(cz.metacentrum.perun.core.api.Vo) List(java.util.List) ArrayList(java.util.ArrayList) Facility(cz.metacentrum.perun.core.api.Facility) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Example 2 with BanNotExistsException

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

the class FacilitiesManagerBlImpl method deleteFacility.

public void deleteFacility(PerunSession sess, Facility facility) throws InternalErrorException, RelationExistsException, FacilityAlreadyRemovedException, HostAlreadyRemovedException, GroupAlreadyRemovedException, ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
    if (getFacilitiesManagerImpl().getAssignedResources(sess, facility).size() > 0) {
        throw new RelationExistsException("Facility is still used as a resource");
    }
    //remove hosts
    List<Host> hosts = this.getHosts(sess, facility);
    for (Host host : hosts) {
        this.removeHost(sess, host);
    }
    //remove destinations
    getPerunBl().getServicesManagerBl().removeAllDestinations(sess, facility);
    // remove assigned security teams
    List<SecurityTeam> teams = getAssignedSecurityTeams(sess, facility);
    for (SecurityTeam team : teams) {
        removeSecurityTeam(sess, facility, team);
    }
    // remove assigned facility contacts
    List<ContactGroup> contacts = getFacilityContactGroups(sess, facility);
    if (contacts != null && !contacts.isEmpty()) {
        removeFacilityContacts(sess, contacts);
    }
    // remove associated attributes
    try {
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (WrongReferenceAttributeValueException e) {
        throw new InternalErrorException(e);
    }
    //Remove all facility bans
    List<BanOnFacility> bansOnFacility = this.getBansForFacility(sess, facility.getId());
    for (BanOnFacility banOnFacility : bansOnFacility) {
        try {
            this.removeBan(sess, banOnFacility.getId());
        } catch (BanNotExistsException ex) {
        //it is ok, we just want to remove it anyway
        }
    }
    // delete facility
    getFacilitiesManagerImpl().deleteFacilityOwners(sess, facility);
    getFacilitiesManagerImpl().deleteFacility(sess, facility);
    getPerunBl().getAuditer().log(sess, "Facility deleted {}.", facility);
}
Also used : Host(cz.metacentrum.perun.core.api.Host) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Aggregations

BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)2 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)1 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)1 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Group (cz.metacentrum.perun.core.api.Group)1 Host (cz.metacentrum.perun.core.api.Host)1 Resource (cz.metacentrum.perun.core.api.Resource)1 SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)1 User (cz.metacentrum.perun.core.api.User)1 Vo (cz.metacentrum.perun.core.api.Vo)1 AttributeValueException (cz.metacentrum.perun.core.api.exceptions.AttributeValueException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)1 NotGroupMemberException (cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException)1 ParentGroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException)1