Пример #1
0
        private bool ProcessCertificateDownloadRequest()
        {
            if (Thread.CurrentPrincipal.Identity.IsAuthenticated && Thread.CurrentPrincipal.Identity is IClaimsIdentity)
            {
                if (!string.IsNullOrEmpty(this.Page.Request.QueryString["___stvc___"]))
                {
                    if (this.Page.Request.QueryString["___stvc___"] == "signcert")
                    {
                        var tokenVisualizer = TokenVisualizerFactory.GetTokenVisualizer(((IClaimsIdentity)Thread.CurrentPrincipal.Identity).BootstrapToken);
                        var certificate     = tokenVisualizer.RetrieveIssuerCertificate();

                        if (certificate != null)
                        {
                            this.RespondCertificate(certificate);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        private void AddSamlTokenTable(HtmlControl container)
        {
            HtmlTable table           = CreateTable(container);
            var       tokenVisualizer = TokenVisualizerFactory.GetTokenVisualizer(
                ((IClaimsPrincipal)Thread.CurrentPrincipal).Identities.First().BootstrapToken);

            AddTableSectionHeader(table, Resources.SamlToken, string.Empty);

            string tokenTextAreaId = string.Format(CultureInfo.InvariantCulture, "{0}_samlToken", this.ID);

            HtmlTextArea tokenTextArea = new HtmlTextArea()
            {
                ID = tokenTextAreaId, InnerText = tokenVisualizer.SecurityTokenString
            };

            tokenTextArea.Attributes["class"]    = "SAMLToken";
            tokenTextArea.Attributes["readonly"] = "true";

            HtmlControl samlTokenHeader = this.CreateCollapsableHeader(Resources.RawSamlToken, tokenTextArea, false /* Expanded as Default */);

            HtmlTableRow  row       = new HtmlTableRow();
            HtmlTableCell tokenCell = new HtmlTableCell {
                ColSpan = TableColumnsQuantity
            };

            tokenCell.Controls.Add(samlTokenHeader);
            tokenCell.Controls.Add(tokenTextArea);
            row.Cells.Add(tokenCell);
            table.Rows.Add(row);

            AddColumnHeadersToTable(table, new[] { Resources.TokenPropertyName, Resources.TokenPropertyValue });

            foreach (var entry in tokenVisualizer.RetrieveTokenProperties())
            {
                AddTokenProperty(table, entry.Key, entry.Value);
            }
        }