// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // TODO: Can I really donate this code? Get approval from Kent and MS LGA. //----------------------------------------------------------------------------- // // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // Copyright (c) Microsoft Corporation. All rights reserved. // // //----------------------------------------------------------------------------- using System.Security.Cryptography.X509Certificates; using System.Web.Configuration; using Microsoft.IdentityModel.Configuration; using Microsoft.IdentityModel.SecurityTokenService; using System.Web; /// /// A custom SecurityTokenServiceConfiguration implementation. /// public class CustomSecurityTokenServiceConfiguration : SecurityTokenServiceConfiguration { private static readonly object syncRoot = new object(); private const string CustomSecurityTokenServiceConfigurationKey = "CustomSecurityTokenServiceConfigurationKey"; /// /// CustomSecurityTokenServiceConfiguration constructor. /// public CustomSecurityTokenServiceConfiguration() : base( WebConfigurationManager.AppSettings[Common.IssuerName], new X509SigningCredentials(CertificateUtil.GetCertificate(StoreName.TrustedPeople, StoreLocation.LocalMachine, WebConfigurationManager.AppSettings[Common.SigningCertificateName]), "http://www.w3.org/2000/09/xmldsig#rsa-sha1", "http://www.w3.org/2000/09/xmldsig#sha1")) { this.SecurityTokenService = typeof(CustomSecurityTokenService); } /// /// Provides a model for creating a single Configuration object for the application. The first call creates a new CustomSecruityTokenServiceConfiguration and /// places it into the current HttpApplicationState using the key "CustomSecurityTokenServiceConfigurationKey". Subsequent calls will return the same /// Configuration object. This maintains any state that is set between calls and improves performance. /// public static CustomSecurityTokenServiceConfiguration Current { get { HttpApplicationState httpAppState = HttpContext.Current.Application; CustomSecurityTokenServiceConfiguration customConfiguration = httpAppState.Get(CustomSecurityTokenServiceConfigurationKey) as CustomSecurityTokenServiceConfiguration; if (customConfiguration == null) { lock (syncRoot) { customConfiguration = httpAppState.Get(CustomSecurityTokenServiceConfigurationKey) as CustomSecurityTokenServiceConfiguration; if (customConfiguration == null) { customConfiguration = new CustomSecurityTokenServiceConfiguration(); httpAppState.Add(CustomSecurityTokenServiceConfigurationKey, customConfiguration); } } } return customConfiguration; } } }