Search in sources :

Example 66 with ExtSource

use of cz.metacentrum.perun.core.api.ExtSource 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 67 with ExtSource

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

the class VosManagerBlImpl method findCandidates.

public List<Candidate> findCandidates(PerunSession sess, Vo vo, String searchString, int maxNumOfResults, List<ExtSource> extSources, boolean filterExistingMembers) {
    List<Candidate> candidates = new ArrayList<>();
    int numOfResults = 0;
    try {
        // Iterate through given extSources
        for (ExtSource source : extSources) {
            try {
                // Info if this is only simple ext source, change behavior if not
                boolean simpleExtSource = true;
                // Get potential subjects from the extSource
                List<Map<String, String>> subjects;
                try {
                    if (source instanceof ExtSourceApi) {
                        // find subjects with all their properties
                        subjects = ((ExtSourceApi) source).findSubjects(searchString, maxNumOfResults);
                        simpleExtSource = false;
                    } else {
                        // find subjects only with logins - they then must be retrieved by login
                        subjects = ((ExtSourceSimpleApi) source).findSubjectsLogins(searchString, maxNumOfResults);
                    }
                } catch (ExtSourceUnsupportedOperationException e1) {
                    log.warn("ExtSource {} doesn't support findSubjects", source.getName());
                    continue;
                } catch (InternalErrorException e) {
                    log.error("Error occurred on ExtSource {},  Exception {}.", source.getName(), e);
                    continue;
                } finally {
                    try {
                        ((ExtSourceSimpleApi) source).close();
                    } catch (ExtSourceUnsupportedOperationException e) {
                    // ExtSource doesn't support that functionality, so silently skip it.
                    } catch (InternalErrorException e) {
                        log.error("Can't close extSource connection.", e);
                    }
                }
                Set<String> uniqueLogins = new HashSet<>();
                for (Map<String, String> s : subjects) {
                    // Check if the user has unique identifier within extSource
                    if ((s.get("login") == null) || (s.get("login") != null && s.get("login").isEmpty())) {
                        log.error("User '{}' cannot be added, because he/she doesn't have a unique identifier (login)", s);
                        // Skip to another user
                        continue;
                    }
                    String extLogin = s.get("login");
                    // check uniqueness of every login in extSource
                    if (uniqueLogins.contains(extLogin)) {
                        throw new InternalErrorException("There are more than 1 login '" + extLogin + "' getting from extSource '" + source + "'");
                    } else {
                        uniqueLogins.add(extLogin);
                    }
                    // Get Candidate
                    Candidate candidate;
                    try {
                        if (simpleExtSource) {
                            // retrieve data about subjects from ext source based on ext. login
                            candidate = new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, source, extLogin));
                        } else {
                            // retrieve data about subjects from subjects we already have locally
                            candidate = new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, s, source, extLogin));
                        }
                    } catch (CandidateNotExistsException e) {
                        throw new ConsistencyErrorException("findSubjects returned that candidate, but getCandidate cannot find him using login " + extLogin, e);
                    } catch (ExtSourceUnsupportedOperationException e) {
                        throw new InternalErrorException("extSource supports findSubjects but not getCandidate???", e);
                    }
                    if (filterExistingMembers) {
                        try {
                            getPerunBl().getMembersManagerBl().getMemberByUserExtSources(sess, vo, candidate.getUserExtSources());
                            // Candidate is already a member of the VO, so do not add him to the list of candidates
                            continue;
                        } catch (MemberNotExistsException e) {
                        // This is OK
                        }
                    }
                    // Add candidate to the list of candidates
                    log.debug("findCandidates: returning candidate: {}", candidate);
                    candidates.add(candidate);
                    numOfResults++;
                    // Stop getting new members if the number of already retrieved members exceeded the maxNumOfResults
                    if (maxNumOfResults > 0 && numOfResults >= maxNumOfResults) {
                        break;
                    }
                }
            } catch (InternalErrorException e) {
                log.error("Failed to get candidates from ExtSource: {}", source);
            } finally {
                if (source instanceof ExtSourceSimpleApi) {
                    try {
                        ((ExtSourceSimpleApi) source).close();
                    } catch (ExtSourceUnsupportedOperationException e) {
                    // silently skip
                    } catch (Exception e) {
                        log.error("Failed to close connection to extsource", e);
                    }
                }
            }
            // Stop walking through next sources if the number of already retrieved members exceeded the maxNumOfResults
            if (maxNumOfResults > 0 && numOfResults >= maxNumOfResults) {
                break;
            }
        }
        log.debug("Returning {} potential members for vo {}", candidates.size(), vo);
        return candidates;
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceApi(cz.metacentrum.perun.core.implApi.ExtSourceApi) 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) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) Map(java.util.Map) HashMap(java.util.HashMap) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) HashSet(java.util.HashSet) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)

Example 68 with ExtSource

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

the class UsersManagerBlImpl method addUserExtSource.

