示例#1
0
        public QosMiddleware(
            RequestDelegate next,
            PolicyBuilder policyBuilder)
        {
            _next = next;

            _policies = policyBuilder.Build().ToArray(); // Use array for best performances
        }
示例#2
0
 public BasePolicyTestFixture()
 {
     _testPolicy         = _policyBuilder.Build();
     _testCancelledState = new Policy.CancelledState(_testPolicy);
     _testClosedState    = new Policy.ClosedState(_testPolicy);
     _testOpenState      = new Policy.OpenState(_testPolicy);
     _testUnwrittenState = new Policy.UnwrittenState(_testPolicy);
     _testVoidState      = new Policy.VoidState(_testPolicy);
 }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationServices(setup =>
            {
                setup.ApplicationName = "AUTHTOOLBOXSAMPLEAPP";
                setup.ApplicationId   = "4830EF90-6252-4EDD-BD44-BC50D0B4F3D4";
            });

            //Add authorization services with options and policies
            #region Code Based configuration

            //services.AddAuth(options =>
            //{
            //    options.ApplicationName = "SampleApp";
            //    options.PdpUrl = "http://localhost:5000/pdp";
            //    //options.ApplicationName = "JHUAT03";
            //    //options.PdpUrl = "https://esb-app1-o.antwerpen.be/authz/v1";
            //    options.PdpCacheDuration = 0; //No caching for the samples
            //    options.JwtAudience = "SampleApp";
            //    options.JwtIssuer = "5f75f0c6cf4d4c4f97dd0ab68ce534f4";
            //    //options.JwtIssuer = "Online JWT Builder";
            //    options.JwtSigningKeyCacheDuration = 0;
            //    options.JwtSigningKeyProviderApikey = "yoursupersecretkey";         //don't do this in your code! just for demo purpose
            //                                                                        //options.jwtSigningKeyProviderApikey = Configuration["apikey"];    //using the recomended way (see https://docs.asp.net/en/latest/security/app-secrets.html)

            //    options.ApiAuthUrl = "http://devasu016.dev.digant.antwerpen.local/API-Engine-auth/v1/login/idp/redirect/proxied";
            //    options.ApiAuthIdpUrl = "https://identityserver-o.antwerpen.be/samlsso";
            //    options.ApiAuthSpName = "apiengine";
            //    options.ApiAuthSpUrl = "https://api-engine-o.antwerpen.be/API-Engine-auth/v1/login/idp/callback";

            //}, PolicyBuilder.Build());

            #endregion

            #region File based configuration

            services.AddAuth(configFile =>
            {
                configFile.BasePath = HostingEnvironment.ContentRootPath;
                configFile.FileName = "authconfig.json";
            }, PolicyBuilder.Build());

            #endregion

            services.AddSession();

            // Add framework services.
            services.AddMvc();

            services.AddSwaggerGen();
        }
示例#4
0
        public void DuplicateNames()
        {
            var provider = new Mock <IQosPolicyProvider>(MockBehavior.Strict);

            provider
            .SetupGet(p => p.Order)
            .Returns(1);
            provider
            .Setup(p => p.GetPolicies())
            .Returns(new[]
            {
                new QosPolicy("A"),
                new QosPolicy("B"),
                new QosPolicy("A")
            });

            var builder = new PolicyBuilder(
                new[] { provider.Object },
                Enumerable.Empty <IQosPolicyPostConfigure>());

            Assert.Throws <Exception>(() => builder.Build());
        }
示例#5
0
        public void Success()
        {
            var provider1 = new Mock <IQosPolicyProvider>(MockBehavior.Strict);

            provider1
            .SetupGet(p => p.Order)
            .Returns(1);
            provider1
            .Setup(p => p.GetPolicies())
            .Returns(new[]
            {
                new QosPolicy("1A"),
                new QosPolicy("1B")
            });

            var provider2 = new Mock <IQosPolicyProvider>(MockBehavior.Strict);

            provider2
            .SetupGet(p => p.Order)
            .Returns(2);
            provider2
            .Setup(p => p.GetPolicies())
            .Returns(new[]
            {
                new QosPolicy("2A"),
                new QosPolicy("2B")
            });

            var postConfigure1 = new Mock <IQosPolicyPostConfigure>(MockBehavior.Strict);

            postConfigure1
            .SetupGet(p => p.Order)
            .Returns(1);
            postConfigure1
            .Setup(p => p.PostConfigure(
                       It.Is <IList <QosPolicy> >(policies => policies
                                                  .Select(x => x.Name)
                                                  .SequenceEqual(new[] { "1A", "1B", "2A", "2B" }))))
            .Callback <IList <QosPolicy> >(policies => policies.RemoveAt(2));

            var postConfigure2 = new Mock <IQosPolicyPostConfigure>(MockBehavior.Strict);

            postConfigure2
            .SetupGet(p => p.Order)
            .Returns(2);
            postConfigure2
            .Setup(p => p.PostConfigure(
                       It.Is <IList <QosPolicy> >(policies => policies
                                                  .Select(x => x.Name)
                                                  .SequenceEqual(new[] { "1A", "1B", "2B" }))))
            .Verifiable();

            var policyProviders = new[]
            {
                provider2.Object,
                provider1.Object
            }; // Set reverse order to check if sorting is done
            var postConfigurators = new[]
            {
                postConfigure2.Object,
                postConfigure1.Object
            }; // Set reverse order to check if sorting is done

            var builder = new PolicyBuilder(policyProviders, postConfigurators);

            var result = builder.Build();

            Assert.Collection(
                result,
                p => Assert.Equal("1A", p.Policy.Name),
                p => Assert.Equal("1B", p.Policy.Name),
                p => Assert.Equal("2B", p.Policy.Name));
        }
示例#6
0
        public void Build_ReturnsAuthResponse()
        {
            var actual = _testObject.Build(_standardArn);

            Assert.NotNull(actual);
        }