Search in sources :

Example 6 with CandidateGroup

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

the class GroupsManagerBlImpl method addMissingGroupsWhileSynchronization.

/**
 * Add missing groups under base group in Perun
 *
 * If some problem occurs, add candidateGroup to skippedGroups and skip it.
 *
 * Method is used by group structure synchronization.
 *
 * @param sess
 * @param baseGroup under which we will be synchronizing groups
 * @param candidateGroupsToAdd list of new groups (candidateGroups)
 * @param loginAttributeDefinition attribute definition for login of group
 * @param skippedGroups groups to be skipped because of any expected problem
 *
 * @throws InternalErrorException if some internal error occurs
 */
private void addMissingGroupsWhileSynchronization(PerunSession sess, Group baseGroup, List<CandidateGroup> candidateGroupsToAdd, AttributeDefinition loginAttributeDefinition, List<String> skippedGroups, List<String> mergeAttributes) {
    Map<CandidateGroup, Group> groupsToUpdate = new HashMap<>();
    // create all groups under base group first
    for (CandidateGroup candidateGroup : candidateGroupsToAdd) {
        try {
            // create group
            Group createdGroup = createGroup(sess, baseGroup, candidateGroup.asGroup());
            groupsToUpdate.put(candidateGroup, createdGroup);
            log.info("Group structure synchronization under base group {}: New Group id {} created during synchronization.", baseGroup, createdGroup.getId());
            // set login for group
            String login = candidateGroup.getLogin();
            if (login == null)
                throw new InternalErrorException("Login of candidate group " + candidateGroup + " can't be null!");
            Attribute loginAttribute = new Attribute(loginAttributeDefinition);
            loginAttribute.setValue(login);
            getPerunBl().getAttributesManagerBl().setAttribute(sess, createdGroup, loginAttribute);
        } catch (GroupExistsException e) {
            log.warn("Group {} was added to group structure {} before adding process. Skip this group.", candidateGroup, baseGroup);
            skippedGroups.add("GroupEntry:[" + candidateGroup + "] was skipped because it was added to group structure before adding process: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (GroupRelationNotAllowed e) {
            log.warn("Can't create group from candidate group {} due to group relation not allowed exception {}.", candidateGroup, e);
            skippedGroups.add("GroupEntry:[" + candidateGroup + "] was skipped because group relation was not allowed: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (GroupRelationAlreadyExists e) {
            log.warn("Can't create group from candidate group {} due to group relation already exists exception {}.", candidateGroup, e);
            skippedGroups.add("GroupEntry:[" + candidateGroup + "] was skipped because group relation already exists: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (WrongAttributeAssignmentException ex) {
            // this means wrong setting of login attribute
            throw new InternalErrorException(ex);
        } catch (WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException("Group login can't be set because of wrong value!", ex);
        }
    }
    // update newly added groups cause the hierarchy could be incorrect
    // no need to send list of removed parent groups here, because it is no need to resolve it for new groups at all
    updateExistingGroupsWhileSynchronization(sess, baseGroup, groupsToUpdate, Collections.emptyList(), loginAttributeDefinition, skippedGroups, mergeAttributes);
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) GroupRelationNotAllowed(cz.metacentrum.perun.core.api.exceptions.GroupRelationNotAllowed) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) GroupExistsException(cz.metacentrum.perun.core.api.exceptions.GroupExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) GroupRelationAlreadyExists(cz.metacentrum.perun.core.api.exceptions.GroupRelationAlreadyExists)

Example 7 with CandidateGroup

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

the class ExtSourcesManagerBlImpl method generateCandidateGroup.

@Override
public CandidateGroup generateCandidateGroup(PerunSession perunSession, Map<String, String> groupSubjectData, ExtSource source, String loginPrefix) {
    if (groupSubjectData == null)
        throw new InternalErrorException("Group subject data cannot be null.");
    if (groupSubjectData.isEmpty())
        throw new InternalErrorException("Group subject data cannot be empty, at least group name has to exists.");
    if (source == null)
        throw new InternalErrorException("ExtSource cannot be null while generating CandidateGroup");
    CandidateGroup candidateGroup = new CandidateGroup();
    candidateGroup.setExtSource(source);
    candidateGroup.asGroup().setName(groupSubjectData.get(GroupsManagerBlImpl.GROUP_NAME));
    candidateGroup.setLogin(loginPrefix + groupSubjectData.get(GroupsManagerBlImpl.GROUP_LOGIN));
    if (candidateGroup.getLogin() == null || candidateGroup.getLogin().isEmpty()) {
        throw new InternalErrorException("Group subject data has to contain valid group login!");
    }
    // Check if the group name is not null and if it is in valid format.
    if (candidateGroup.asGroup().getName() != null) {
        try {
            Utils.validateGroupName(candidateGroup.asGroup().getName());
        } catch (IllegalArgumentException e) {
            throw new InternalErrorException("Group subject data has to contain valid group name!", e);
        }
    } else {
        throw new InternalErrorException("group name cannot be null in Group subject data!");
    }
    if (groupSubjectData.get(GroupsManagerBlImpl.PARENT_GROUP_LOGIN) != null) {
        candidateGroup.setParentGroupLogin(loginPrefix + groupSubjectData.get(GroupsManagerBlImpl.PARENT_GROUP_LOGIN));
    }
    candidateGroup.asGroup().setDescription(groupSubjectData.get(GroupsManagerBlImpl.GROUP_DESCRIPTION));
    groupSubjectData.entrySet().stream().filter(entry -> !GROUP_SYNC_DEFAULT_DATA.contains(entry.getKey())).forEach(entry -> candidateGroup.addAdditionalAttribute(entry.getKey(), entry.getValue()));
    return candidateGroup;
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) ExtSourceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotAssignedException) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) Vo(cz.metacentrum.perun.core.api.Vo) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ExtSourceAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyAssignedException) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) ExtSourceAddedToGroup(cz.metacentrum.perun.audit.events.ExtSourcesManagerEvents.ExtSourceAddedToGroup) ExtSource(cz.metacentrum.perun.core.api.ExtSource) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) ExtSourcesManagerBl(cz.metacentrum.perun.core.bl.ExtSourcesManagerBl) Matcher(java.util.regex.Matcher) Map(java.util.Map) CandidateSync(cz.metacentrum.perun.core.api.CandidateSync) SubjectNotExistsException(cz.metacentrum.perun.core.api.exceptions.SubjectNotExistsException) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) ExtSourceRemovedFromGroup(cz.metacentrum.perun.audit.events.ExtSourcesManagerEvents.ExtSourceRemovedFromGroup) Logger(org.slf4j.Logger) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceAddedToVo(cz.metacentrum.perun.audit.events.ExtSourcesManagerEvents.ExtSourceAddedToVo) ExtSourceCreated(cz.metacentrum.perun.audit.events.ExtSourcesManagerEvents.ExtSourceCreated) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) ExtSourceRemovedFromVo(cz.metacentrum.perun.audit.events.ExtSourcesManagerEvents.ExtSourceRemovedFromVo) User(cz.metacentrum.perun.core.api.User) ExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) List(java.util.List) Utils(cz.metacentrum.perun.core.impl.Utils) ExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyRemovedException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) ExtSourcesManagerImplApi(cz.metacentrum.perun.core.implApi.ExtSourcesManagerImplApi) Pattern(java.util.regex.Pattern) ExtSourceDeleted(cz.metacentrum.perun.audit.events.ExtSourcesManagerEvents.ExtSourceDeleted) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) GROUP_SYNC_DEFAULT_DATA(cz.metacentrum.perun.core.blImpl.GroupsManagerBlImpl.GROUP_SYNC_DEFAULT_DATA) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup)

Aggregations

CandidateGroup (cz.metacentrum.perun.core.api.CandidateGroup)7 Group (cz.metacentrum.perun.core.api.Group)6 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)5 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)5 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)5 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)5 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)5 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)5 EnrichedGroup (cz.metacentrum.perun.core.api.EnrichedGroup)5 RichGroup (cz.metacentrum.perun.core.api.RichGroup)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 ExtSource (cz.metacentrum.perun.core.api.ExtSource)2 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)2 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)2 Vo (cz.metacentrum.perun.core.api.Vo)2 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)2 CandidateNotExistsException (cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)2 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)2 ExtSourceAlreadyAssignedException (cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyAssignedException)2 ExtSourceAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyRemovedException)2