@Override
public UserExtSource addUserExtSource(PerunSession sess, User user, UserExtSource userExtSource) throws UserExtSourceExistsException {
    // Check if the userExtSource already exists
    if (usersManagerImpl.userExtSourceExists(sess, userExtSource)) {
        throw new UserExtSourceExistsException("UserExtSource " + userExtSource + " already exists.");
    }
    // Check if userExtsource is type of IDP (special testing behavior)
    if (userExtSource.getExtSource().getType().equals(ExtSourcesManager.EXTSOURCE_IDP)) {
        // If extSource of this userExtSource is type of IDP, test uniqueness of login in this extSource type for all users
        String login = userExtSource.getLogin();
        List<UserExtSource> userExtSources = getAllUserExtSourcesByTypeAndLogin(sess, ExtSourcesManager.EXTSOURCE_IDP, login);
        if (!userExtSources.stream().allMatch(ues -> ues.getUserId() == user.getId())) {
            if (userExtSources.stream().allMatch(ues -> ues.getUserId() == userExtSources.get(0).getUserId())) {
                // Duplicate identity belongs to different user - block it!!
                throw new InternalErrorException("ExtLogin: " + login + " is already used for extSourceType: " + ExtSourcesManager.EXTSOURCE_IDP);
            } else {
                // more users cannot have the same login
                throw new ConsistencyErrorException("There are " + userExtSources.size() + " extLogins: " + login + " for  extSourceType: " + ExtSourcesManager.EXTSOURCE_IDP);
            }
        }
    }
    userExtSource = getUsersManagerImpl().addUserExtSource(sess, user, userExtSource);
    getPerunBl().getAuditer().log(sess, new UserExtSourceAddedToUser(userExtSource, user));
    return userExtSource;
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserVirtualAttributesModuleImplApi) Pair(cz.metacentrum.perun.core.api.Pair) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) Vo(cz.metacentrum.perun.core.api.Vo) SpecificUserType(cz.metacentrum.perun.core.api.SpecificUserType) PasswordOperationTimeoutRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Map(java.util.Map) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) OwnershipRemovedForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser) BeansUtils(cz.metacentrum.perun.core.api.BeansUtils) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceAlreadyRemovedException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Set(java.util.Set) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) User(cz.metacentrum.perun.core.api.User) OwnershipEnabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser) UserAddedToOwnersOfSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser) PasswordDoesntMatchRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDoesntMatchRuntimeException) UsersPageQuery(cz.metacentrum.perun.core.api.UsersPageQuery) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) LoginNotExistsRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException) UserExtSourceUpdated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceUpdated) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) SpecificUserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserAlreadyRemovedException) AlreadyReservedLoginException(cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException) UserUpdated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserUpdated) SpecificUserOwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserOwnerAlreadyRemovedException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) RichUser(cz.metacentrum.perun.core.api.RichUser) PasswordChangeFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordChangeFailedException) Member(cz.metacentrum.perun.core.api.Member) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) PasswordResetLinkExpiredException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkExpiredException) Utils(cz.metacentrum.perun.core.impl.Utils) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) Candidate(cz.metacentrum.perun.core.api.Candidate) AuthzResolver(cz.metacentrum.perun.core.api.AuthzResolver) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) LoggerFactory(org.slf4j.LoggerFactory) PasswordChangeFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordChangeFailedRuntimeException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) PasswordStrengthFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordStrengthFailedRuntimeException) OwnershipDisabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Resource(cz.metacentrum.perun.core.api.Resource) UserDeleted(cz.metacentrum.perun.audit.events.UserManagerEvents.UserDeleted) PerunSession(cz.metacentrum.perun.core.api.PerunSession) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Paginated(cz.metacentrum.perun.core.api.Paginated) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) Group(cz.metacentrum.perun.core.api.Group) UsersManagerImplApi(cz.metacentrum.perun.core.implApi.UsersManagerImplApi) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) HashSet(java.util.HashSet) UserCreated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserCreated) UserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserAlreadyRemovedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) RichResource(cz.metacentrum.perun.core.api.RichResource) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) RelationNotExistsException(cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException) ActionType(cz.metacentrum.perun.core.api.ActionType) PasswordDoesntMatchException(cz.metacentrum.perun.core.api.exceptions.PasswordDoesntMatchException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) Host(cz.metacentrum.perun.core.api.Host) PasswordResetLinkNotValidException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkNotValidException) AllUserExtSourcesDeletedForUser(cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) PasswordDeletionFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) AnonymizationNotSupportedException(cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 69 with ExtSource

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

the class UsersManagerBlImpl method getUserByExtSourceNameAndExtLogin.

@Override
public User getUserByExtSourceNameAndExtLogin(PerunSession sess, String extSourceName, String extLogin) throws ExtSourceNotExistsException, UserExtSourceNotExistsException, UserNotExistsException {
    ExtSource extSource = perunBl.getExtSourcesManagerBl().getExtSourceByName(sess, extSourceName);
    UserExtSource userExtSource = this.getUserExtSourceByExtLogin(sess, extSource, extLogin);
    return this.getUserByUserExtSource(sess, userExtSource);
}
Also used : RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 70 with ExtSource

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

the class VosManagerBlImpl method findCandidates.

public List<Candidate> findCandidates(PerunSession sess, Group group, String searchString) throws InternalErrorException {
    List<Candidate> candidates = new ArrayList<>();
    try {
        // Iterate through all registered extSources in the group
        for (ExtSource source : getPerunBl().getExtSourcesManagerBl().getGroupExtSources(sess, group)) {
            // Info if this is only simple ext source, change behavior if not
            boolean simpleExtSource = true;
            // Get potential subjects from the extSource
            List<Map<String, String>> subjects;
            try {
                if (source instanceof ExtSourceApi) {
                    // find subjects with all their properties
                    subjects = ((ExtSourceApi) source).findSubjects(searchString);
                    simpleExtSource = false;
                } else {
                    // find subjects only with logins - they then must be retrieved by login
                    subjects = ((ExtSourceSimpleApi) source).findSubjectsLogins(searchString);
                }
            } catch (ExtSourceUnsupportedOperationException e1) {
                log.warn("ExtSource {} doesn't support findSubjects", source.getName());
                continue;
            } catch (InternalErrorException e) {
                log.error("Error occurred on ExtSource {},  Exception {}.", source.getName(), e);
                continue;
            } finally {
                try {
                    ((ExtSourceSimpleApi) source).close();
                } catch (ExtSourceUnsupportedOperationException e) {
                // ExtSource doesn't support that functionality, so silently skip it.
                } catch (InternalErrorException e) {
                    log.error("Can't close extSource connection. Cause: {}", e);
                }
            }
            Set<String> uniqueLogins = new HashSet<>();
            for (Map<String, String> s : subjects) {
                // Check if the user has unique identifier within extSource
                if ((s.get("login") == null) || (s.get("login") != null && ((String) s.get("login")).isEmpty())) {
                    log.error("User '{}' cannot be added, because he/she doesn't have a unique identifier (login)", s);
                    // Skip to another user
                    continue;
                }
                String extLogin = (String) s.get("login");
                // check uniqueness of every login in extSource
                if (uniqueLogins.contains(extLogin)) {
                    throw new InternalErrorException("There are more than 1 login '" + extLogin + "' getting from extSource '" + source + "'");
                } else {
                    uniqueLogins.add(extLogin);
                }
                // Get Candidate
                Candidate candidate;
                try {
                    if (simpleExtSource) {
                        // retrieve data about subjects from ext source based on ext. login
                        candidate = getPerunBl().getExtSourcesManagerBl().getCandidate(sess, source, extLogin);
                    } else {
                        // retrieve data about subjects from subjects we already have locally
                        candidate = getPerunBl().getExtSourcesManagerBl().getCandidate(sess, s, source, extLogin);
                    }
                } catch (ExtSourceNotExistsException e) {
                    throw new ConsistencyErrorException("Getting candidate from non-existing extSource " + source, e);
                } catch (CandidateNotExistsException e) {
                    throw new ConsistencyErrorException("findSubjects returned that candidate, but getCandidate cannot find him using login " + extLogin, e);
                } catch (ExtSourceUnsupportedOperationException e) {
                    throw new InternalErrorException("extSource supports findSubjects but not getCandidate???", e);
                }
                try {
                    Vo vo = getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
                    getPerunBl().getMembersManagerBl().getMemberByUserExtSources(sess, vo, candidate.getUserExtSources());
                    // Candidate is already a member of the VO, so do not add him to the list of candidates
                    continue;
                } catch (VoNotExistsException e) {
                    throw new InternalErrorException(e);
                } catch (MemberNotExistsException e) {
                // This is OK
                }
                // Add candidate to the list of candidates
                log.debug("findCandidates: returning candidate: {}", candidate);
                candidates.add(candidate);
            }
        }
        log.debug("Returning {} potential members for group {}", candidates.size(), group);
        return candidates;
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceApi(cz.metacentrum.perun.core.implApi.ExtSourceApi) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) Vo(cz.metacentrum.perun.core.api.Vo) ExtSource(cz.metacentrum.perun.core.api.ExtSource) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) Map(java.util.Map) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) HashSet(java.util.HashSet) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)

Aggregations

ExtSource (cz.metacentrum.perun.core.api.ExtSource)135 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)110 Test (org.junit.Test)57 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)52 Attribute (cz.metacentrum.perun.core.api.Attribute)40 User (cz.metacentrum.perun.core.api.User)40 Vo (cz.metacentrum.perun.core.api.Vo)38 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)35 Member (cz.metacentrum.perun.core.api.Member)31 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)30 UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)28 Candidate (cz.metacentrum.perun.core.api.Candidate)27 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)27 ArrayList (java.util.ArrayList)25 Group (cz.metacentrum.perun.core.api.Group)23 LinkedHashMap (java.util.LinkedHashMap)20 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)19 RichMember (cz.metacentrum.perun.core.api.RichMember)17 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)17 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)16