public void BuildAuthnRequest_test_requested_authn_context_default_overwritten_multiple_contexts()
        {
            //ARRANGE
            var requestUri = new Uri("http://localhost:59611/");
            var federationPartyContextBuilder      = new FederationPartyContextBuilderMock();
            var requestedAuthnContextConfiguration = new RequestedAuthnContextConfiguration(AuthnContextComparisonType.Minimum.ToString());

            requestedAuthnContextConfiguration.RequestedAuthnContexts.Add((new Kernel.Federation.Protocols.AuthnContext(AuthnContextType.AuthnContextClassRef.ToString(), new Uri(AuthnticationContexts.Password))));
            requestedAuthnContextConfiguration.RequestedAuthnContexts.Add((new Kernel.Federation.Protocols.AuthnContext(AuthnContextType.AuthnContextClassRef.ToString(), new Uri(AuthnticationContexts.PasswordProtectedTransport))));
            var federationContex = federationPartyContextBuilder.BuildContext("local", requestedAuthnContextConfiguration);

            var supportedNameIdentifierFormats = new List <Uri> {
                new Uri(NameIdentifierFormats.Transient)
            };
            var authnRequestContext  = new AuthnRequestContext(requestUri, new Uri("http://localhost"), federationContex, supportedNameIdentifierFormats);
            var requestConfiguration = federationContex.GetAuthnRequestConfigurationFromContext(Guid.NewGuid().ToString());

            RequestHelper.GetAuthnRequestBuilders = AuthnRequestBuildersFactoryMock.GetAuthnRequestBuildersFactory();
            //ACT
            var authnRequest = RequestHelper.BuildRequest(authnRequestContext) as AuthnRequest;

            //ASSERT
            Assert.NotNull(authnRequest);
            Assert.IsNotNull(authnRequest.RequestedAuthnContext);
            Assert.AreEqual(AuthnContextComparisonType.Minimum, authnRequest.RequestedAuthnContext.Comparison);
            Assert.AreEqual(2, authnRequest.RequestedAuthnContext.Items.Length);
            Assert.AreEqual(2, authnRequest.RequestedAuthnContext.ItemsElementName.Length);
            Assert.AreEqual(AuthnContextType.AuthnContextClassRef, authnRequest.RequestedAuthnContext.ItemsElementName[0]);
            Assert.AreEqual(AuthnticationContexts.Password, authnRequest.RequestedAuthnContext.Items[0]);
            Assert.AreEqual(AuthnContextType.AuthnContextClassRef, authnRequest.RequestedAuthnContext.ItemsElementName[1]);
            Assert.AreEqual(AuthnticationContexts.PasswordProtectedTransport, authnRequest.RequestedAuthnContext.Items[1]);
        }
Пример #2
0
 public FederationPartyAuthnRequestConfiguration(RequestedAuthnContextConfiguration requestedAuthnContextConfiguration, DefaultNameId defaultNameId, ScopingConfiguration scopingConfiguration)
 {
     this.RequestedAuthnContextConfiguration = requestedAuthnContextConfiguration;
     this.DefaultNameId        = defaultNameId;
     this.ScopingConfiguration = scopingConfiguration;
     this.Version                = "2.0";
     this.IsPassive              = false;
     this.ForceAuthn             = false;
     this.AssertionIndexEndpoint = 0;
 }
        private FederationPartyAuthnRequestConfiguration BuildFederationPartyAuthnRequestConfiguration(AutnRequestSettings autnRequestSettings, string entityId)
        {
            if (autnRequestSettings == null)
            {
                throw new ArgumentNullException("autnRequestSettings");
            }

            RequestedAuthnContextConfiguration requestedAuthnContextConfiguration = null;

            if (autnRequestSettings.RequitedAutnContext != null)
            {
                requestedAuthnContextConfiguration = new RequestedAuthnContextConfiguration(autnRequestSettings.RequitedAutnContext.Comparison.ToString());
                autnRequestSettings.RequitedAutnContext.RequitedAuthnContexts.Aggregate(requestedAuthnContextConfiguration.RequestedAuthnContexts, (t, next) =>
                {
                    t.Add(new Kernel.Federation.Protocols.AuthnContext(next.RefType.ToString(), new Uri(next.Value)));
                    return(t);
                });
            }
            if (autnRequestSettings.NameIdConfiguration == null)
            {
                throw new ArgumentNullException("nameIdConfiguration");
            }
            var defaultNameUri = autnRequestSettings.NameIdConfiguration.DefaultNameIdFormat != null ? autnRequestSettings.NameIdConfiguration.DefaultNameIdFormat.Uri : NameIdentifierFormats.Unspecified;
            var defaultNameId  = new DefaultNameId(new Uri(defaultNameUri))
            {
                AllowCreate   = autnRequestSettings.NameIdConfiguration.AllowCreate,
                EncryptNameId = autnRequestSettings.NameIdConfiguration.EncryptNameId
            };
            var scopingConfiguration = autnRequestSettings.Scoping == null ? (ScopingConfiguration)null
                    : new ScopingConfiguration(entityId)
            {
                PoxyCount = autnRequestSettings.Scoping.MaxProxyCount
            };

            var configuration = new FederationPartyAuthnRequestConfiguration(requestedAuthnContextConfiguration, defaultNameId, scopingConfiguration)
            {
                ForceAuthn = autnRequestSettings.ForceAuthn,
                IsPassive  = autnRequestSettings.IsPassive,
                Version    = autnRequestSettings.Version ?? "2.0"
            };

            return(configuration);
        }
