public async Task <XmppXElement> AuthenticateAsync(Mechanisms mechanisms, XmppClient xmppClient, CancellationToken cancellationToken)
        {
            var authMessage = new Auth(Matrix.Xmpp.Sasl.SaslMechanism.Plain, GetMessage(xmppClient));

            return
                (await xmppClient.SendAsync <Success, Failure>(authMessage, cancellationToken));
        }
示例#2
0
        public static SaslMechanism Create(string name)
        {
            name.ThrowIfNull <string>("name");
            if (!Mechanisms.ContainsKey(name))
            {
                throw new SaslException("A Sasl mechanism with the specified name is not registered with Sasl.SaslFactory.");
            }
            Type type = Mechanisms[name];

            return(Activator.CreateInstance(type, true) as SaslMechanism);
        }
示例#3
0
        /// <summary>
        /// 清空机器人Home预制坐标信息_Yecc
        /// </summary>
        /// <param name="FM"></param>
        /// <param name="DSystem"></param>
        /// <param name="product"></param>
        /// <param name="RobotName"></param>
        /// <param name="progressBar"></param>
        /// <param name="CreateCable"></param>
        public void ClearRobotHomeList(Form FM, DataType.Dsystem DSystem, Product product, String RobotName, ProgressBar progressBar, bool CreateCable = false)
        {
            //Workbench TheKinWorkbench = DSystem.CDSActiveDocument.GetWorkbench("KinematicsWorkbench");
            Mechanisms      cTheMechanisms = null;
            ProductDocument partDocument   = GetProductPath(product, DSystem, false);
            Selection       selection      = partDocument.Selection;

            selection.Clear();
            try
            {
                BasicDevice  basicDevice   = (BasicDevice)product.GetTechnologicalObject("BasicDevice");
                System.Array homePositions = null;
                //for (int i = 0; i < 100; i++) // add New Robot Home Position
                //{
                //    object[] HomePos = { 0, 0, 0, 0, 0, 0 };
                //    basicDevice.SetHomePosition("RobotHome_" + i, HomePos);
                //}
                basicDevice.GetHomePositions(out homePositions);
                int HomePosNum = homePositions.Length;
                if (HomePosNum > 1) //当对象运动机构数量>1时 清除全部机构对象
                {
                    foreach (HomePosition homePosition in homePositions)
                    {
                        selection.Add(homePosition);
                        //Array AtoolTip = null;
                        //homePosition.GetAssociatedToolTip(out AtoolTip);
                        //selection.Add(homePosition);
                    }
                    selection.Delete();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + ";请在帮助-》问题反馈与建议中反馈该问题,谢谢!");
                //选定的对象不存在任何运动机构
            }
            //Mechanisms TheMechanismsList = TheKinWorkbench.Mechanisms;
            RobGenericController Rgcr          = (RobGenericController)product.GetTechnologicalObject("RobGenericController");
            RobControllerFactory CRM           = (RobControllerFactory)product.GetTechnologicalObject("RobControllerFactory");
            GenericMotionProfile genericMotion = null;
            int ProfileCount = 0;

            Rgcr.GetMotionProfileCount(out ProfileCount);
            if (ProfileCount > 0)
            {
                string ProfileName = "DNBRobController";
                Rgcr.GetMotionProfile(ProfileName, out genericMotion);
            }
            InitController(Rgcr, CRM, 10, progressBar);
            Mechanism mechanism = cTheMechanisms.Add();
            //mechanism.FixedPart=
            ///RefDocument//mk:@MSITStore:F:\02%20我的知识库\05%20学习&总结资料\01%20CAA开发资料\V5Automation.chm::/online/CAAScdDmuUseCases/CAAKiiMechanismCreationSource.htm
            //string GetName = CRM.get_Name();
        }
示例#4
0
 protected EnumMemberAttribute(string valueString, bool _isFragment, string description, string css,
                               Mechanisms mechanism, bool isCollection = false, HtmlTagName tag = HtmlTagName.Any)
 {
     this._isFragment  = _isFragment;
     this._value       = valueString;
     this.description  = description;
     this._css         = css;
     this.mechanism    = mechanism;
     this.isCollection = isCollection;
     this.tagName      = tag;
 }
