예제 #1
0
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView drv = null;

        switch (sourceName.ToLowerCSafe())
        {
        case "result":
            drv = parameter as DataRowView;
            string errorMsg = ValidationHelper.GetString(drv["SynchronizationErrorMessage"], string.Empty);

            bool errorOccurred = !string.IsNullOrEmpty(errorMsg);
            if (errorOccurred)
            {
                int    synchronizationId = ValidationHelper.GetInteger(drv["SynchronizationID"], 0);
                string logUrl            = ResolveUrl("~/CMSModules/Integration/Pages/Administration/Log.aspx?synchronizationid=") + synchronizationId;
                return(String.Format("<a target=\"_blank\" href=\"{0}\" onclick=\"modalDialog('{0}', 'tasklog', 700, 500); return false;\">{1}</a>", logUrl, GetString("Tasks.ResultFailed")));
            }
            else
            {
                return(string.Empty);
            }

        case "view":
            if (sender is ImageButton)
            {
                ImageButton viewButton = sender as ImageButton;
                drv = UniGridFunctions.GetDataRowView(viewButton.Parent as DataControlFieldCell);
                int    taskId    = ValidationHelper.GetInteger(drv["TaskID"], 0);
                string detailUrl = ResolveUrl("~/CMSModules/Integration/Pages/Administration/View.aspx?taskid=") + taskId;
                viewButton.OnClientClick = "modalDialog('" + detailUrl + "', 'tasklog', 700, 500); return false;";
                return(viewButton);
            }
            return(parameter);

        case "run":
            if (sender is ImageButton)
            {
                ImageButton runButton = sender as ImageButton;
                drv = UniGridFunctions.GetDataRowView(runButton.Parent as DataControlFieldCell);

                bool   connectorEnabled   = ValidationHelper.GetBoolean(drv["ConnectorEnabled"], false);
                string connectorName      = ValidationHelper.GetString(drv["ConnectorName"], String.Empty);
                bool   processingDisabled = TasksAreInbound ? !IntegrationHelper.IntegrationProcessExternal : !IntegrationHelper.IntegrationProcessInternal;
                if (processingDisabled || (IntegrationHelper.GetConnector(connectorName) == null) || !connectorEnabled)
                {
                    // Set appropriate tooltip
                    if (processingDisabled)
                    {
                        runButton.ToolTip = GetString("integration.processingdisabled");
                    }
                    else
                    {
                        string connectorDisplayName = ValidationHelper.GetString(drv["ConnectorDisplayName"], String.Empty);
                        if (!connectorEnabled)
                        {
                            runButton.ToolTip = String.Format(GetString("integration.connectordisabled"), HTMLHelper.HTMLEncode(connectorDisplayName));
                        }
                        else
                        {
                            runButton.ToolTip = String.Format(GetString("integration.connectorunavailable"), HTMLHelper.HTMLEncode(connectorDisplayName));
                        }
                    }

                    runButton.ImageUrl      = GetImageUrl("/Design/Controls/UniGrid/Actions/SynchronizeDisabled.png");
                    runButton.OnClientClick = "return false;";
                    runButton.Style.Add(HtmlTextWriterStyle.Cursor, "default");
                    return(runButton);
                }
            }
            break;
        }
        return(parameter);
    }
 public DataTable ExecuteIntegrationQuery(string Connection, string Query)
 {
     return(IntegrationHelper.GetDataFromIntegration(Connection, Query));
 }
예제 #3
0
    protected override void OnPreRender(EventArgs e)
    {
        // Hide multiple actions if grid is empty
        pnlFooter.Visible = !gridElem.IsEmpty;

        // Initialize actions dropdown list - they need to be refreshed on connector selection
        drpAction.Items.Clear();
        drpAction.Items.Add(new ListItem(GetString("general." + Action.SelectAction), Convert.ToInt32(Action.SelectAction).ToString()));

        // Add synchronize option only when task processing is enabled
        IntegrationConnectorInfo connector = IntegrationConnectorInfoProvider.GetIntegrationConnectorInfo(ConnectorID);

        if ((TasksAreInbound ? IntegrationHelper.IntegrationProcessExternal : IntegrationHelper.IntegrationProcessInternal) && ((ConnectorID <= 0) || (connector != null) && connector.ConnectorEnabled && (IntegrationHelper.GetConnector(connector.ConnectorName) != null)))
        {
            drpAction.Items.Add(new ListItem(GetString("general." + Action.Synchronize), Convert.ToInt32(Action.Synchronize).ToString()));
        }
        drpAction.Items.Add(new ListItem(GetString("general." + Action.Delete), Convert.ToInt32(Action.Delete).ToString()));

        base.OnPreRender(e);
    }