Пример #4
0
        private FederationPartyAuthnRequestConfiguration BuildFederationPartyAuthnRequestConfiguration(AutnRequestSettings autnRequestSettings)
        {
            if (autnRequestSettings == null)
            {
                throw new ArgumentNullException("autnRequestSettings");
            }
            if (autnRequestSettings.RequitedAutnContext == null)
            {
                throw new ArgumentNullException("requitedAutnContext");
            }

            var requestedAuthnContextConfiguration = new RequestedAuthnContextConfiguration(autnRequestSettings.RequitedAutnContext.Comparison.ToString());

            autnRequestSettings.RequitedAutnContext.RequitedAuthnContexts.Aggregate(requestedAuthnContextConfiguration.RequestedAuthnContexts, (t, next) =>
            {
                t.Add(new Kernel.Federation.Protocols.AuthnContext(next.RefType.ToString(), new Uri(next.Value)));
                return(t);
            });
            if (autnRequestSettings.NameIdConfiguration == null)
            {
                throw new ArgumentNullException("nameIdConfiguration");
            }

            var defaultNameId = new DefaultNameId(new Uri(autnRequestSettings.NameIdConfiguration.DefaultNameIdFormat.Uri))
            {
                AllowCreate   = autnRequestSettings.NameIdConfiguration.AllowCreate,
                EncryptNameId = autnRequestSettings.NameIdConfiguration.EncryptNameId
            };
            var configuration = new FederationPartyAuthnRequestConfiguration(requestedAuthnContextConfiguration, defaultNameId)
            {
                ForceAuthn = autnRequestSettings.ForceAuthn,
                IsPassive  = autnRequestSettings.IsPassive,
                Version    = autnRequestSettings.Version ?? "2.0"
            };

            return(configuration);
        }
Пример #5
0
 public FederationPartyAuthnRequestConfiguration(RequestedAuthnContextConfiguration requestedAuthnContextConfiguration, DefaultNameId defaultNameId)
 {
     this.RequestedAuthnContextConfiguration = requestedAuthnContextConfiguration;
     this.DefaultNameId = defaultNameId;
 }
Пример #6
0
        public FederationPartyConfiguration BuildContext(string federationPartyId, string defaultNameIdFormat, ScopingConfiguration scopingConfiguration, RequestedAuthnContextConfiguration requestedAuthnContextConfiguration)
        {
            var nameIdconfiguration = new DefaultNameId(new Uri(defaultNameIdFormat));
            var federationPartyAuthnRequestConfiguration = new FederationPartyAuthnRequestConfiguration(requestedAuthnContextConfiguration, nameIdconfiguration, scopingConfiguration);

            return(new FederationPartyConfiguration("local", "https://dg-mfb/idp/shibboleth")
            {
                MetadataContext = this._inlineMetadataContextBuilder.BuildContext(new MetadataGenerateRequest(MetadataType.SP, "local")),
                FederationPartyAuthnRequestConfiguration = federationPartyAuthnRequestConfiguration
            });
        }
Пример #7
0
 public FederationPartyConfiguration BuildContext(string federationPartyId, RequestedAuthnContextConfiguration requestedAuthnContextConfiguration)
 {
     return(this.BuildContext(federationPartyId, NameIdentifierFormats.Unspecified, new ScopingConfiguration(), requestedAuthnContextConfiguration));
 }