예제 #1
0
        public static void SaveCardTemplate(InformationCardTemplate card, string templateFilename)
        {
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(card.GetType());
            XmlTextWriter fileWriter = new XmlTextWriter(templateFilename, Encoding.UTF8);

            x.Serialize(fileWriter, card);
            fileWriter.Flush();
            fileWriter.Close();
        }
예제 #2
0
        public static InformationCardTemplate LoadCardTemplate(string templateFileName)
        {
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(InformationCardTemplate));

            XmlTextReader           fileReader = new XmlTextReader(templateFileName);
            InformationCardTemplate ict        = (InformationCardTemplate)x.Deserialize(fileReader);

            return(ict);
        }
예제 #3
0
        private void CreateICToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InformationCardTemplate ict = PopulateCardTemplateFromUI();

            saveFileDialog1.Filter = "Managed Card (*.crd)|*.crd";
            DialogResult dr = saveFileDialog1.ShowDialog();

            string filename = saveFileDialog1.FileName;

            ManagedCardHelper.SaveCardTemplate(ict, filename);
        }
예제 #4
0
        private void btnCreatCard_Click(object sender, EventArgs e)
        {
            InformationCardTemplate ict = PopulateCardTemplateFromUI();

            saveFileDialog1.Filter = "Managed Card (*.crd)|*.crd";
            DialogResult dr = saveFileDialog1.ShowDialog();

            string filename = saveFileDialog1.FileName;

            CertificateInfo certInfo = new CertificateInfo();

            certInfo.CommonName = tbCertificateCommonName.Text;
            certInfo.Location   = tbCertificateLocation.Text;
            certInfo.Store      = tbCertificateStore.Text;
            X509Certificate2 certificate = ManagedCardHelper.RetrieveCertificate(certInfo);

            ManagedCardHelper helper = new ManagedCardHelper();

            helper.SaveCard(ict.InformationCardDefinition, certificate, filename);
        }
예제 #5
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     //InformationCard ic = PopulateCard();
     //ManagedCardHelper.SaveCardTemplate(ic, "C:\\MyCard.crdtemplate");
     InformationCardTemplate ic = ManagedCardHelper.LoadCardTemplate("C:\\MyCard.crdtemplate");
 }
예제 #6
0
        private void PopulateUIFromCardTemplate(string filename)
        {
            InformationCardTemplate ict = ManagedCardHelper.LoadCardTemplate(filename);

            InformationCard ic = ict.InformationCardDefinition;

            tbCardImage.Text           = ic.CardImage.ImageName;
            tbCardName.Text            = ic.CardName;
            tbCardID.Text              = ic.CardReference.CardID;
            tbCardVersion.Text         = ic.CardReference.CardVersion.ToString();
            tbIssuer.Text              = ic.Issuer;
            tbIssuerName.Text          = ic.IssuerName;
            tbPrivacyPolicy.Text       = ic.PrivacyNotice;
            cbRequireAppliesTo.Checked = ic.RequireRPIdentification;
            dtpTimeExpires.Value       = ic.TimeExpires;
            dtpTimeIssued.Value        = ic.TimeIssued;

            foreach (CardClaim cardClaim in ic.SupportedClaimTypeList)
            {
                DataGridViewRow row = new DataGridViewRow();

                DataGridViewTextBoxCell uri         = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell displayTag  = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell description = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell claimValue  = new DataGridViewTextBoxCell();

                uri.Value         = cardClaim.Uri;
                displayTag.Value  = cardClaim.DisplayTag;
                description.Value = cardClaim.Description;
                claimValue.Value  = cardClaim.Value;

                row.Cells.Add(uri);
                row.Cells.Add(displayTag);
                row.Cells.Add(description);
                row.Cells.Add(claimValue);

                dgvClaims.Rows.Add(row);
            }

            cbSAML10.Checked = false;
            cbSAML11.Checked = false;

            foreach (TokenType tokenType in ic.AcceptedTokenTypes)
            {
                if (tokenType.Name == "SAML10")
                {
                    cbSAML10.Checked = true;
                }

                if (tokenType.Name == "SAML11")
                {
                    cbSAML11.Checked = true;
                }
            }

            foreach (TokenService ts in ic.TokenServiceList)
            {
                //Add the token service
                DataGridViewTextBoxCell address               = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell mex                   = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell identity              = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell credentialType        = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell value                 = new DataGridViewTextBoxCell();
                DataGridViewTextBoxCell displayCredentialHint = new DataGridViewTextBoxCell();

                DataGridViewRow row = new DataGridViewRow();

                address.Value  = ts.EndpointReference.Address;
                mex.Value      = ts.EndpointReference.Mex;
                identity.Value = ts.EndpointReference.Identity;


                credentialType.Value        = ts.UserCredential.UserCredentialType.ToString();
                credentialType.Tag          = ts.UserCredential.UserCredentialType;
                value.Value                 = ts.UserCredential.Value;
                displayCredentialHint.Value = ts.UserCredential.DisplayCredentialHint;


                row.Cells.Add(address);
                row.Cells.Add(mex);
                row.Cells.Add(identity);
                row.Cells.Add(credentialType);
                row.Cells.Add(value);
                row.Cells.Add(displayCredentialHint);

                dgvTokenServiceList.Rows.Add(row);
            }

            cbRequireAppliesTo.Checked = ic.RequireRPIdentification;
        }