示例#5
0
 public void TakeAllFrom(MetaSet set)
 {
     Objects.AddRange(set.Objects);
     Actions.AddRange(set.Actions);
     Tutorials.AddRange(set.Tutorials);
     Mechanisms.AddRange(set.Mechanisms);
     Tags.AddRange(set.Tags);
     Commands.AddRange(set.Commands);
     Languages.AddRange(set.Languages);
     Events.AddRange(set.Events);
 }
示例#6
0
文件: XMPP.cs 项目: remobjects/ipxmpp
        private void GotFeatures(StreamFeatures features)
        {
            EndTimeout();
            OnStreamFeatures(features);
            if (fState == XMPP.State.Authenticated)
            {
                if (BindResource)
                {
                    fState = XMPP.State.BindingResource;

                    SendResourceBinding();
                }
                else
                {
                    fState = XMPP.State.Active; // finally!

                    OnActive();
                }
                return;
            }
            fServerMechanisms = features.AuthenticationMechanisms;
            var starttls = features.StartTLS;

            if (!(fConnection is SslConnection))
            {
                switch (InitTLS)
                {
                case InitTLSMode.Always:
                    if (starttls == null)
                    {
                        OnError(new TlsRequiredException("TLS required but not supported by server"));
                        Close();
                        return;
                    }
                    StartTLS();
                    break;

                case InitTLSMode.IfAvailable:
                    StartTLS();
                    break;

                default:
                    StartAuth();
                    break;
                }
            }
            else
            {
                StartAuth();
            }
        }
示例#7
0
文件: XMPP.cs 项目: remobjects/ipxmpp
        private void RestartConnection(InternetPack.Connection newconn)
        {
            OnInitializedTLS();
            fConnection = newconn;
            fState      = XMPP.State.Connected;
            fServerElementStack.Clear();
            fServerMechanisms = null;
            fServerRoot       = null;

            parser.Origin = fConnection;
            parser.ReadXmlElementAsync(new Action <XmlParserResult>(GotData), fServerElementStack.Count > 0);
            BeginSend(fRootElement, WriteMode.Open, null);
            BeginTimeout();
        }
示例#8
0
        private async Task <StreamFeatures> DoAuthenicateAsync(Mechanisms mechanisms, CancellationToken cancellationToken)
        {
            XmppSessionState.Value = SessionState.Authenticating;
            var res = await SaslHandler.AuthenticateAsync(mechanisms, this, cancellationToken);

            if (res is Success)
            {
                XmppSessionState.Value = SessionState.Authenticated;
                return(await ResetStreamAsync(cancellationToken));
            }
            else //if (res is Failure)
            {
                throw new AuthenticationException(res);
            }
        }
        public void CssComposing_MechanismOfByCustom()
        {
            int    i         = 0;
            string enumValue = " cite";

            Console.WriteLine("When EnumValue = '{0}'", enumValue);
            foreach (var tag in allTags)
            {
                Mechanisms          mechanisms      = Mechanisms.ByCustom;
                EnumTypeAttribute   typeAttribute   = new EnumTypeAttribute(false, mechanisms, tag);
                EnumMemberAttribute memberAttribute = new EnumMemberAttribute(enumValue);
                string css = EnumMemberAttribute.CssSelectorOf(typeAttribute, memberAttribute, enumValue);
                Console.WriteLine(string.Format("{0, 3}) {1, -20} : {2}", i++, typeAttribute, css));
            }
        }
示例#10
0
 public static void Add(string name, Type t)
 {
     name.ThrowIfNull <string>("name");
     t.ThrowIfNull <Type>("t");
     if (!t.IsSubclassOf(typeof(SaslMechanism)))
     {
         throw new ArgumentException("The type t must be a subclass of Sasl.SaslMechanism");
     }
     try
     {
         Mechanisms.Add(name, t);
     }
     catch (Exception exception)
     {
         throw new SaslException("Registration of Sasl mechanism failed.", exception);
     }
 }
示例#11
0
        XmppXElement BuildFeatures()
        {
            var feat = new StreamFeatures();

            if (!IsOnline)
            {
                var mechs = new Mechanisms();
                mechs.AddMechanism(SaslMechanism.PLAIN);
                feat.Mechanisms = mechs;
            }
            else
            {
                feat.Bind    = new Xmpp.Bind.Bind();
                feat.Session = new Xmpp.Session.Session();
            }

            return(feat);
        }
