Search in sources :

Example 1 with RelationExistsException

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

the class MembersManagerBlImpl method createSpecificMember.

public Member createSpecificMember(PerunSession sess, Vo vo, Candidate candidate, List<User> specificUserOwners, SpecificUserType specificUserType, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException, GroupOperationsException {
    if (specificUserType.equals(SpecificUserType.SERVICE))
        candidate.setFirstName("(Service)");
    //Set organization only if user in sessione exists (in tests there is no user in session)
    if (sess.getPerunPrincipal().getUser() != null) {
        String userOrganization = AttributesManager.NS_USER_ATTR_DEF + ":organization";
        String memberOrganization = AttributesManager.NS_MEMBER_ATTR_DEF + ":organization";
        Map<String, String> candidateAttributes = new HashMap<>();
        if (candidate.getAttributes() != null)
            candidateAttributes.putAll(candidate.getAttributes());
        if (candidateAttributes.get(memberOrganization) == null) {
            Attribute actorUserOrganization;
            String actorUserOrganizationValue;
            try {
                actorUserOrganization = perunBl.getAttributesManagerBl().getAttribute(sess, sess.getPerunPrincipal().getUser(), userOrganization);
                actorUserOrganizationValue = (String) actorUserOrganization.getValue();
            } catch (WrongAttributeAssignmentException | AttributeNotExistsException ex) {
                throw new InternalErrorException(ex);
            }
            if (actorUserOrganizationValue != null) {
                candidateAttributes.put(memberOrganization, actorUserOrganizationValue);
                candidate.setAttributes(candidateAttributes);
            }
        }
    }
    //create member for service user from candidate
    Member member = createMember(sess, vo, specificUserType, candidate, groups, null);
    //set specific user owners or sponsors
    User specificUser = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    for (User u : specificUserOwners) {
        try {
            getPerunBl().getUsersManagerBl().addSpecificUserOwner(sess, u, specificUser);
        } catch (RelationExistsException ex) {
            throw new InternalErrorException(ex);
        }
    }
    return member;
}
Also used : User(cz.metacentrum.perun.core.api.User) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 2 with RelationExistsException

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

the class SecurityTeamsManagerBlImpl method deleteSecurityTeam.

@Override
public void deleteSecurityTeam(PerunSession sess, SecurityTeam securityTeam, boolean forceDelete) throws SecurityTeamNotExistsException, RelationExistsException {
    // remove admins of this securityTeam
    List<Group> adminGroups = getSecurityTeamsManagerImpl().getAdminGroups(sess, securityTeam);
    for (Group adminGroup : adminGroups) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminGroup, securityTeam, Role.SECURITYADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("When trying to unsetRole SecurityAdmin for group {} in the securityTeam {} the exception was thrown {}", adminGroup, securityTeam, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<User> adminUsers = getSecurityTeamsManagerImpl().getAdmins(sess, securityTeam);
    for (User adminUser : adminUsers) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminUser, securityTeam, Role.SECURITYADMIN);
        } catch (UserNotAdminException e) {
            log.warn("When trying to unsetRole SecurityAdmin for user {} in the securityTeam {} the exception was thrown {}", adminUser, securityTeam, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    // remove all users from blacklist, which were blacklisted by this security team.
    List<User> blacklist = getSecurityTeamsManagerImpl().getBlacklist(sess, Collections.singletonList(securityTeam));
    if (!blacklist.isEmpty() && !forceDelete) {
        throw new RelationExistsException("SecurityTeam has blacklisted users.");
    }
    for (User blacklistedUser : blacklist) {
        // calling BL will make auditer message about user to appear.
        getPerunBl().getSecurityTeamsManagerBl().removeUserFromBlacklist(sess, securityTeam, blacklistedUser);
    }
    // remove security team from all facilities
    List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getAssignedFacilities(sess, securityTeam);
    if (!facilities.isEmpty() && !forceDelete) {
        throw new RelationExistsException("SecurityTeam is assigned to some facilities.");
    }
    for (Facility facility : facilities) {
        // calling BL will make auditer message about facility to appear.
        getPerunBl().getFacilitiesManagerBl().removeSecurityTeam(sess, facility, securityTeam);
    }
    getSecurityTeamsManagerImpl().deleteSecurityTeam(sess, securityTeam);
    getPerunBl().getAuditer().log(sess, new SecurityTeamDeleted(securityTeam));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) User(cz.metacentrum.perun.core.api.User) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) SecurityTeamDeleted(cz.metacentrum.perun.audit.events.SecurityTeamsManagerEvents.SecurityTeamDeleted) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Facility(cz.metacentrum.perun.core.api.Facility)

Example 3 with RelationExistsException

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

the class OwnersManagerBlImpl method deleteOwner.

@Override
public void deleteOwner(PerunSession sess, Owner owner, boolean forceDelete) throws RelationExistsException, OwnerAlreadyRemovedException {
    // Check if the owner is assigned to some facility
    List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getOwnerFacilities(sess, owner);
    if (facilities != null && facilities.size() > 0) {
        if (!forceDelete) {
            throw new RelationExistsException("Owner own " + facilities.size() + " facilities");
        } else {
            for (Facility facility : facilities) {
                try {
                    getPerunBl().getFacilitiesManagerBl().removeOwner(sess, facility, owner);
                } catch (OwnerAlreadyRemovedException e) {
                    throw new InternalErrorException(e);
                }
            }
        }
    }
    getOwnersManagerImpl().deleteOwner(sess, owner);
    getPerunBl().getAuditer().log(sess, new OwnerDeleted(owner));
}
Also used : RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) OwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.OwnerAlreadyRemovedException) OwnerDeleted(cz.metacentrum.perun.audit.events.OwnersManagerEvents.OwnerDeleted)

