private Claim CreateClaim(string claimType, string claimValue, string claimProperty, string claimPropertyValue)
        {
            var claim = new Claim(claimType, claimValue);
            claim.Properties[claimProperty] = claimPropertyValue;

            return claim;
        }
        /// <summary>
        /// Do a deep-copy of IClaimsIdentity except the issuer.
        /// </summary>
        /// <param name="srcIdentity">Source Identity.</param>
        /// <param name="dstIdentity">Destination Identity.</param>
        private void CopyClaims(IClaimsIdentity srcIdentity, IClaimsIdentity dstIdentity)
        {
            foreach (Claim claim in srcIdentity.Claims)
            {
                // We don't copy the issuer because it is not needed in this case. The STS always issues claims
                // using its own identity.
                Claim newClaim = new Claim(claim.ClaimType, claim.Value, claim.ValueType);

                // copy all claim properties
                foreach (string key in claim.Properties.Keys)
                {
                    newClaim.Properties.Add(key, claim.Properties[key]);
                }

                // add claim to the destination identity
                dstIdentity.Claims.Add(newClaim);
            }

            // Recursively copy claims from the source identity delegates
            if (srcIdentity.Actor != null)
            {
                dstIdentity.Actor = new ClaimsIdentity();
                CopyClaims(srcIdentity.Actor, dstIdentity.Actor);
            }
        }
Beispiel #3
0
        // print a compact display of the supplied claim
        private static void logClaim(Claim c, CustomTextTraceSource ts)
        {
            string claimType = c.ClaimType;
            string value = c.Value;

            ts.TraceInformation(CLAIM_FORMAT_STRING, c.Subject, claimType, value);

            if (claimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint")
            {
                //value = Base64Util.DecodeFrom64(value);

                X509Certificate2 cert = CertificateUtil.GetCertificateByThumbprint(StoreName.TrustedPeople, StoreLocation.LocalMachine, value);
                //X509Certificate2 cert = CertificateUtil.GetCertificateByCommonName(StoreName.TrustedPeople, StoreLocation.LocalMachine, "HA50WSC");
                //X509Certificate2 cert = System.ServiceModel.EndpointIdentity.CreateX509CertificateIdentity((X509Certificate2)c.Subject.Actor);

                if (cert != null)
                {
                    ts.TraceInformation("X509Certificate2: " + cert.Subject);
                    //file.WriteLine("X509Certificate2: " + cert.Thumbprint);
                    //file.WriteLine("X509Certificate2 H: " + cert.GetCertHashString());
                    //file.WriteLine("X509Certificate2 H64: " + cert.GetCertHash().ToString());
                    //file.WriteLine("X509Certificate2 D: " + Base64Util.DecodeFrom64(cert.Thumbprint));

                    //file.WriteLine("X509Certificate2 D: " + Base64Util.EncodeTo64(cert.GetCertHash()));
                }
                else
                {
                    ts.TraceInformation("X509Certificate2: " + "NULL");
                }

            }


        }