示例#12
0
        public MechanismCSpace(Mechanisms mechanism, SceneBoxes scene)
        {
            this.mechanism = mechanism;
            this.scene = scene;

            double[] dimensionLowLimit = new double[mechanism.Joints.Count];
            double[] dimensionHighLimit = new double[mechanism.Joints.Count];
            double[] dimensionWeight = new double[mechanism.Joints.Count];
            for (int i = 0; i < mechanism.Joints.Count; i++)
            {
                dimensionLowLimit[i] = -180;
                dimensionHighLimit[i] = 180;
                dimensionWeight[i] = 1;

            }

            this.cSpace = new CSpace(mechanism.Joints.Count, dimensionLowLimit, dimensionHighLimit, dimensionWeight, CheckCollision);
        }
示例#13
0
        /// <summary>
        /// Create a new SASLProcessor, of the best type possible
        /// </summary>
        /// <param name="mechs">The mechanisms supported by the server</param>
        /// <param name="mt">The types the server implements</param>
        /// <param name="plaintextOK">Is it ok to select insecure types?</param>
        /// <param name="useClientCertificate">
        /// <c>true</c> if the connection have an associated local client certificate.
        /// </param>
        /// <param name="useAnonymous"></param>
        /// <returns></returns>
        public static SASLProcessor createProcessor(
            Mechanisms mechs,
            MechanismType mt,
            bool plaintextOK,
            bool useClientCertificate,
            bool useAnonymous)
        {
            if (useAnonymous && (mt & MechanismType.ANONYMOUS) == MechanismType.ANONYMOUS)
            {
                return(new AnonymousProcessor());
            }

            if (mt.HasFlag(MechanismType.EXTERNAL) && useClientCertificate)
            {
                return(new ExternalProcessor());
            }
            else if ((mt & MechanismType.GSSAPI) == MechanismType.GSSAPI)
            {
                string RemotePrincipal = "";
                foreach (Mechanism mechanism in mechs.GetMechanisms())
                {
                    if (mechanism.MechanismName == "GSSAPI")
                    {
                        RemotePrincipal = mechanism.GetAttribute("kerb:principal");
                        break;
                    }
                }
                return(new KerbProcessor(RemotePrincipal));
            }
            if ((mt & MechanismType.DIGEST_MD5) == MechanismType.DIGEST_MD5)
            {
                return(new MD5Processor());
            }
            else if (plaintextOK && ((mt & MechanismType.PLAIN) == MechanismType.PLAIN))
            {
                return(new PlainProcessor());
            }
            if (mt == MechanismType.X_RIOT_RSO)
            {
                return(new RiotProcessor());
            }
            return(null);
        }
示例#14
0
        private XmppXElement BuildStreamFeatures()
        {
            var feat = new StreamFeatures();

            //feat.Add(new StartTls());

            if (!IsAuthenticated)
            {
                var mechs = new Mechanisms();
                mechs.AddMechanism(SaslMechanism.Plain);
                feat.Mechanisms = mechs;
            }
            else if (!IsBinded && IsAuthenticated)
            {
                feat.Add(new Bind());
            }

            return(feat);
        }
示例#15
0
        public async Task <XmppXElement> AuthenticateAsync(Mechanisms mechanisms, XmppClient xmppClient, CancellationToken cancellationToken)
        {
            ISaslProcessor saslProc = null;

            if (mechanisms.SupportsMechanism(SaslMechanism.ScramSha1))
            {
                saslProc = new ScramSha1Processor();
            }

            else if (mechanisms.SupportsMechanism(SaslMechanism.DigestMd5))
            {
                saslProc = new DigestMd5Processor();
            }

            else if (mechanisms.SupportsMechanism(SaslMechanism.Plain))
            {
                saslProc = new PlainProcessor();
            }

            return(await saslProc.AuthenticateClientAsync(xmppClient, cancellationToken));
        }
