Exemplo n.º 1
0
        /// <summary>
        /// Configures the ACS service namespace with the proper objects for this sample.
        /// </summary>
        /// <remarks>
        /// Existing objects that are needed for this sample will be deleted and recreated.
        /// </remarks>
        static void Main(string[] args)
        {
            const string rpName            = "Federation Sample RP";
            const string rpRealm           = "http://*****:*****@"..\..\..\Certificates\ACS2SigningCertificate.pfx", "password");
            byte[] decryptionCertificate = ManagementServiceHelper.ReadBytesFromPfxFile(@"..\..\..\Certificates\ACS2DecryptionCert.pfx", "password");
            byte[] encryptionCertificate = new X509Certificate2(@"..\..\..\Certificates\WcfServiceCertificate.cer").RawData;

            svc.CreateRelyingPartyKey(relyingParty, signingCertificate, "password", RelyingPartyKeyType.X509Certificate, RelyingPartyKeyUsage.Signing, true);
            svc.CreateRelyingPartyKey(relyingParty, encryptionCertificate, null, RelyingPartyKeyType.X509Certificate, RelyingPartyKeyUsage.Encrypting, true);

            svc.CreateIdentityProviderDecryptionKey(decryptionKeyName, decryptionCertificate, "password", true);

            svc.ImportIdentityProviderFromMetadataUrl(new Uri(IdentityProviderMetadataUrl));

            svc.AssociateIdentityProvidersWithRelyingParties(new[] { svc.GetIdentityProviderByName(entityId) }, new[] { relyingParty });

            RuleGroup ruleGroup = svc.CreateRuleGroup(ruleGroupName);

            svc.GenerateRules(ruleGroup, new[] { svc.GetIdentityProviderByName(entityId) });
            svc.AssignRuleGroupToRelyingParty(ruleGroup, relyingParty);

            svc.SaveChangesBatch();

            Console.WriteLine("Sample successfully configured. Press ENTER to continue ...");
            Console.ReadLine();
        }