/// <summary>
        /// Import a relying party from a stream.
        /// </summary>
        /// <param name="svc"></param>
        /// <param name="metadataStream">Stream containing the contents of the metadata.</param>
        public static void ImportRelyingPartyFromStream(this ManagementService svc, AccessControlConfiguration acsConfig, Stream metadataStream)
        {
            string metadataImportHead = "v2/mgmt/service/importFederationMetadata/importRelyingParty";
            string metadataImporter   = string.Format("https://{0}.{1}/{2}",
                                                      acsConfig.ServiceNamespace,
                                                      acsConfig.AcsHostUrl,
                                                      metadataImportHead);

            HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(metadataImporter);

            postRequest.Method = "POST";

            ExecuteMetadataImportOperation(acsConfig, postRequest, metadataStream);
        }
        private static void ExecuteMetadataImportOperation(AccessControlConfiguration acsConfig, HttpWebRequest postRequest, Stream metadataStream)
        {
            new ManagementServiceHelper(acsConfig).AddTokenWithWritePermission(postRequest);

            using (Stream postStream = postRequest.GetRequestStream())
            {
                int nextByte = metadataStream.ReadByte();
                while (nextByte != -1)
                {
                    postStream.WriteByte((byte)nextByte);
                    nextByte = metadataStream.ReadByte();
                }
            }

            HttpWebResponse resp = (HttpWebResponse)postRequest.GetResponse();
        }
Esempio n. 3
0
 public ManagementServiceHelper(AccessControlConfiguration acsConfig)
 {
     _acsConfig = acsConfig;
 }
        /// <summary>
        /// Import an identity provider from a stream, specifying an optional metadata source.
        /// </summary>
        /// <param name="svc"></param>
        /// <param name="metadataStream">Stream containing the contents of the metadata.</param>
        /// <param name="metadataSource">Optional: if metadata is from a URI, this will be recorded as an IdentityProviderAddress.</param>
        public static void ImportIdentityProviderFromStream(this ManagementService svc, AccessControlConfiguration acsConfig, Stream metadataStream, Uri metadataSource)
        {
            string metadataImportHead = "v2/mgmt/service/importFederationMetadata/importIdentityProvider";
            string metadataImporter   = string.Format("https://{0}.{1}/{2}",
                                                      acsConfig.ServiceNamespace,
                                                      acsConfig.AcsHostUrl,
                                                      metadataImportHead);

            HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(metadataImporter);

            postRequest.Method = "POST";

            if (metadataSource != null)
            {
                postRequest.Headers["metadataUrl"] = metadataSource.OriginalString;
            }

            ExecuteMetadataImportOperation(acsConfig, postRequest, metadataStream);
        }
 /// <summary>
 /// Import an identity provider from a stream.
 /// </summary>
 /// <param name="svc"></param>
 /// <param name="metadataStream">Stream containing the contents of the metadata.</param>
 public static void ImportIdentityProviderFromStream(this ManagementService svc, AccessControlConfiguration acsConfig, Stream metadataStream)
 {
     ImportIdentityProviderFromStream(svc, acsConfig, metadataStream, null);
 }
        /// <summary>
        /// Import an identity provider from the given Federation Metadata URL
        /// </summary>
        /// <param name="metadataUrl"></param>
        public static void ImportIdentityProviderFromMetadataUrl(this ManagementService svc, AccessControlConfiguration acsConfig, Uri metadataUrl)
        {
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(metadataUrl);

            getRequest.Method = "GET";
            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();

            using (Stream getStream = getResponse.GetResponseStream())
            {
                ImportIdentityProviderFromStream(svc, acsConfig, getStream, metadataUrl);
            }
        }