示例#16
0
        public void CreateRobotMoto(Form FM, DataType.Dsystem DSystem, Product product, String RobotName, ProgressBar progressBar, bool CreateCable = false)
        {
            Workbench  TheKinWorkbench = DSystem.CDSActiveDocument.GetWorkbench("KinematicsWorkbench");
            Mechanisms cTheMechanisms  = null;

            try
            {
                cTheMechanisms = (Mechanisms)product.GetTechnologicalObject("Mechanisms");
                if (cTheMechanisms.Count > 1) //当对象运动机构数量>1时 清除全部机构对象
                {
                    foreach (Mechanism item in cTheMechanisms)
                    {
                        cTheMechanisms.Remove(item); //Clear All Mechanisms
                    }
                }
            }
            catch (Exception)
            {
                //选定的对象不存在任何运动机构
            }
            //BasicDevice basicDevice = (BasicDevice)product.GetTechnologicalObject("BasicDevice");
            //Mechanisms TheMechanismsList = TheKinWorkbench.Mechanisms;
            RobGenericController Rgcr          = (RobGenericController)product.GetTechnologicalObject("RobGenericController");
            RobControllerFactory CRM           = (RobControllerFactory)product.GetTechnologicalObject("RobControllerFactory");
            GenericMotionProfile genericMotion = null;
            int ProfileCount = 0;

            Rgcr.GetMotionProfileCount(out ProfileCount);
            if (ProfileCount > 0)
            {
                string ProfileName = "DNBRobController";
                Rgcr.GetMotionProfile(ProfileName, out genericMotion);
            }
            InitController(Rgcr, CRM, 10, progressBar);
            Mechanism mechanism = cTheMechanisms.Add();
            //mechanism.FixedPart=
            ///RefDocument//mk:@MSITStore:F:\02%20我的知识库\05%20学习&总结资料\01%20CAA开发资料\V5Automation.chm::/online/CAAScdDmuUseCases/CAAKiiMechanismCreationSource.htm
            //string GetName = CRM.get_Name();
        }
        public async Task EventsTest()
        {
            var server = StartServerDummyTicker(new ServerContentIntegrationOption
            {
                ContentBeforeIoC = () =>
                {
                    IoCManager.Resolve <IComponentFactory>().Register <TestBehaviorComponent>();
                }
            });

            await server.WaitAssertion(() =>
            {
                var mapManager = IoCManager.Resolve <IMapManager>();

                var mapId = new MapId(0);
                mapManager.CreateNewMapEntity(mapId);

                var entityManager = IoCManager.Resolve <IEntityManager>();
                var human         = entityManager.SpawnEntity("HumanMob_Content", MapCoordinates.Nullspace);

                Assert.That(human.TryGetComponent(out IBody? body));
                Assert.NotNull(body);

                var centerPart = body !.CenterPart();
                Assert.NotNull(centerPart);

                Assert.That(body.TryGetSlot(centerPart !, out var centerSlot));
                Assert.NotNull(centerSlot);

                var mechanism = centerPart !.Mechanisms.First();
                Assert.NotNull(mechanism);

                var component = mechanism.Owner.AddComponent <TestBehaviorComponent>();
                Assert.False(component.WasAddedToBody);
                Assert.False(component.WasAddedToPart);
                Assert.That(component.WasAddedToPartInBody);
                Assert.That(component.NoRemoved);

                component.ResetAll();

                Assert.That(component.NoAdded);
                Assert.That(component.NoRemoved);

                centerPart.RemoveMechanism(mechanism);

                Assert.That(component.NoAdded);
                Assert.False(component.WasRemovedFromBody);
                Assert.False(component.WasRemovedFromPart);
                Assert.That(component.WasRemovedFromPartInBody);

                component.ResetAll();

                centerPart.TryAddMechanism(mechanism, true);

                Assert.False(component.WasAddedToBody);
                Assert.False(component.WasAddedToPart);
                Assert.That(component.WasAddedToPartInBody);
                Assert.That(component.NoRemoved());

                component.ResetAll();

                body.RemovePart(centerPart);

                Assert.That(component.NoAdded);
                Assert.That(component.WasRemovedFromBody);
                Assert.False(component.WasRemovedFromPart);
                Assert.False(component.WasRemovedFromPartInBody);

                component.ResetAll();

                centerPart.RemoveMechanism(mechanism);

                Assert.That(component.NoAdded);
                Assert.False(component.WasRemovedFromBody);
                Assert.That(component.WasRemovedFromPart);
                Assert.False(component.WasRemovedFromPartInBody);

                component.ResetAll();

                centerPart.TryAddMechanism(mechanism, true);

                Assert.False(component.WasAddedToBody);
                Assert.That(component.WasAddedToPart);
                Assert.False(component.WasAddedToPartInBody);
                Assert.That(component.NoRemoved);

                component.ResetAll();

                body.TryAddPart(centerSlot !, centerPart, true);

                Assert.That(component.WasAddedToBody);
                Assert.False(component.WasAddedToPart);
                Assert.False(component.WasAddedToPartInBody);
                Assert.That(component.NoRemoved);
            });
        }
 /// <summary>
 /// </summary>
 /// <param name="mechanisms"> </param>
 public SaslEventArgs(Mechanisms mechanisms)
 {
     Mechanisms = mechanisms;
 }