예제 #7
0
        private InformationCardTemplate PopulateCardTemplateFromUI()
        {
            InformationCard ic = new InformationCard();

            ic.CardImage.ImageName       = tbCardImage.Text;
            ic.CardName                  = tbCardName.Text;
            ic.CardReference.CardID      = tbCardID.Text;
            ic.CardReference.CardVersion = Convert.ToInt32(tbCardVersion.Text);
            ic.Issuer                  = tbIssuer.Text;
            ic.IssuerName              = tbIssuerName.Text;
            ic.PrivacyNotice           = tbPrivacyPolicy.Text;
            ic.RequireRPIdentification = cbRequireAppliesTo.Checked;
            ic.TimeExpires             = dtpTimeExpires.Value;
            ic.TimeIssued              = dtpTimeIssued.Value;

            foreach (DataGridViewRow row in dgvClaims.Rows)
            {
                CardClaim claim = new CardClaim();
                claim.Description = row.Cells["Description"].Value.ToString();
                claim.DisplayTag  = row.Cells["DisplayTag"].Value.ToString();
                claim.Uri         = row.Cells["Uri"].Value.ToString();
                //claim.Value = row.Cells["ClaimValue"].Value.ToString();
                ic.SupportedClaimTypeList.Add(claim);
            }

            if (cbSAML10.Checked)
            {
                TokenType SAML10 = new TokenType();
                SAML10.Name     = "SAML10";
                SAML10.Uri      = "urn:oasis:names:tc:SAML:1.0:assertion";
                SAML10.Accepted = true;
                ic.AcceptedTokenTypes.Add(SAML10);
            }
            if (cbSAML11.Checked)
            {
                TokenType SAML11 = new TokenType();
                SAML11.Name = "SAML11";
                SAML11.Uri  = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
                ic.AcceptedTokenTypes.Add(SAML11);
            }

            foreach (DataGridViewRow tsRow in dgvTokenServiceList.Rows)
            {
                TokenService ts = new TokenService();
                ts.EndpointReference.Address            = tsRow.Cells["Address"].Value.ToString();
                ts.EndpointReference.Identity           = tsRow.Cells["Identity"].Value.ToString();
                ts.EndpointReference.Mex                = tsRow.Cells["Mex"].Value.ToString();
                ts.UserCredential.DisplayCredentialHint = tsRow.Cells["DisplayCredentialHint"].Value.ToString();
                ts.UserCredential.UserCredentialType    = (CredentialType)(tsRow.Cells["CredentialType"].Tag);
                ts.UserCredential.Value = tsRow.Cells["Value"].Value.ToString();
                ic.TokenServiceList.Add(ts);
            }



            InformationCardTemplate ict = new InformationCardTemplate();

            ict.InformationCardDefinition         = ic;
            ict.SigningCertificateInfo.CommonName = tbCertificateCommonName.Text;
            ict.SigningCertificateInfo.Location   = tbCertificateLocation.Text;
            ict.SigningCertificateInfo.Store      = tbCertificateStore.Text;



            return(ict);
        }