Exemple #1
0
        public IdentityConfiguration(bool loadConfig)
        {
            if (loadConfig)
            {
                var section = SustainsysSaml2Section.Current;
                if (section == null)
                {
                    throw new InvalidOperationException("No sustainsys.saml2 configuration element was found");
                }

                IdentityConfigurationElement element = section
                                                       .IdentityConfigurations
                                                       .IdentityConfigurationsCollection
                                                       .GetElement(DefaultServiceName);
                LoadConfiguration(element);
            }
            else
            {
                LoadConfiguration(null);
            }

            if (serviceHandlerConfiguration == null)
            {
                serviceHandlerConfiguration = new SecurityTokenHandlerConfiguration();
                serviceHandlerConfiguration.MaxClockSkew = DefaultMaxClockSkew;
            }
        }
Exemple #2
0
        protected void LoadConfiguration(IdentityConfigurationElement element)
        {
            if (element == null)
            {
                return;
            }

            if (element.ClaimsAuthenticationManager.Type != null)
            {
                claimsAuthenticationManager = (ClaimsAuthenticationManager)Activator.CreateInstance(
                    element.ClaimsAuthenticationManager.Type);
            }
            name = element.Name;

            serviceHandlerConfiguration = LoadHandlerConfiguration(element);
        }
Exemple #3
0
        protected SecurityTokenHandlerConfiguration LoadHandlerConfiguration(IdentityConfigurationElement element)
        {
            SecurityTokenHandlerConfiguration handlerConfiguration = new SecurityTokenHandlerConfiguration()
            {
                MaxClockSkew         = element.MaximumClockSkew,
                SaveBootstrapContext = element.SaveBootstrapContext
            };

            if (element.AudienceUris != null)
            {
                handlerConfiguration.AudienceRestriction.AudienceMode = element.AudienceUris.Mode;
                foreach (AudienceUriElement audienceUriElement in element.AudienceUris)
                {
                    handlerConfiguration.AudienceRestriction.AllowedAudienceUris.Add(
                        new Uri(audienceUriElement.Value, UriKind.RelativeOrAbsolute));
                }
            }
            if (element.Caches != null)
            {
                if (element.Caches.TokenReplayCache != null &&
                    element.Caches.TokenReplayCache.Type != null)
                {
                    handlerConfiguration.TokenReplayCache = (ITokenReplayCache)
                                                            Activator.CreateInstance(element.Caches.TokenReplayCache.Type);
                }
            }
            if (element.TokenReplayDetection != null)
            {
                handlerConfiguration.TokenReplayCacheExpirationPeriod =
                    element.TokenReplayDetection.ExpirationPeriod;
                handlerConfiguration.DetectReplayedTokens =
                    element.TokenReplayDetection.Enabled;

                if (handlerConfiguration.TokenReplayCache == null)
                {
                    TimeSpan?expiryTime = null;
                    if (handlerConfiguration.TokenReplayCacheExpirationPeriod > TimeSpan.Zero &&
                        handlerConfiguration.TokenReplayCacheExpirationPeriod < TimeSpan.MaxValue)
                    {
                        expiryTime = handlerConfiguration.TokenReplayCacheExpirationPeriod;
                    }
                    handlerConfiguration.TokenReplayCache = new TokenReplayCache(expiryTime);
                }
            }

            return(handlerConfiguration);
        }