示例#19
0
文件: XMPP.cs 项目: remobjects/ipxmpp
        private Element CreateNode(XmlNodeResult nd, Element parent)
        {
            string ens;

            if (nd.Prefix != null)
            {
                RemObjects.InternetPack.XMPP.Elements.Attribute at = nd.Attribute.FirstOrDefault(a => a.Prefix == "xmlns" && a.Name == nd.Prefix);
                if (at == null)
                {
                    Element el = parent;
                    ens = string.Empty;
                    while (el != null)
                    {
                        RemObjects.InternetPack.XMPP.Elements.Attribute els = el.Attributes.Where(a => a.Prefix == "xmlns" && a.Name == nd.Prefix).FirstOrDefault();
                        if (els != null)
                        {
                            ens = els.Value;
                            break;
                        }
                        el = el.Parent;
                    }
                }
                else
                {
                    ens = at.Value;
                }
            }
            else
            {
                RemObjects.InternetPack.XMPP.Elements.Attribute at = nd.Attribute.FirstOrDefault(a => a.Prefix == null && a.Name == "xmlns");
                if (at == null)
                {
                    ens = string.Empty;
                }
                else
                {
                    ens = at.Value;
                }
            }
            Element res = null;

            switch (ens)
            {
            case Namespaces.ClientStreamNamespace:
            case Namespaces.ServerStreamNamespace:
            case "":
                if (ens == null && parent != null && parent.Type == ElementType.IQ && nd.Name == "error")
                {
                    res = new IQError();
                }
                else
                {
                    switch (nd.Name)
                    {
                    case "iq":
                        res = new IQ();
                        break;

                    case "presence":
                        res = new Presence();
                        break;

                    case "message":
                        res = new Message();
                        break;
                    }
                }
                break;

            case Namespaces.StreamNamespace:
                switch (nd.Name)
                {
                case "stream":

                    RemObjects.InternetPack.XMPP.Elements.Attribute att = nd.Attribute.FirstOrDefault(a => a.Prefix == null && a.Name == "xmlns");
                    if (att == null || att.Value == Namespaces.ClientStreamNamespace)
                    {
                        res = new ClientStream();
                    }
                    else
                    {
                        res = new ServerStream();
                    }
                    break;

                case "features":
                    res = new StreamFeatures();
                    break;

                case "error":
                    res = new StreamError();
                    break;
                }
                break;

            case Namespaces.StartTLSNamespace:
                switch (nd.Name)
                {
                case "starttls":
                    res = new StartTLS();
                    break;

                case "failure":
                    res = new StartTLSFailure();
                    break;

                case "proceed":
                    res = new StartTLSProceed();
                    break;
                }

                break;

            case Namespaces.SaslNamespace:
                switch (nd.Name)
                {
                case "mechanisms":
                    res = new Mechanisms();
                    break;

                case "auth":
                    res = new SaslAuth();
                    break;

                case "challenge":
                    res = new SaslChallenge();
                    break;

                case "response":
                    res = new SaslResponse();
                    break;

                case "abort":
                    res = new SaslAbort();
                    break;

                case "success":
                    res = new SaslSuccess();
                    break;

                case "failure":
                    res = new SaslFailure();
                    break;
                }
                break;
            }
            if (res == null)
            {
                res = new UnknownElement();
            }
            else
            {
                res.Attributes.Clear(); // default ones shouldn't be here during the reading process
            }
            if (parent != null)
            {
                res.Parent = parent;
                if (parent != fServerRoot)
                {
                    parent.Elements.Add(res);
                }
            }
            res.Prefix = nd.Prefix;
            res.Name   = nd.Name;
            foreach (var el in nd.Attribute)
            {
                res.Attributes.Add(el);
            }
            return(res);
        }
