static void InitStore() { SigningCertificate = CertificateHelper.CreateSelfSignedCertificate( "ADFS Signing - " + EnvironmentConfig.ADFSFamrDNSName); if (System.IO.File.Exists(dataStoreFile)) { dataStore.Load(dataStoreFile); } else if (dataStore.DocumentElement == null) { dataStore.AppendChild(dataStore.CreateElement("Root")); XmlNode defaultApp = dataStore.CreateElement("Data"); XmlAttribute attr = dataStore.CreateAttribute("key"); attr.Value = managedAppsRecord; defaultApp.Attributes.Append(attr); attr = dataStore.CreateAttribute("version"); attr.Value = "-1"; defaultApp.Attributes.Append(attr); attr = dataStore.CreateAttribute("value"); RelyingPartyTrust[] relies = new RelyingPartyTrust[1]; relies[0] = createInitialRelyingPartyTrust(managedApp1Name, managedApp1Id); attr.Value = JsonUtility.SerializeJSON(relies); defaultApp.Attributes.Append(attr); dataStore.DocumentElement.AppendChild(defaultApp); } }
static RelyingPartyTrust createInitialRelyingPartyTrust(string name, string identifier) { RelyingPartyTrust ret = new RelyingPartyTrust(); ret.name = name; ret.objectIdentifier = identifier; ret.enabled = true; return(ret); }
/// <summary> /// Initializes relying parties. /// </summary> private void InitializeRelyingParties(bool published = false) { var relyingParty = new RelyingPartyTrust { name = EnvironmentConfig.App1Name, objectIdentifier = TestEndpointGuid1, enabled = true, nonClaimsAware = false, publishedThroughProxy = false }; //add nonClaimsAware var nonRP = new RelyingPartyTrust { name = EnvironmentConfig.App2Name, objectIdentifier = TestEndpointGuid2, enabled = true, nonClaimsAware = true, publishedThroughProxy = false }; if (published) { relyingParty.publishedThroughProxy = true; relyingParty.proxyTrustedEndpoints = new[] { EnvironmentConfig.App1Url }; relyingParty.proxyEndpointMappings = new[] { new ProxyEndpointMapping { Key = EnvironmentConfig.App1Url, Value = EnvironmentConfig.App1Url } }; nonRP.publishedThroughProxy = true; nonRP.proxyTrustedEndpoints = new[] { EnvironmentConfig.App2Url }; nonRP.proxyEndpointMappings = new[] { new ProxyEndpointMapping { Key = EnvironmentConfig.App2Url, Value = EnvironmentConfig.App2Url } }; } _relyingPartyTrust = new List <RelyingPartyTrust> { relyingParty, nonRP }; }
public static PortableRelyingParty FromRelyingPartyTrust(RelyingPartyTrust relyingPartyTrust) { var source = relyingPartyTrust; var target = new PortableRelyingParty(); target.AutoUpdateEnabled = source.AutoUpdateEnabled; target.ClaimsAccepted = (source.ClaimsAccepted ?? new ClaimDescription[0]).Select(SerializableClaimDescription.FromClaimDescription).ToList(); target.ConflictWithPublishedPolicy = source.ConflictWithPublishedPolicy; target.DelegationAuthorizationRules = source.DelegationAuthorizationRules; target.Enabled = source.Enabled; target.EncryptClaims = source.EncryptClaims; target.EncryptedNameIdRequired = source.EncryptedNameIdRequired; target.EncryptionCertificate = source.EncryptionCertificate; target.EncryptionCertificateRevocationCheck = source.EncryptionCertificateRevocationCheck; target.Identifier = source.Identifier; target.ImpersonationAuthorizationRules = source.ImpersonationAuthorizationRules; target.IssuanceAuthorizationRules = source.IssuanceAuthorizationRules; target.IssuanceTransformRules = source.IssuanceTransformRules; target.LastMonitoredTime = source.LastMonitoredTime; target.LastPublishedPolicyCheckSuccessful = source.LastPublishedPolicyCheckSuccessful; target.LastUpdateTime = source.LastUpdateTime; target.MetadataUrl = source.MetadataUrl; target.MonitoringEnabled = source.MonitoringEnabled; target.Name = source.Name; target.NotBeforeSkew = source.NotBeforeSkew; target.Notes = source.Notes; target.OrganizationInfo = source.OrganizationInfo; target.ProtocolProfile = source.ProtocolProfile; target.RequestSigningCertificate = (source.RequestSigningCertificate ?? new ReadOnlyCollection <X509Certificate2>(new X509Certificate2[0])).ToArray(); target.SamlEndpoints = (source.SamlEndpoints ?? new SamlEndpoint[0]).Select(SerializableSamlEndpoint.FromSamlEndpoint).ToList(); target.SamlResponseSignature = source.SamlResponseSignature; target.SignatureAlgorithm = source.SignatureAlgorithm; target.SignedSamlRequestsRequired = source.SignedSamlRequestsRequired; target.SigningCertificateRevocationCheck = source.SigningCertificateRevocationCheck; target.TokenLifetime = source.TokenLifetime; target.WSFedEndpoint = source.WSFedEndpoint; return(target); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: GetRelyingParty name"); return; } GetRelyingPartyTrustCommand getRelyingPartyTrustCommand = new GetRelyingPartyTrustCommand(); getRelyingPartyTrustCommand.Name = new string[1]; getRelyingPartyTrustCommand.Name[0] = args[0]; // salesforce iHCP IEnumerable result = getRelyingPartyTrustCommand.Invoke(); RelyingPartyTrust rp = null; foreach (object obj in result) { rp = obj as RelyingPartyTrust; break; } if (rp == null) { Console.WriteLine("No relying party found."); return; } XElement relyingPartyTrustXml = new XElement("RelyingPartyTrust"); XElement nameXml = new XElement("Name", rp.Name); relyingPartyTrustXml.Add(nameXml); XElement identifiersXml = new XElement("Identifiers"); int i = 0; foreach (string identifier in rp.Identifier) { XElement identifierXml = new XElement("Identifier", rp.Identifier[i++]); identifiersXml.Add(identifierXml); } relyingPartyTrustXml.Add(identifiersXml); XElement samlEndpointsXml = new XElement("SamlEndpoints"); foreach (SamlEndpoint samlEndpoint in rp.SamlEndpoints) { XElement samlEndpointXml = new XElement("SamlEndpoint", new XElement("Binding", samlEndpoint.Binding), new XElement("Protocol", samlEndpoint.Protocol), new XElement("Index", samlEndpoint.Index), new XElement("IsDefault", samlEndpoint.IsDefault), new XElement("Location", samlEndpoint.Location == null ? null : samlEndpoint.Location.ToString()), new XElement("ResponseLocation", samlEndpoint.ResponseLocation == null ? null : samlEndpoint.ResponseLocation.ToString()) ); samlEndpointsXml.Add(samlEndpointXml); } relyingPartyTrustXml.Add(samlEndpointsXml); XElement wsFedEndpointXml = new XElement("WsFedEndpoint", rp.WSFedEndpoint == null ? null : rp.WSFedEndpoint.ToString()); relyingPartyTrustXml.Add(wsFedEndpointXml); XElement autoUpdateEnabledXml = new XElement("AutoUpdateEnabled", rp.AutoUpdateEnabled); relyingPartyTrustXml.Add(autoUpdateEnabledXml); XElement monitoringEnabledXml = new XElement("MonitoringEnabled", rp.MonitoringEnabled); relyingPartyTrustXml.Add(monitoringEnabledXml); XElement metadataUrlXml = new XElement("MetadataUrl", rp.MetadataUrl == null ? null : rp.MetadataUrl.ToString()); relyingPartyTrustXml.Add(metadataUrlXml); XElement signatureAlgorithmXml = new XElement("SignatureAlgorithm", rp.SignatureAlgorithm); relyingPartyTrustXml.Add(signatureAlgorithmXml); XElement requestSigningCertificatesXml = new XElement("RequestSigningCertificates"); foreach (X509Certificate2 x509Certificate2 in rp.RequestSigningCertificate) { // x509Certificate2.RawData contains ASN.1 DER data XElement requestSigningCertificateXml = new XElement("RequestSigningCertificate", Convert.ToBase64String(x509Certificate2.RawData)); requestSigningCertificatesXml.Add(requestSigningCertificateXml); } relyingPartyTrustXml.Add(requestSigningCertificatesXml); XElement issuanceTransformRulesXml = new XElement("IssuanceTransformRules", rp.IssuanceTransformRules); relyingPartyTrustXml.Add(issuanceTransformRulesXml); XElement issuanceAuthorizationRulesXml = new XElement("IssuanceAuthorizationRules", rp.IssuanceAuthorizationRules); relyingPartyTrustXml.Add(issuanceAuthorizationRulesXml); XElement delegationAuthorizationRulesXml = new XElement("DelegationAuthorizationRules", rp.DelegationAuthorizationRules); relyingPartyTrustXml.Add(delegationAuthorizationRulesXml); XElement encryptClaimsXml = new XElement("EncryptClaims", rp.EncryptClaims); relyingPartyTrustXml.Add(encryptClaimsXml); XElement encryptedNameIdRequiredXml = new XElement("EncryptedNameIdRequired", rp.EncryptedNameIdRequired); relyingPartyTrustXml.Add(encryptedNameIdRequiredXml); XElement encryptionCertificateXml = new XElement("EncryptionCertificate", rp.EncryptionCertificate == null ? null : Convert.ToBase64String(rp.EncryptionCertificate.RawData)); relyingPartyTrustXml.Add(encryptionCertificateXml); XElement encryptionCertificateRevocationCheckXml = new XElement("EncryptionCertificateRevocationCheck", rp.EncryptionCertificateRevocationCheck); relyingPartyTrustXml.Add(encryptionCertificateRevocationCheckXml); XElement notBeforeSkewXml = new XElement("NotBeforeSkew", rp.NotBeforeSkew); relyingPartyTrustXml.Add(notBeforeSkewXml); XElement notesXml = new XElement("Notes", rp.Notes); relyingPartyTrustXml.Add(notesXml); XElement protocolProfileXml = new XElement("ProtocolProfile", rp.ProtocolProfile); relyingPartyTrustXml.Add(protocolProfileXml); XElement samlResponseSignatureXml = new XElement("SamlResponseSignature", rp.SamlResponseSignature); relyingPartyTrustXml.Add(samlResponseSignatureXml); XElement signedSamlRequestsRequiredXml = new XElement("SignedSamlRequestsRequired", rp.SignedSamlRequestsRequired); relyingPartyTrustXml.Add(signedSamlRequestsRequiredXml); XElement signingCertificateRevocationCheckXml = new XElement("SigningCertificateRevocationCheck", rp.SigningCertificateRevocationCheck); relyingPartyTrustXml.Add(signingCertificateRevocationCheckXml); XElement tokenLifetimeXml = new XElement("TokenLifetime", rp.TokenLifetime); relyingPartyTrustXml.Add(tokenLifetimeXml); Console.WriteLine(relyingPartyTrustXml); relyingPartyTrustXml.Save(rp.Name + ".xml"); }