Example 4 with RelationExistsException

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

the class VosManagerBlImpl method deleteVo.

@Override
public void deleteVo(PerunSession sess, Vo vo, boolean forceDelete) {
    log.debug("Deleting vo {}", vo);
    try {
        // remove admins of this vo
        List<Group> adminGroups = getVosManagerImpl().getAdminGroups(sess, vo);
        for (Group adminGroup : adminGroups) {
            try {
                AuthzResolverBlImpl.unsetRole(sess, adminGroup, vo, Role.VOADMIN);
            } catch (GroupNotAdminException e) {
                log.warn("When trying to unsetRole VoAdmin for group {} in the vo {} the exception was thrown {}", adminGroup, vo, e);
            // skip and log as warning
            }
        }
        List<User> adminUsers = getVosManagerImpl().getAdmins(sess, vo);
        for (User adminUser : adminUsers) {
            try {
                AuthzResolverBlImpl.unsetRole(sess, adminUser, vo, Role.VOADMIN);
            } catch (UserNotAdminException e) {
                log.warn("When trying to unsetRole VoAdmin for user {} in the vo {} the exception was thrown {}", adminUser, vo, e);
            // skip and log as warning
            }
        }
        List<Member> members = getPerunBl().getMembersManagerBl().getMembers(sess, vo);
        log.debug("Deleting vo {} members", vo);
        // Check if there are some members left
        if (members != null && members.size() > 0) {
            if (forceDelete) {
                getPerunBl().getMembersManagerBl().deleteAllMembers(sess, vo);
            } else
                throw new RelationExistsException("Vo vo=" + vo + " contains members");
        }
        log.debug("Removing vo {} resources and theirs attributes", vo);
        // Delete resources
        List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
        if ((resources.size() == 0) || forceDelete) {
            for (Resource resource : resources) {
                getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, resource);
                // Remove binding between service and resource
                List<Service> services = getPerunBl().getResourcesManagerBl().getAssignedServices(sess, resource);
                for (Service service : services) {
                    getPerunBl().getResourcesManagerBl().removeService(sess, resource, service);
                }
                getPerunBl().getResourcesManagerBl().deleteResource(sess, resource);
            }
        } else {
            throw new RelationExistsException("Vo vo=" + vo + " contains resources");
        }
        log.debug("Removing vo {} groups", vo);
        // Delete all groups
        List<Group> groups = getPerunBl().getGroupsManagerBl().getGroups(sess, vo);
        if (groups.size() != 1) {
            if (groups.size() < 1)
                throw new ConsistencyErrorException("'members' group is missing");
            if (forceDelete) {
                getPerunBl().getGroupsManagerBl().deleteAllGroups(sess, vo);
            } else {
                throw new RelationExistsException("Vo vo=" + vo + " contains groups");
            }
        }
        // Finally delete binding between Vo and external source
        List<ExtSource> ess = getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, vo);
        log.debug("Deleting {} external sources binded to the vo {}", ess.size(), vo);
        for (ExtSource es : ess) {
            getPerunBl().getExtSourcesManagerBl().removeExtSource(sess, vo, es);
        }
        // Delete members group
        log.debug("Removing an administrators' group from the vo {}", vo);
        getPerunBl().getGroupsManagerBl().deleteMembersGroup(sess, vo);
        // delete all VO reserved logins from KDC
        List<Integer> list = getVosManagerImpl().getVoApplicationIds(sess, vo);
        for (Integer appId : list) {
            // for each application
            for (Pair<String, String> login : getVosManagerImpl().getApplicationReservedLogins(appId)) {
                // for all reserved logins - delete them in ext. system (e.g. KDC)
                try {
                    // !!! left = namespace / right = login !!!
                    getPerunBl().getUsersManagerBl().deletePassword(sess, login.getRight(), login.getLeft());
                } catch (LoginNotExistsException ex) {
                    log.error("Login: {} not exists in namespace {} while deleting passwords", login.getRight(), login.getLeft());
                }
            }
        }
        // delete all VO reserved logins from DB
        getVosManagerImpl().deleteVoReservedLogins(sess, vo);
        // VO applications, submitted data and app_form are deleted on cascade with "deleteVo()"
        // Delete VO attributes
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, vo);
        // Delete all Vo tags (for resources in Vo)
        getPerunBl().getResourcesManagerBl().deleteAllResourcesTagsForVo(sess, vo);
    } catch (Exception ex) {
        throw new InternalErrorException(ex);
    }
    // Finally delete the VO
    Vo deletedVo = getVosManagerImpl().deleteVo(sess, vo);
    getPerunBl().getAuditer().log(sess, new VoDeleted(deletedVo));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) VoDeleted(cz.metacentrum.perun.audit.events.VoManagerEvents.VoDeleted) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) Vo(cz.metacentrum.perun.core.api.Vo) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) Member(cz.metacentrum.perun.core.api.Member) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) Service(cz.metacentrum.perun.core.api.Service) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) GroupExistsException(cz.metacentrum.perun.core.api.exceptions.GroupExistsException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException) VoExistsException(cz.metacentrum.perun.core.api.exceptions.VoExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) MemberNotSponsoredException(cz.metacentrum.perun.core.api.exceptions.MemberNotSponsoredException) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 5 with RelationExistsException

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