示例#20
0
        public static string CssSelectorOf(EnumTypeAttribute typeAttribute, EnumMemberAttribute memberAttribute, string memberValue)
        {
            HtmlTagName tagName         = typeAttribute.TagName;
            string      tagLocator      = tagName.Value();
            Mechanisms  mechanism       = typeAttribute.Mechanism;
            string      mechanismFormat = typeAttribute.Mechanism.Value();

            string css;

            switch (mechanism)
            {
            case Mechanisms.ByAttr:
            case Mechanisms.ByAttribute:
            {
                int index = memberValue.IndexOf(EnumValueSplitter);
                if (index == -1) //The Value of the Enum entry shall be treated as the attribute name
                {
                    string withAttr = string.Format("[{0}]", memberValue);
                    css = string.Format(tagLocator, string.Empty, withAttr);
                }
                else
                {
                    string attrString = string.Format(mechanismFormat,
                                                      memberValue.Substring(0, index), memberValue.Substring(index + 1));
                    css = string.Format(tagLocator, string.Empty, attrString);
                }
                break;
            }

            case Mechanisms.ByOrder:
            case Mechanisms.ByOrderLast:
            case Mechanisms.ByChild:
            case Mechanisms.ByChildLast:
            {
                string[] pair = memberValue.Split(EnumValueSplitter);

                string attrString = null;
                switch (pair.Count())
                {
                case 2:
                    attrString = string.Format(mechanismFormat, string.Empty, pair[1]).Trim();
                    css        = string.Format(tagLocator, pair[0], attrString);
                    break;

                case 1:
                    attrString = string.Format(mechanismFormat, string.Empty, memberValue).TrimStart();
                    css        = string.Format(tagLocator, string.Empty, attrString);
                    break;

                default:
                    throw new InvalidEnumArgumentException(mechanismFormat +
                                                           " expects one item or two items seperated by '='.");
                }
                break;
            }

            case Mechanisms.ByText:
            case Mechanisms.ByTag:
            {
                //Notice: this is not preferrable with CSS Locator.
                //The value of the Enum member shall be used afterwards
                css = string.Format(tagLocator, string.Empty, string.Empty);
                break;
            }

            case Mechanisms.ByCustom:
            {
                css = memberValue;
                break;
            }

            case Mechanisms.ByAdjacent:
            case Mechanisms.ByAncestor:
            case Mechanisms.ByParent:
            case Mechanisms.BySibling:
            {
                string[] pair = memberValue.Split(EnumValueSplitter);

                string attrString = null;
                switch (pair.Count())
                {
                case 2:
                    attrString = string.Format(mechanismFormat, pair[0], string.Empty);
                    css        = string.Format(tagLocator, attrString, pair[1]);
                    break;

                case 1:
                    attrString = string.Format(mechanismFormat, memberValue, string.Empty);
                    css        = string.Format(tagLocator, attrString, string.Empty);
                    break;

                default:
                    throw new InvalidEnumArgumentException(mechanismFormat +
                                                           " expects one item or two items seperated by '='.");
                }
                break;
            }

            default:
                //case Mechanisms.ById:
                //case Mechanisms.ByClass:
                //case Mechanisms.ByUrl:
                //case Mechanisms.ByName:
                //case Mechanisms.ByValue:
            {
                string[] pair = memberValue.Split(EnumValueSplitter);
                string   byId = string.Format(mechanismFormat, pair.Last());
                css = string.Format(tagLocator, string.Empty, byId);
                break;
            }
            }
            return(css);
        }
