Esempio n. 1
0
        List <List <T> > ConvertMultiSearchResultToList(MultiSearchResult multiSearchResult)
        {
            var result = new List <List <T> >();

            var paths = multiSearchResult.TokenizedResults;

            foreach (var path in paths)
            {
                var tokens = new List <T>();

                foreach (var node in path)
                {
                    var wordId = node.WordId;
                    if (node.Type == ViterbiNode.NodeType.Known && wordId == -1)
                    {
                        // Do not include BOS/EOS
                        continue;
                    }

                    var token = TokenFactory.CreateToken(
                        wordId,
                        node.Surface,
                        node.Type,
                        node.StartIndex,
                        DictionaryMap[node.Type]
                        );
                    tokens.Add(token);
                }
                result.Add(tokens);
            }

            return(result);
        }
Esempio n. 2
0
        private IAToken CreateToken(int startPos, int endPos)
        {
            IAToken token = TokenFactory.CreateToken(_text.Substring(startPos, endPos - startPos));

            SetAddSpaceFlag(token, endPos);
            return(token);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new login token for authenticating a specific user for a specific application.
 /// </summary>
 /// <param name="username">The login name of the user requesting authentication.</param>
 /// <param name="applicationID">The unique identifier of the application requesting authentication.</param>
 /// <returns>A new login token if the specified user has access to the specified application; otherwise, null.</returns>
 public Token CreateToken(string username, byte applicationID)
 {
     using (CPSecurityEntities context = new CPSecurityEntities())
     {
         var app = context.SecuritySsoApplications.FirstOrDefault(a => a.ApplicationId == applicationID);
         if (app != null && HasUserRights(username, (CPUserRights)app.UserRights))
         {
             SecuritySsoToken token = new SecuritySsoToken()
             {
                 UserName = username,
                 SecuritySsoApplication = app
             };
             try
             {
                 context.SecuritySsoTokens.AddObject(token);
                 context.SaveChanges();
                 return(TokenFactory.CreateToken(token));
             }
             catch
             {
             }
         }
     }
     return(null);
 }
Esempio n. 4
0
        private IAToken GetQuotedIdentifier(ref int textPos, char endQuote)
        {
            int startPos = textPos;

            textPos++;
            while (textPos < _text.Length)
            {
                if (_text[textPos] == endQuote)
                {
                    break;
                }
                textPos++;
            }

            if (textPos == _text.Length)
            {
                throw new ATokenizerException(string.Format("Missing terminating quote for quoted identifier starting at position {0}", startPos));
            }

            textPos++;
            IAToken token = TokenFactory.CreateToken(_text.Substring(startPos, textPos - startPos));

            SetAddSpaceFlag(token, textPos);

            return(token);
        }
Esempio n. 5
0
        private void button5_Click(object sender, EventArgs e)
        {
            IToken lToken = TokenFactory.CreateToken(WebSocketMessage.NS_SYSTEM_PLUGIN, "string");

            lToken.SetString("data", "Hello");
            mClient.SendToken(lToken, StringResponse);
        }
        public async Task WhenNoCorsHeadersAreAlreadySetOnTheResponse_SetsThemFromRequestSpecificHeaders()
        {
            var client = PipelineFactory.CreateHttpClient(_options, x =>
            {
                x.Use(async(context, next) =>
                {
                    context.Request.Headers.Add("Origin", new[] { "Origin Value" });
                    context.Request.Headers.Add("Access-Control-Request-Method", new[] { "ACRM Value" });
                    context.Request.Headers.Add("Access-Control-Request-Headers", new[] { "ACRH Value" });

                    await next()
                    .ConfigureAwait(true);
                });
            });

            var token = TokenFactory.CreateTokenString(TokenFactory.CreateToken(scope: new string[] { TokenFactory.Api1Scope }));

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test")
                         .ConfigureAwait(false);

            var responseHeaders = result.Headers;

            responseHeaders.GetValues("Access-Control-Allow-Origin").Should().BeEquivalentTo("Origin Value");
            responseHeaders.GetValues("Access-Control-Expose-Headers").Should().BeEquivalentTo("WWW-Authenticate");
            responseHeaders.GetValues("Access-Control-Allow-Method").Should().BeEquivalentTo("ACRM Value");
            responseHeaders.GetValues("Access-Control-Allow-Headers").Should().BeEquivalentTo("ACRH Value");
        }
Esempio n. 7
0
        private void button6_Click(object sender, EventArgs e)
        {
            IToken lToken = TokenFactory.CreateToken(WebSocketMessage.NS_SYSTEM_PLUGIN, "int");

            lToken.SetInt("data", 5);
            mClient.SendToken(lToken, IntegerResponse);
        }
Esempio n. 8
0
        private void button7_Click(object sender, EventArgs e)
        {
            IToken lToken = TokenFactory.CreateToken(WebSocketMessage.NS_SYSTEM_PLUGIN, "double");

            lToken.SetDouble("data", 1.3);
            mClient.SendToken(lToken, DoubleResponse);
        }
Esempio n. 9
0
        private void button8_Click(object sender, EventArgs e)
        {
            IToken lToken = TokenFactory.CreateToken(WebSocketMessage.NS_SYSTEM_PLUGIN, "bool");

            lToken.SetBool("data", true);
            mClient.SendToken(lToken, BooleanResponse);
        }
        public async Task WhenCorsHeadersAreAlreadySetOnTheResponse_LeavesThemAsIs()
        {
            var client = PipelineFactory.CreateHttpClient(_options, x =>
            {
                x.Use(async(context, next) =>
                {
                    var hdr = context.Response.Headers;
                    //hdr.Remove("Access-Control-Allow-Origin");
                    //hdr.Remove("Access-Control-Allow-Method");
                    //hdr.Remove("Access-Control-Allow-Headers");

                    hdr.Add("Access-Control-Allow-Origin", new[] { "ACAO Value" });
                    hdr.Add("Access-Control-Allow-Method", new[] { "ACAM Value" });
                    hdr.Add("Access-Control-Allow-Headers", new[] { "ACAH Value" });

                    await next();
                });
            });

            var token = TokenFactory.CreateTokenString(TokenFactory.CreateToken(scope: new string[] { TokenFactory.Api1Scope }));

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test");

            var responseHeaders = result.Headers;

            responseHeaders.GetValues("Access-Control-Allow-Origin").Should().BeEquivalentTo("ACAO Value");
            responseHeaders.GetValues("Access-Control-Allow-Method").Should().BeEquivalentTo("ACAM Value");
            responseHeaders.GetValues("Access-Control-Allow-Headers").Should().BeEquivalentTo("ACAH Value");
        }
Esempio n. 11
0
        /// <summary>
        /// Tokenize input sentence.
        /// </summary>
        /// <param name="offset">offset of sentence in original input text</param>
        /// <param name="text">sentence to tokenize</param>
        /// <returns>list of Token</returns>
        List <T> CreateTokenList(int offset, string text)
        {
            var result = new List <T>();

            var lattice  = ViterbiBuilder.Build(text);
            var bestPath = ViterbiSearcher.Search(lattice);

            foreach (var node in bestPath)
            {
                var wordId = node.WordId;
                if (node.Type == ViterbiNode.NodeType.Known && wordId == -1)
                {
                    // Do not include BOS/EOS
                    continue;
                }

                var token = TokenFactory.CreateToken(
                    wordId,
                    node.Surface,
                    node.Type,
                    offset + node.StartIndex,
                    DictionaryMap[node.Type]
                    );
                result.Add(token);
            }

            return(result);
        }
Esempio n. 12
0
        private void Echo_Click(object sender, RoutedEventArgs e)
        {
            StatusList.Items.Add("sending echo token..");
            var token = TokenFactory.CreateToken(WebSocketTokenClient.NS_SYSTEM_PLUGIN, "echo");

            token.SetString("data", EchoMessage.Text);
            _webSocketTokenClient.SendTokenText(token);
        }
Esempio n. 13
0
        public void CreateHandshakeTokenAsyncTest()
        {
            string encodedToken = _token.GetEncodedToken();

            _restoredSyn = _tokenFactory.CreateToken(encodedToken);
            Assert.AreEqual(encodedToken, _restoredSyn.GetEncodedToken());
            Assert.AreEqual(_token.PublicKey, _restoredSyn.PublicKey);
            Assert.AreEqual(_token.Signature, _restoredSyn.Signature);
        }
Esempio n. 14
0
        private void button10_Click(object sender, EventArgs e)
        {
            IToken lToken = TokenFactory.CreateToken(WebSocketMessage.NS_SYSTEM_PLUGIN, "dictionary");
            Dictionary <string, object> lDic = new Dictionary <string, object>();

            lDic.Add("data", 6);

            lToken.SetDictionary("data", lDic);
            mClient.SendToken(lToken, DictResponse);
        }
        public async Task Token_Sent_With_Unexpected_Audience_And_Audience_Validation_Is_On()
        {
            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(TokenFactory.CreateToken(audience: "UNEXPECTED_AUDIENCE"));

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test");

            result.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
Esempio n. 16
0
        public async Task Token_Sent_No_Scope_No_ScopeRequirements()
        {
            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(TokenFactory.CreateToken());

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test");

            result.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Esempio n. 17
0
        private void button9_Click(object sender, EventArgs e)
        {
            IToken        lToken = TokenFactory.CreateToken(WebSocketMessage.NS_SYSTEM_PLUGIN, "list");
            List <object> lList  = new List <object>();

            for (int i = 0; i < 5; i++)
            {
                lList.Add(i + 1);
            }
            lToken.SetList("data", lList);
            mClient.SendToken(lToken, ListResponse);
        }
Esempio n. 18
0
        public async Task Token_Sent_No_Scope_Api1_Api2_ScopeRequirements()
        {
            _options.RequiredScopes = new[] { TokenFactory.Api1Scope, TokenFactory.Api2Scope };

            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(TokenFactory.CreateToken());

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test");

            result.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
Esempio n. 19
0
        public async Task JWT_Sent_No_Scope_No_ScopeRequirements()
        {
            _options.BackchannelHttpHandler = new DiscoveryEndpointHandler();

            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(TokenFactory.CreateToken());

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test");

            result.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Esempio n. 20
0
        public async Task Token_Sent_Api1_Scope_Api1_ScopeRequirements()
        {
            _options.RequiredScopes = new[] { TokenFactory.Api1Scope };

            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(
                TokenFactory.CreateToken(scope: new[] { TokenFactory.Api1Scope }));

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test")
                         .ConfigureAwait(false);

            result.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public async Task JWT_Sent_No_Scope_Api1_ScopeRequirements()
        {
            _options.BackchannelHttpHandler = new DiscoveryEndpointHandler();
            _options.RequiredScopes         = new[] { TokenFactory.Api1Scope };

            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(TokenFactory.CreateToken());

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test")
                         .ConfigureAwait(false);

            result.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
Esempio n. 22
0
        public override void ExecuteOperation()
        {
            if (!ExecuteDomainExistsQuery())
            {
                CreateDomainCommand().ExecuteNonQuery();
            }

            Guid newNodeId = Guid.Empty;

            CreateNodeCommand(out newNodeId).ExecuteNonQuery();

            TransactionToken token = TokenFactory.CreateToken();

            token.DelayedExecutionMapObjectId = newNodeId;

            ResultTokens.Add(token);
        }
Esempio n. 23
0
        public HttpClient CreateAuthenticatedClient(string token = null, string scheme = "Test")
        {
            if (string.IsNullOrEmpty(token))
            {
                token = TokenFactory.CreateToken("Test User", Array.Empty <string>());
            }

            var client = WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddAuthentication(scheme)
                    .AddScheme <AuthenticationSchemeOptions, TestAuthenticationHandler>(
                        scheme, options => { });
                });
            }).CreateClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(scheme, token);

            return(client);
        }
Esempio n. 24
0
        public override IEnumerable <Token> Parse(string ETLString, TokenFactory tokenFactory)
        {
            var            strs      = SplitString(ETLString);
            List <Token>   retTokens = new List <Token>(strs.Count());
            Regex          _matcher;
            ExpressionType _type;

            foreach (string str in strs)
            {
                try
                {
                    _type = tokenIdentifiers.First(ti =>
                    {
                        _matcher = new Regex(ti.Item1, RegexOptions.IgnoreCase);
                        return(_matcher.IsMatch(str));
                    }).Item2;
                }
                catch (InvalidOperationException ex)
                {
                    throw new InvalidExpressionException($"Unrecognized Token {str}", ex);
                }
                if (_type.IsOperand())
                {
                    retTokens.Add(tokenFactory.CreateValueToken(_type, Convert.ChangeType(str, ValueExpTypeToValueType[_type])));
                }
                else if (_type.IsOperator())
                {
                    retTokens.Add(tokenFactory.CreateToken(_type));
                }
                else if (_type.IsSpecial())
                {
                    retTokens.Add(tokenFactory.CreateSpecialToken(_type));
                }
                else
                {
                    throw new ArgumentException($"Unrecoginzed Type: {_type.ToString()}");
                }
            }
            return(retTokens);
        }
Esempio n. 25
0
        private IAToken GetStringToken(ref int textPos)
        {
            int startPos = textPos;

            textPos++;
            while (textPos < _text.Length)
            {
                if (_text[textPos] == QuoteChar)
                {
                    if (textPos + 1 < _text.Length && _text[textPos + 1] == QuoteChar)
                    {
                        textPos += 2;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    textPos++;
                }
            }

            if (textPos == _text.Length)
            {
                throw new ATokenizerException(string.Format("Missing terminating quote for string starting at position {0}", startPos));
            }

            textPos++;
            IAToken token = TokenFactory.CreateToken(_text.Substring(startPos, textPos - startPos));

            if (ExpandEmptyStrings && token.Text == "''")
            {
                token.Text = "' '";
            }
            SetAddSpaceFlag(token, textPos);

            return(token);
        }
Esempio n. 26
0
        public async Task Token_From_QueryString()
        {
            var provider = new OAuthBearerAuthenticationProvider
            {
                OnRequestToken = c =>
                {
                    var qs = c.OwinContext.Request.Query;
                    c.Token = qs.Get("access_token");

                    return(Task.FromResult(0));
                }
            };

            _options.TokenProvider = provider;

            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(TokenFactory.CreateToken());

            var result = await client.GetAsync("http://test?access_token=" + token);

            result.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Esempio n. 27
0
        public async Task WhenDelayLoadMetadataIsTrue_MetadataRetrievalIsRetriedAfterFailure()
        {
            _options.BackchannelHttpHandler = new FailureDiscoveryEndpointHandler();

            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(TokenFactory.CreateToken());

            client.SetBearerToken(token);

            Func <Task> action = async() => await client.GetAsync("http://test");

            action.
            ShouldThrow <InvalidOperationException>().
            And.
            Message.Should().Contain("IDX10803");     // IDX10803: Unable to create to obtain configuration from: https://discodoc

            _options.BackchannelHttpHandler = new DiscoveryEndpointHandler();

            var result = await client.GetAsync("http://test");

            result.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Esempio n. 28
0
        public async Task Valid_Token_With_ValidatingIdentity_Deny_Access()
        {
            var provider = new OAuthBearerAuthenticationProvider
            {
                OnValidateIdentity = c =>
                {
                    c.Rejected();

                    return(Task.FromResult(0));
                }
            };

            _options.TokenProvider = provider;

            var client = PipelineFactory.CreateHttpClient(_options);
            var token  = TokenFactory.CreateTokenString(TokenFactory.CreateToken());

            client.SetBearerToken(token);

            var result = await client.GetAsync("http://test");

            result.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
Esempio n. 29
0
 public AddNodeTransactionOperation(SqlConnection connection, TransactionTokenFactory factory)
     : base(connection, factory)
 {
     NewNodeToken = TokenFactory.CreateToken();
     ResultTokens.Add(NewNodeToken);
 }
Esempio n. 30
0
 public AddRelationshipTransactionOperation(SqlConnection connection, TransactionTokenFactory factory)
     : base(connection, factory)
 {
     ResultTokens.Add(TokenFactory.CreateToken());
 }