the class ServicesManagerBlImpl method deleteDestination.

@Override
public void deleteDestination(PerunSession sess, Destination destination) throws DestinationAlreadyRemovedException, RelationExistsException {
    List<Service> services = getServicesManagerImpl().getServicesFromDestination(destination.getId());
    if (!services.isEmpty()) {
        throw new RelationExistsException("Destination is used by some services and facilities.");
    }
    // remove task results of destination
    List<TaskResult> taskResults = getPerunBl().getTasksManagerBl().getTaskResultsByDestinations(sess, Collections.singletonList(destination.getDestination()));
    for (TaskResult taskResult : taskResults) {
        getPerunBl().getTasksManagerBl().deleteTaskResultById(sess, taskResult.getId());
    }
    // remove all service denials on destination
    this.unblockAllServicesOnDestination(sess, destination.getId());
    getServicesManagerImpl().deleteDestination(sess, destination);
}
Also used : RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) RequiredAttributeRemovedFromService(cz.metacentrum.perun.audit.events.ServicesManagerEvents.RequiredAttributeRemovedFromService) DestinationRemovedFromService(cz.metacentrum.perun.audit.events.ServicesManagerEvents.DestinationRemovedFromService) PropagationPlannedOnFacilityAndService(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.PropagationPlannedOnFacilityAndService) PropagationPlannedOnService(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.PropagationPlannedOnService) RequiredAttributesRemovedFromService(cz.metacentrum.perun.audit.events.ServicesManagerEvents.RequiredAttributesRemovedFromService) DestinationsRemovedFromService(cz.metacentrum.perun.audit.events.ServicesManagerEvents.DestinationsRemovedFromService) ForcePropagationOnService(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.ForcePropagationOnService) Service(cz.metacentrum.perun.core.api.Service) AttributesAddedAsRequiredToService(cz.metacentrum.perun.audit.events.ServicesManagerEvents.AttributesAddedAsRequiredToService) ForcePropagationOnFacilityAndService(cz.metacentrum.perun.audit.events.GeneralServiceManagerEvents.ForcePropagationOnFacilityAndService) AllRequiredAttributesRemovedFromService(cz.metacentrum.perun.audit.events.ServicesManagerEvents.AllRequiredAttributesRemovedFromService) AttributeAddedAsRequiredToService(cz.metacentrum.perun.audit.events.ServicesManagerEvents.AttributeAddedAsRequiredToService) TaskResult(cz.metacentrum.perun.taskslib.model.TaskResult)

Aggregations

RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)18 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)12 User (cz.metacentrum.perun.core.api.User)8 RichUser (cz.metacentrum.perun.core.api.RichUser)6 Group (cz.metacentrum.perun.core.api.Group)5 Member (cz.metacentrum.perun.core.api.Member)5 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5 Facility (cz.metacentrum.perun.core.api.Facility)4 Resource (cz.metacentrum.perun.core.api.Resource)4 GroupNotAdminException (cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException)4 RoleCannotBeManagedException (cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException)4 UserNotAdminException (cz.metacentrum.perun.core.api.exceptions.UserNotAdminException)4 AllUserExtSourcesDeletedForUser (cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser)3 Attribute (cz.metacentrum.perun.core.api.Attribute)3 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)3 RichGroup (cz.metacentrum.perun.core.api.RichGroup)3 RichMember (cz.metacentrum.perun.core.api.RichMember)3 SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)3 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)3