示例#21
0
        public async Task EventsTest()
        {
            var options = new ServerContentIntegrationOption {
                ExtraPrototypes = Prototypes
            };
            var server = StartServerDummyTicker(options);

            await server.WaitAssertion(() =>
            {
                var mapManager = IoCManager.Resolve <IMapManager>();

                var mapId = new MapId(0);
                mapManager.CreateNewMapEntity(mapId);

                var entityManager = IoCManager.Resolve <IEntityManager>();
                var human         = entityManager.SpawnEntity("HumanBodyDummy", MapCoordinates.Nullspace);

                Assert.That(human.TryGetComponent(out IBody? body));
                Assert.NotNull(body);

                var centerPart = body !.CenterPart;
                Assert.NotNull(centerPart);

                Assert.That(body.TryGetSlot(centerPart !, out var centerSlot));
                Assert.NotNull(centerSlot);

                var mechanism = centerPart !.Mechanisms.First();
                Assert.NotNull(mechanism);

                mechanism.EnsureBehavior <TestMechanismBehavior>(out var behavior);
                Assert.False(behavior.WasAddedToBody);
                Assert.False(behavior.WasAddedToPart);
                Assert.That(behavior.WasAddedToPartInBody);
                Assert.That(behavior.NoRemoved);

                behavior.ResetAll();

                Assert.That(behavior.NoAdded);
                Assert.That(behavior.NoRemoved);

                centerPart.RemoveMechanism(mechanism);

                Assert.That(behavior.NoAdded);
                Assert.False(behavior.WasRemovedFromBody);
                Assert.False(behavior.WasRemovedFromPart);
                Assert.That(behavior.WasRemovedFromPartInBody);

                behavior.ResetAll();

                centerPart.TryAddMechanism(mechanism, true);

                Assert.False(behavior.WasAddedToBody);
                Assert.False(behavior.WasAddedToPart);
                Assert.That(behavior.WasAddedToPartInBody);
                Assert.That(behavior.NoRemoved());

                behavior.ResetAll();

                body.RemovePart(centerPart);

                Assert.That(behavior.NoAdded);
                Assert.That(behavior.WasRemovedFromBody);
                Assert.False(behavior.WasRemovedFromPart);
                Assert.False(behavior.WasRemovedFromPartInBody);

                behavior.ResetAll();

                centerPart.RemoveMechanism(mechanism);

                Assert.That(behavior.NoAdded);
                Assert.False(behavior.WasRemovedFromBody);
                Assert.That(behavior.WasRemovedFromPart);
                Assert.False(behavior.WasRemovedFromPartInBody);

                behavior.ResetAll();

                centerPart.TryAddMechanism(mechanism, true);

                Assert.False(behavior.WasAddedToBody);
                Assert.That(behavior.WasAddedToPart);
                Assert.False(behavior.WasAddedToPartInBody);
                Assert.That(behavior.NoRemoved);

                behavior.ResetAll();

                body.SetPart(centerSlot !.Id, centerPart);

                Assert.That(behavior.WasAddedToBody);
                Assert.False(behavior.WasAddedToPart);
                Assert.False(behavior.WasAddedToPartInBody);
                Assert.That(behavior.NoRemoved);
            });
        }
示例#22
0
 /// <summary>
 /// Create a new SASLProcessor, of the best type possible
 /// </summary>
 /// <param name="mt">The types the server implements</param>
 /// <param name="plaintextOK">Is it ok to select insecure types?</param>
 /// <param name="mechs">The mechanisms supported by the server</param>
 /// <returns></returns>
 public static SASLProcessor createProcessor(MechanismType mt, bool plaintextOK, Mechanisms mechs)
 {
     if ((mt & MechanismType.EXTERNAL) == MechanismType.EXTERNAL)
     {
         return(new ExternalProcessor());
     }
     if ((mt & MechanismType.GSSAPI) == MechanismType.GSSAPI)
     {
         string RemotePrincipal = "";
         foreach (Mechanism mechanism in mechs.GetMechanisms())
         {
             if (mechanism.MechanismName == "GSSAPI")
             {
                 RemotePrincipal = mechanism.GetAttribute("kerb:principal");
                 break;
             }
         }
         return(new KerbProcessor(RemotePrincipal));
     }
     if ((mt & MechanismType.DIGEST_MD5) == MechanismType.DIGEST_MD5)
     {
         return(new MD5Processor());
     }
     else if (plaintextOK && ((mt & MechanismType.PLAIN) == MechanismType.PLAIN))
     {
         return(new PlainProcessor());
     }
     return(null);
 }
示例#23
0
 public SaslEventArgs(Mechanisms mechanisms)
 {
     this.m_Mechanisms = mechanisms;
 }
示例#24
0
        XmppXElement BuildFeatures()
        {
            var feat = new StreamFeatures();
            if (!IsOnline)
            {
                var mechs = new Mechanisms();
                mechs.AddMechanism(SaslMechanism.PLAIN);
                feat.Mechanisms = mechs;
            }
            else
            {
                feat.Bind = new Xmpp.Bind.Bind();
                feat.Session = new Xmpp.Session.Session();
            }

            return feat;
        }