예제 #4
0
        public async System.Threading.Tasks.Task Prepair_TestDataAsync()
        {
            var model     = faker.PredefinedRawSignedModel();
            var fullModel = faker.PredefinedRawSignedModel(
                "a666318071274adb738af3f67b8c7ec29d954de2cabfd71a942e6ea38e59fff9",
                true, true, true);
            var data = new Dictionary <string, string>
            {
                { "STC-1.as_string", model.ExportAsString() },
                { "STC-1.as_json", model.ExportAsJson() },
                { "STC-2.as_string", fullModel.ExportAsString() },
                { "STC-2.as_json", fullModel.ExportAsJson() }
            };

            var cardManager = faker.CardManager();
            var card        = cardManager.ImportCardFromString(model.ExportAsString());
            var crypto      = new VirgilCrypto();

            data.Add("STC-3.as_string", cardManager.ExportCardAsString(card));
            data.Add("STC-3.as_json", cardManager.ExportCardAsJson(card));
            data.Add("STC-3.card_id", card.Id);
            data.Add("STC-3.public_key_base64", Bytes.ToString(crypto.ExportPublicKey(card.PublicKey), StringEncoding.BASE64));

            fullModel = faker.PredefinedRawSignedModel(null, true, true, true);
            var fullCard = cardManager.ImportCardFromString(fullModel.ExportAsString());

            data.Add("STC-4.as_string", cardManager.ExportCardAsString(fullCard));
            data.Add("STC-4.as_json", cardManager.ExportCardAsJson(fullCard));
            data.Add("STC-4.card_id", fullCard.Id);
            data.Add("STC-4.public_key_base64", Bytes.ToString(crypto.ExportPublicKey(fullCard.PublicKey),
                                                               StringEncoding.BASE64));
            foreach (var signature in fullCard.Signatures)
            {
                data.Add($"STC-4.signature_{signature.Signer}_base64", Bytes.ToString(signature.Signature,
                                                                                      StringEncoding.BASE64));
            }

            string apiPublicKeyId;
            string apiPublicKeyBase64;
            var    jwtTuple = faker.PredefinedToken(
                new VirgilAccessTokenSigner(),
                TimeSpan.FromMinutes(10),
                out apiPublicKeyId,
                out apiPublicKeyBase64);

            data.Add("STC-22.jwt", jwtTuple.Item1.ToString());
            data.Add("STC-22.api_public_key_base64", apiPublicKeyBase64);
            data.Add("STC-22.api_key_id", apiPublicKeyId);


            data.Add("STC-23.api_public_key_base64", apiPublicKeyBase64);
            data.Add("STC-23.api_key_id", apiPublicKeyId);
            data.Add("STC-23.app_id", jwtTuple.Item2.AppId);

            data.Add("STC-23.api_private_key_base64", Bytes.ToString(
                         crypto.ExportPrivateKey(jwtTuple.Item2.ApiKey), StringEncoding.BASE64));

            // STC-10
            var cardKeyPair     = crypto.GenerateKeys();
            var cardIdentity    = faker.Random.AlphaNumeric(10);
            var rawCardContent1 = new RawCardContent()
            {
                CreatedAt = DateTime.UtcNow,
                Identity  = cardIdentity,
                PublicKey = crypto.ExportPublicKey(cardKeyPair.PublicKey),
                Version   = "5.0",
            };
            var rawSignedModel = new RawSignedModel()
            {
                ContentSnapshot = SnapshotUtils.TakeSnapshot(rawCardContent1)
            };

            var signer = new ModelSigner(new VirgilCardCrypto());

            signer.SelfSign(rawSignedModel, cardKeyPair.PrivateKey);


            var keyPair = crypto.GenerateKeys();

            signer.Sign(rawSignedModel, new SignParams()
            {
                SignerPrivateKey = keyPair.PrivateKey,
                Signer           = "extra"
            });
            data.Add("STC-10.private_key1_base64", Bytes.ToString(
                         crypto.ExportPrivateKey(keyPair.PrivateKey), StringEncoding.BASE64));

            var accessTokenGenerator = new JwtGenerator(
                AppSettings.AppId,
                IntegrationHelper.ApiPrivateKey(),
                AppSettings.ApiPublicKeyId,
                TimeSpan.FromMinutes(10),
                new VirgilAccessTokenSigner()
                );
            var accessTokenProvider = Substitute.For <IAccessTokenProvider>();

            accessTokenProvider.GetTokenAsync(Arg.Any <TokenContext>()).Returns(
                accessTokenGenerator.GenerateToken(cardIdentity)
                );
            var validator = new VirgilCardVerifier(new VirgilCardCrypto())
            {
                VerifySelfSignature = true, VerifyVirgilSignature = true
            };

            validator.ChangeServiceCreds(AppSettings.ServicePublicKeyDerBase64);
            var manager = new CardManager(new CardManagerParams()
            {
                CardCrypto          = new VirgilCardCrypto(),
                AccessTokenProvider = accessTokenProvider,
                ApiUrl   = AppSettings.CardsServiceAddress,
                Verifier = validator
            });

            card = await manager.PublishCardAsync(rawSignedModel);

            data.Add("STC-10.as_string", manager.ExportCardAsString(card));


            // STC - 11
            rawSignedModel = faker.PredefinedRawSignedModel(null, false, false, false);
            data.Add("STC-11.as_string", rawSignedModel.ExportAsString());

            // STC - 12
            rawSignedModel = faker.PredefinedRawSignedModel(null, true, false, false);
            data.Add("STC-12.as_string", rawSignedModel.ExportAsString());

            // STC - 14
            rawSignedModel = faker.PredefinedRawSignedModel(null, false, true, false);
            data.Add("STC-14.as_string", rawSignedModel.ExportAsString());

            // STC - 15
            rawSignedModel = faker.PredefinedRawSignedModel(null, false, false, false);
            keyPair        = crypto.GenerateKeys();
            signer.Sign(rawSignedModel, new SignParams()
            {
                SignerPrivateKey = keyPair.PrivateKey,
                Signer           = "self"
            });
            data.Add("STC-15.as_string", rawSignedModel.ExportAsString());

            // STC - 16
            rawSignedModel = faker.PredefinedRawSignedModel(null, true, true, false);
            keyPair        = crypto.GenerateKeys();
            signer.Sign(rawSignedModel, new SignParams()
            {
                SignerPrivateKey = keyPair.PrivateKey,
                Signer           = "extra"
            });
            data.Add("STC-16.as_string", rawSignedModel.ExportAsString());
            data.Add("STC-16.public_key1_base64", Bytes.ToString(
                         crypto.ExportPublicKey(keyPair.PublicKey), StringEncoding.BASE64));

            // STC - 28
            jwtTuple = faker.PredefinedToken(
                new VirgilAccessTokenSigner(),
                TimeSpan.FromMinutes(2),
                out apiPublicKeyId,
                out apiPublicKeyBase64);
            data.Add("STC-28.jwt", jwtTuple.Item1.ToString());
            data.Add("STC-28.jwt_identity", jwtTuple.Item1.BodyContent.Identity);
            data.Add("STC-28.jwt_app_id", jwtTuple.Item1.BodyContent.AppId);
            data.Add("STC-28.jw_issuer", jwtTuple.Item1.BodyContent.Issuer);
            data.Add("STC-28.jwt_subject", jwtTuple.Item1.BodyContent.Subject);
            data.Add("STC-28.jwt_additional_data", Configuration.Serializer.Serialize(jwtTuple.Item1.BodyContent.AdditionalData));
            data.Add("STC-28.jwt_expires_at", Configuration.Serializer.Serialize(jwtTuple.Item1.BodyContent.ExpiresAt));
            data.Add("STC-28.jwt_issued_at", Configuration.Serializer.Serialize(jwtTuple.Item1.BodyContent.IssuedAt));
            data.Add("STC-28.jwt_algorithm", jwtTuple.Item1.HeaderContent.Algorithm);
            data.Add("STC-28.jwt_api_key_id", jwtTuple.Item1.HeaderContent.KeyId);
            data.Add("STC-28.jwt_content_type", jwtTuple.Item1.HeaderContent.ContentType);
            data.Add("STC-28.jwt_type", jwtTuple.Item1.HeaderContent.Type);
            data.Add("STC-28.jwt_signature_base64", Bytes.ToString(jwtTuple.Item1.SignatureData, StringEncoding.BASE64));


            // STC - 29
            jwtTuple = faker.PredefinedToken(
                new VirgilAccessTokenSigner(),
                TimeSpan.FromDays(365),
                out apiPublicKeyId,
                out apiPublicKeyBase64);
            data.Add("STC-29.jwt", jwtTuple.Item1.ToString());
            data.Add("STC-29.jwt_identity", jwtTuple.Item1.BodyContent.Identity);
            data.Add("STC-29.jwt_app_id", jwtTuple.Item1.BodyContent.AppId);
            data.Add("STC-29.jw_issuer", jwtTuple.Item1.BodyContent.Issuer);
            data.Add("STC-29.jwt_subject", jwtTuple.Item1.BodyContent.Subject);
            data.Add("STC-29.jwt_additional_data", Configuration.Serializer.Serialize(jwtTuple.Item1.BodyContent.AdditionalData));
            data.Add("STC-29.jwt_expires_at", Configuration.Serializer.Serialize(jwtTuple.Item1.BodyContent.ExpiresAt));
            data.Add("STC-29.jwt_issued_at", Configuration.Serializer.Serialize(jwtTuple.Item1.BodyContent.IssuedAt));
            data.Add("STC-29.jwt_algorithm", jwtTuple.Item1.HeaderContent.Algorithm);
            data.Add("STC-29.jwt_api_key_id", jwtTuple.Item1.HeaderContent.KeyId);
            data.Add("STC-29.jwt_content_type", jwtTuple.Item1.HeaderContent.ContentType);
            data.Add("STC-29.jwt_type", jwtTuple.Item1.HeaderContent.Type);
            data.Add("STC-29.jwt_signature_base64", Bytes.ToString(jwtTuple.Item1.SignatureData, StringEncoding.BASE64));


            // STC - 34
            keyPair = crypto.GenerateKeys();
            var rawCardContent = new RawCardContent()
            {
                CreatedAt = DateTime.UtcNow,
                Identity  = "test",
                PublicKey = crypto.ExportPublicKey(keyPair.PublicKey),
                Version   = "5.0"
            };

            model = new RawSignedModel()
            {
                ContentSnapshot = SnapshotUtils.TakeSnapshot(rawCardContent)
            };

            signer.SelfSign(
                model, keyPair.PrivateKey, new Dictionary <string, string>()
            {
                { "info", "some_additional_info" }
            }
                );

            data.Add("STC-34.private_key_base64", Bytes.ToString(
                         crypto.ExportPrivateKey(keyPair.PrivateKey), StringEncoding.BASE64));
            data.Add("STC-34.public_key_base64", Bytes.ToString(
                         crypto.ExportPublicKey(keyPair.PublicKey), StringEncoding.BASE64));
            data.Add("STC-34.self_signature_snapshot_base64",
                     Bytes.ToString(model.Signatures.First().Snapshot, StringEncoding.BASE64));
            data.Add("STC-34.content_snapshot_base64",
                     Bytes.ToString(
                         SnapshotUtils.TakeSnapshot(rawCardContent), StringEncoding.BASE64));
            data.Add("STC-34.as_string", model.ExportAsString());

            System.IO.File.WriteAllText(AppSettings.OutputTestDataPath,
                                        Configuration.Serializer.Serialize(data));
        }