public void CreateAuthorizationCallHandlerFromConfiguration()
        {
            PolicyInjectionSettings settings = new PolicyInjectionSettings();

            PolicyData policyData             = new PolicyData("policy");
            AuthorizationCallHandlerData data = new AuthorizationCallHandlerData("foo", 2);

            policyData.MatchingRules.Add(new CustomMatchingRuleData("matchesEverything", typeof(AlwaysMatchingRule)));
            policyData.Handlers.Add(data);
            settings.Policies.Add(policyData);

            using (var configSource = new FileConfigurationSource("Authorization.config", false))
            {
                IUnityContainer container = new UnityContainer().AddNewExtension <Interception>();
                settings.ConfigureContainer(container, configSource);
                new UnityContainerConfigurator(container)
                .RegisterAll(
                    configSource,
                    (ITypeRegistrationsProvider)configSource.GetSection(SecuritySettings.SectionName));

                InjectionFriendlyRuleDrivenPolicy policy = container.Resolve <InjectionFriendlyRuleDrivenPolicy>("policy");

                ICallHandler handler =
                    (policy.GetHandlersFor(new MethodImplementationInfo(null, (MethodInfo)MethodBase.GetCurrentMethod()), container)).ElementAt(0);
                Assert.IsNotNull(handler);
                Assert.AreEqual(handler.Order, data.Order);
                //Assert.AreSame(authorizationProvider, ((AuthorizationCallHandler)handler).AutorizationProvider); // TODO this test only checked for provider name, so it didn't fail even though the configuration source supplied didn't have the settings required to build it
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new <see cref="AuthorizationCallHandlerNode"/> with configuration
        /// data read from the supplied <see cref="AuthorizationCallHandlerData" />.
        /// </summary>
        /// <param name="callHandlerData"><see cref="AuthorizationCallHandlerData" /> that
        /// contains the configuration information for this handler.</param>
        public AuthorizationCallHandlerNode(AuthorizationCallHandlerData callHandlerData)
            : base(callHandlerData)
        {
            authorizationProviderName = callHandlerData.AuthorizationProvider;
            operationName             = callHandlerData.OperationName;

            authorizationProviderNodeRemovedHandler = new EventHandler <ConfigurationNodeChangedEventArgs>(OnAuthorizationNodeRemoved);
        }
Esempio n. 3
0
        public void CanCreateCustomAttributeMatchingRuleNodeFromData()
        {
            AuthorizationCallHandlerData handlerData = new AuthorizationCallHandlerData();

            handlerData.Name          = "authHandler";
            handlerData.OperationName = "operation";

            AuthorizationCallHandlerNode handlerNode = new AuthorizationCallHandlerNode(handlerData);

            Assert.AreEqual(handlerData.Name, handlerNode.Name);
            Assert.AreEqual(handlerData.OperationName, handlerNode.OperationName);
        }
Esempio n. 4
0
        /// <summary>
        /// Converts the information stored in the node and generate
        /// the corresponding configuration element to store in
        /// an <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource" />.
        /// </summary>
        /// <returns>Newly created <see cref="AuthorizationCallHandlerData"/> containing
        /// the configuration data from this node.</returns>
        public override CallHandlerData CreateCallHandlerData()
        {
            AuthorizationCallHandlerData callHandlerData = new AuthorizationCallHandlerData(Name);

            callHandlerData.OperationName = operationName;
            if (authorizationProviderNode != null)
            {
                callHandlerData.AuthorizationProvider = authorizationProviderNode.Name;
            }

            return(callHandlerData);
        }
Esempio n. 5
0
        public void CanCreateRuleDataFromCustomAttributeMatchingRuleNode()
        {
            AuthorizationCallHandlerNode handlerNode = new AuthorizationCallHandlerNode();

            handlerNode.Name          = "authHandler";
            handlerNode.OperationName = "Operation";

            AuthorizationCallHandlerData handlerData = handlerNode.CreateCallHandlerData() as AuthorizationCallHandlerData;

            Assert.IsNotNull(handlerData);
            Assert.AreEqual(handlerNode.Name, handlerData.Name);
            Assert.AreEqual(handlerNode.OperationName, handlerData.OperationName);
        }
Esempio n. 6
0
        public void CanDeserializeAuthorizationCallHandlerData()
        {
            AuthorizationCallHandlerData data = new AuthorizationCallHandlerData("Authorization Handler");

            data.AuthorizationProvider = "auhtorizationProvider";
            data.OperationName         = "operationName";

            AuthorizationCallHandlerData deserialized =
                (AuthorizationCallHandlerData)SerializeAndDeserializeHandler(data);

            Assert.AreEqual(data.AuthorizationProvider, deserialized.AuthorizationProvider);
            Assert.AreEqual(data.OperationName, deserialized.OperationName);
            Assert.AreEqual(typeof(AuthorizationCallHandler), deserialized.Type);
        }