public bool TryMapUserIdentity(
            RichIdentity sourceUserIdentity,
            IdentityLookupContext context,
            out RichIdentity mappedUserIdentity)
        {
            mappedUserIdentity = new RichIdentity();

            // 1. figure out the mapping direction in the identity's host session, e.g. left to right or the opposite
            if (!m_lookupContextManager.TrySetupContext(context))
            {
                TraceManager.TraceError(
                    "Identity look up failed - Migration Source '{0}' and '{1}' in the lookup context does not belong to the same session",
                    context.SourceMigrationSourceId.ToString(), context.TargetMigrationSourceId.ToString());
                return(false);
            }

            bool mapped = false;

            // 2. use the most specific mapping: user identity mapping
            mapped |= m_userMappingAlg.TryMapUserIdentity(sourceUserIdentity, context, mappedUserIdentity);

            // 3. then use the display name mapping
            mapped |= m_dispNameMappingAlg.TryMapUserIdentity(sourceUserIdentity, context, mappedUserIdentity);

            // 4. and then use the alias and/or domain name mapping together
            bool aliasMappingRslt  = m_aliasMappingAlg.TryMapUserIdentity(sourceUserIdentity, context, mappedUserIdentity);
            bool domainMappingRslt = m_domainMappingAlg.TryMapUserIdentity(sourceUserIdentity, context, mappedUserIdentity);

            return(mapped | (aliasMappingRslt & domainMappingRslt));
        }
        /// <summary>
        /// This method tries to look up in the sessions to find the source Migration
        /// Source that context.SourceMigrationSourceId corresponds to. Then it verifies
        /// that context.TargetMigrationSourceId corresponds to the peer Migration Source
        /// in the same session.
        /// If the mapping session found, the direction of mapping (context.MappingDirection)
        /// is set accordingly.
        /// Note that only LeftToRight and RightToLeft direction enum is used to set the
        /// MappingDirection
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public bool TrySetupContext(IdentityLookupContext context)
        {
            if (m_leftToRightMigrationSourcePairs.ContainsKey(context.SourceMigrationSourceId))
            {
                // source migration source id is "left"

                if (context.TargetMigrationSourceId.Equals(m_leftToRightMigrationSourcePairs[context.SourceMigrationSourceId]))
                {
                    // bingo: target migration source id is "right"

                    context.MappingDirection = MappingDirectionEnum.LeftToRight;
                    return(true);
                }
            }
            else if (m_leftToRightMigrationSourcePairs.ContainsKey(context.TargetMigrationSourceId))
            {
                // target migration source id is "right"

                if (context.SourceMigrationSourceId.Equals(m_leftToRightMigrationSourcePairs[context.TargetMigrationSourceId]))
                {
                    // bingo: source migration source id is "right"

                    context.MappingDirection = MappingDirectionEnum.RightToLeft;
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        internal IdentityLookupContext Reverse()
        {
            IdentityLookupContext retVal = new IdentityLookupContext(TargetMigrationSourceId, SourceMigrationSourceId);

            retVal.MappingDirection = (this.MappingDirection == MappingDirectionEnum.LeftToRight
                                      ? MappingDirectionEnum.RightToLeft
                                      : MappingDirectionEnum.LeftToRight);
            return(retVal);
        }
        /// <summary>
        /// Try map the user identity based on the mappings rules in the configuration
        /// </summary>
        /// <param name="sourceUserIdentity"></param>
        /// <param name="context"></param>
        /// <param name="mappedUserIdentity"></param>
        /// <returns>True if a mapping rule is applied to the sourceUserIdentity; FALSE otherwise</returns>
        public bool TryMapUserIdentity(
            RichIdentity sourceUserIdentity,
            IdentityLookupContext context,
            RichIdentity mappedUserIdentity)
        {
            switch (context.MappingDirection)
            {
            case MappingDirectionEnum.LeftToRight:
                return(MapUser(sourceUserIdentity, true, mappedUserIdentity));

            case MappingDirectionEnum.RightToLeft:
                return(MapUser(sourceUserIdentity, false, mappedUserIdentity));

            default:
                TraceManager.TraceError("Unknown context.MappingDirection: {0}", context.MappingDirection.ToString());
                return(false);
            }
        }
        public override void Translate(IMigrationAction action, Guid migrationSourceIdOfChangeGroup)
        {
            MigrationAction migrAction = action as MigrationAction;

            Debug.Assert(migrAction != null, "action is not a MigrationActin");

            migrAction.Path     = GetMappedPath(action.Path, migrationSourceIdOfChangeGroup);
            migrAction.FromPath = GetMappedPath(action.FromPath, migrationSourceIdOfChangeGroup);

            if (UserIdLookupService.IsConfigured)
            {
                if (action.ChangeGroup.ChangeGroupId != m_cachedUserIdLookupResult.Key)
                {
                    IdentityLookupContext context = new IdentityLookupContext(
                        migrationSourceIdOfChangeGroup, m_migratinSourcePair[migrationSourceIdOfChangeGroup]);

                    UserIdPropertyNameEnum srcDefaultUserIdProperty;
                    UserIdPropertyNameEnum targetDefaultUserIdProperty;
                    if (UserIdLookupService.TryGetDefaultUserIdProperty(context.SourceMigrationSourceId, out srcDefaultUserIdProperty) &&
                        UserIdLookupService.TryGetDefaultUserIdProperty(context.TargetMigrationSourceId, out targetDefaultUserIdProperty))
                    {
                        RichIdentity srcUserId = new RichIdentity();
                        srcUserId[srcDefaultUserIdProperty.ToString()] = action.ChangeGroup.Owner; // todo: parse qualified name?

                        RichIdentity mappedUserId;
                        if (UserIdLookupService.TryLookup(srcUserId, context, out mappedUserId))
                        {
                            action.ChangeGroup.Owner = mappedUserId[targetDefaultUserIdProperty.ToString()];
                        }
                    }

                    m_cachedUserIdLookupResult = new KeyValuePair <long, string>(action.ChangeGroup.ChangeGroupId, action.ChangeGroup.Owner);
                }
                else
                {
                    action.ChangeGroup.Owner = m_cachedUserIdLookupResult.Value;
                }
            }
        }