Exemple #1
0
        public void SerDeser()
        {
            var t  = new SysAuthToken("a", "b");
            var s  = t.ToString();
            var t2 = SysAuthToken.Parse(s);

            Aver.AreEqual("a", t2.Realm);
            Aver.AreEqual("b", t2.Data);
        }
        protected override RequestMsg DoDecodeRequest(WireFrame frame, MemoryStream ms, ISerializer serializer)
        {
            var utf8 = ms.GetBuffer();
            var json = Encoding.UTF8.GetString(utf8, (int)ms.Position, (int)ms.Length - (int)ms.Position);
            var data = JsonReader.DeserializeDataObject(json) as JsonDataMap;

            if (data == null)
            {
                throw new ProtocolException(StringConsts.GLUE_BINDING_REQUEST_ERROR.Args(nameof(AppTermBinding), "data==null"));
            }

            var reqID    = new FID(data["request-id"].AsULong(handling: ConvertErrorHandling.Throw)); //kuda ego vstavit?
            var instance = data["instance"].AsNullableGUID(handling: ConvertErrorHandling.Throw);
            var oneWay   = data["one-way"].AsBool();
            var method   = data["method"].AsString();

            MethodSpec mspec;

            if (method.EqualsOrdIgnoreCase(nameof(Contracts.IRemoteTerminal.Connect)))
            {
                mspec = AppTermBinding.METHOD_CONNECT;
            }
            else if (method.EqualsOrdIgnoreCase(nameof(Contracts.IRemoteTerminal.Execute)))
            {
                mspec = AppTermBinding.METHOD_EXECUTE;
            }
            else if (method.EqualsOrdIgnoreCase(nameof(Contracts.IRemoteTerminal.Disconnect)))
            {
                mspec = AppTermBinding.METHOD_DISCONNECT;
            }
            else
            {
                throw new ProtocolException(StringConsts.GLUE_BINDING_REQUEST_ERROR.Args(nameof(AppTermBinding), "unknown method `{0}`".Args(method)));
            }

            var args = data["command"] == null ? new object[0] : new object[] { data["command"].AsString() };

            var result = new RequestAnyMsg(AppTermBinding.TYPE_CONTRACT, mspec, oneWay, instance, args);

            var autht = data["auth-token"].AsString();

            if (autht != null)
            {
                var hdr = new AuthenticationHeader(SysAuthToken.Parse(autht));
                result.Headers.Add(hdr);
            }
            var authc = data["auth-cred"].AsString();

            if (authc != null)
            {
                var hdr = new AuthenticationHeader(Azos.Security.IDPasswordCredentials.FromBasicAuth(authc));
                result.Headers.Add(hdr);
            }

            return(result);
        }
Exemple #3
0
        public void Parse()
        {
            Aver.IsFalse(SysAuthToken.Parse(null).Assigned);
            Aver.IsFalse(SysAuthToken.Parse("").Assigned);


            var v = SysAuthToken.Parse("frog::toad");

            Aver.AreEqual("frog", v.Realm);
            Aver.AreEqual("toad", v.Data);

            Aver.Throws <SecurityException>(() => SysAuthToken.Parse("::toad"));
            Aver.Throws <SecurityException>(() => SysAuthToken.Parse("frog::"));
            Aver.Throws <SecurityException>(() => SysAuthToken.Parse("frogtoad"));
            Aver.Throws <SecurityException>(() => SysAuthToken.Parse("frog:toad"));
        }