Ejemplo n.º 1
0
 public PreparingRedirectToSubFunctionStateParameters(
     WxeFunction subFunction, NameValueCollection postBackCollection, WxePermaUrlOptions permaUrlOptions)
     : base(subFunction, postBackCollection)
 {
     ArgumentUtility.CheckNotNull("permaUrlOptions", permaUrlOptions);
     _permaUrlOptions = permaUrlOptions;
 }
        public RedirectingToSubFunctionStateParameters(WxeFunction subFunction, NameValueCollection postBackCollection, string destinationUrl)
            : base(subFunction, postBackCollection)
        {
            ArgumentUtility.CheckNotNullOrEmpty("destinationUrl", destinationUrl);

            _destinationUrl = destinationUrl;
        }
        public ISecurableObject GetSecurableObject(WxeFunction function)
        {
            ArgumentUtility.CheckNotNullAndType("function", function, _functionType);

            WxeParameterDeclaration parameterDeclaration = GetParameterDeclaration(function.VariablesContainer.ParameterDeclarations);
            var tuple = GetActualParameterTypeAndValue(parameterDeclaration.Type, function.Variables[parameterDeclaration.Name]);
            var actualParameterType = tuple.Item1;
            var parameterValue      = tuple.Item2;

            if (parameterValue == null)
            {
                throw new WxeException(string.Format(
                                           "The parameter '{1}' specified by the {0} applied to WxeFunction '{2}' is null.",
                                           _attribute.GetType().Name, parameterDeclaration.Name, _functionType.FullName));
            }

            ISecurableObject securableObject = parameterValue as ISecurableObject;

            if (securableObject == null)
            {
                throw new WxeException(string.Format(
                                           "The parameter '{1}' specified by the {0} applied to WxeFunction '{2}' does not implement interface '{3}'.",
                                           _attribute.GetType().Name, parameterDeclaration.Name, _functionType.FullName, typeof(ISecurableObject).FullName));
            }

            if (SecurableClass != null)
            {
                CheckParameterDeclarationMatchesSecurableClass(actualParameterType, parameterDeclaration.Name);
            }
            return(securableObject);
        }
Ejemplo n.º 4
0
        /// <summary> Executes the <see cref="WxeFunction"/> defined by the <see cref="WxeFunctionCommandInfo"/>. </summary>
        /// <param name="wxePage">
        ///   The <see cref="IWxePage"/> where this command is rendered on. Must not be <see langword="null"/>.
        /// </param>
        /// <param name="additionalWxeParameters">
        ///   The parameters passed to the <see cref="WxeFunction"/> in addition to the executing function's variables.
        ///   Use <see langword="null"/> or an empty collection if all parameters are supplied by the
        ///   <see cref="WxeFunctionCommandInfo.Parameters"/> string and the function stack.
        /// </param>
        /// <exception cref="InvalidOperationException">
        ///   <para>
        ///     Thrown if called while the <see cref="Type"/> is not set to <see cref="CommandType.WxeFunction"/>.
        ///   </para><para>
        ///     Thrown if neither the <see cref="WxeFunctionCommandInfo.MappingID"/> nor the
        ///     <see cref="WxeFunctionCommandInfo.TypeName"/> are set.
        ///   </para><para>
        ///     Thrown if the <see cref="WxeFunctionCommandInfo.MappingID"/> and <see cref="WxeFunctionCommandInfo.TypeName"/>
        ///     specify different functions.
        ///   </para>
        /// </exception>
        public virtual void ExecuteWxeFunction(IWxePage wxePage, NameObjectCollection additionalWxeParameters)
        {
            ArgumentUtility.CheckNotNull("wxePage", wxePage);

            if (Type != CommandType.WxeFunction)
            {
                throw new InvalidOperationException("Call to ExecuteWxeFunction not allowed unless Type is set to CommandType.WxeFunction.");
            }

            if (!wxePage.IsReturningPostBack)
            {
                string      target    = WxeFunctionCommand.Target;
                bool        hasTarget = !string.IsNullOrEmpty(target);
                WxeFunction function  = WxeFunctionCommand.InitializeFunction(additionalWxeParameters);

                IWxeCallArguments callArguments;
                if (hasTarget)
                {
                    callArguments = new WxeCallArguments((Control)OwnerControl, new WxeCallOptionsExternal(target, null, false));
                }
                else
                {
                    callArguments = WxeCallArguments.Default;
                }

                try
                {
                    wxePage.ExecuteFunction(function, callArguments);
                }
                catch (WxeCallExternalException)
                {
                }
            }
        }
Ejemplo n.º 5
0
        private void LoadFunctionInFrame(WxeFunction function, bool asSub = false)
        {
            var variableKey = "WxeFunctionToOpen_" + Guid.NewGuid();

            Variables[variableKey] = function;
            ExecuteCommandOnClient_InFrame("frame", ExecuteFunctionCommand, true, CurrentFunction.FunctionToken, variableKey, asSub.ToString());
        }
        /// <summary> Executes the <paramref name="function"/> in the current window. </summary>
        /// <include file='..\..\doc\include\ExecutionEngine\WxePageExtensions.xml' path='WxePageExtensions/ExecuteFunction/param[@name="page" or @name="function" or @name="createPermaUrl" or @name="useParentPermaUrl" or @name="permaUrlParameters"]' />
        public static void ExecuteFunction(
            this IWxePage page, WxeFunction function, bool createPermaUrl, bool useParentPermaUrl, NameValueCollection permaUrlParameters)
        {
            var permaUrlOptions = CreatePermaUrlOptions(createPermaUrl, useParentPermaUrl, permaUrlParameters);
            var arguments       = new WxeCallArgumentsWithoutSender(permaUrlOptions);

            Execute(page, function, arguments);
        }
        public virtual TransactionStrategyBase CreateTransactionStrategy(WxeFunction function, WxeContext context)
        {
            ArgumentUtility.CheckNotNull("function", function);

            var outerTransactionStrategy = function.ParentFunction != null ? function.ParentFunction.TransactionStrategy : NullTransactionStrategy.Null;

            return(new RootTransactionStrategy(_autoCommit, _transactionFactory.CreateRootTransaction, outerTransactionStrategy, function));
        }
        public virtual TransactionStrategyBase CreateTransactionStrategy(WxeFunction function, WxeContext context)
        {
            ArgumentUtility.CheckNotNull("function", function);

            var outerTransactionStrategy = function.ParentFunction != null? function.ParentFunction.TransactionStrategy : NullTransactionStrategy.Null;

            return(new NoneTransactionStrategy(outerTransactionStrategy));
        }
        /// <summary>Executes the <paramref name="function"/> in the current window without triggering the current post-back event on returning.</summary>
        /// <remarks>This overload tries to determine automatically whether the current event was caused by the <c>__EVENTTARGET</c> field.</remarks>
        /// <include file='..\..\doc\include\ExecutionEngine\WxePageExtensions.xml' path='WxePageExtensions/ExecuteFunctionNoRepost/param[@name="page" or @name="function" or @name="sender" or @name="createPermaUrl" or @name="useParentPermaUrl" or @name="permaUrlParameters"]' />
        public static void ExecuteFunctionNoRepost(
            this IWxePage page, WxeFunction function, Control sender, bool createPermaUrl, bool useParentPermaUrl, NameValueCollection permaUrlParameters)
        {
            var permaUrlOptions = CreatePermaUrlOptions(createPermaUrl, useParentPermaUrl, permaUrlParameters);
            var options         = new WxeCallOptionsNoRepost(permaUrlOptions);
            var arguments       = new WxeCallArguments(sender, options);

            Execute(page, function, arguments);
        }
        public SecurityExecutionListener(WxeFunction function, IWxeFunctionExecutionListener innerListener, [CanBeNull] IWxeSecurityAdapter wxeSecurityAdapter)
        {
            ArgumentUtility.CheckNotNull("function", function);
            ArgumentUtility.CheckNotNull("innerListener", innerListener);

            _function           = function;
            _innerListener      = innerListener;
            _wxeSecurityAdapter = wxeSecurityAdapter;
        }
        public WxeContext CreateContext(WxeFunction rootFunction)
        {
            HttpContextBase         httpContext          = MockRepository.GenerateStub <HttpContextBase> ();
            WxeFunctionStateManager functionStateManager = new WxeFunctionStateManager(MockRepository.GenerateStub <HttpSessionStateBase> ());
            WxeFunctionState        functionState        = new WxeFunctionState(rootFunction, false);
            NameValueCollection     queryString          = new NameValueCollection();

            return(new WxeContext(httpContext, functionStateManager, functionState, queryString));
        }
Ejemplo n.º 13
0
            public virtual WxeFunction InitializeFunction(NameObjectCollection additionalWxeParameters)
            {
                Type        functionType = ResolveFunctionType();
                WxeFunction function     = (WxeFunction)Activator.CreateInstance(functionType);

                function.VariablesContainer.InitializeParameters(_parameters, additionalWxeParameters);

                return(function);
            }
Ejemplo n.º 14
0
        public void HasStatelessAccessDenied()
        {
            Expect.Call(_mockWxeSecurityAdapter.HasStatelessAccess(typeof(TestFunction))).Return(false);
            _mockRepository.ReplayAll();

            bool hasAccess = WxeFunction.HasAccess(typeof(TestFunction));

            _mockRepository.VerifyAll();
            Assert.That(hasAccess, Is.False);
        }
Ejemplo n.º 15
0
        public PreProcessingSubFunctionStateParameters(IWxePage page, WxeFunction subFunction, WxePermaUrlOptions permaUrlOptions)
        {
            ArgumentUtility.CheckNotNull("page", page);
            ArgumentUtility.CheckNotNull("subFunction", subFunction);
            ArgumentUtility.CheckNotNull("permaUrlOptions", permaUrlOptions);

            _page            = page;
            _subFunction     = subFunction;
            _permaUrlOptions = permaUrlOptions;
        }
 private static void Execute(IWxePage page, WxeFunction function, IWxeCallArguments arguments)
 {
     try
     {
         page.ExecuteFunction(function, arguments);
     }
     catch (WxeCallExternalException)
     {
     }
 }
        public WxeVariablesContainer(WxeFunction function, object[] actualParameters, WxeParameterDeclaration[] parameterDeclarations)
        {
            ArgumentUtility.CheckNotNull("function", function);
            ArgumentUtility.CheckNotNull("actualParameters", actualParameters);
            ArgumentUtility.CheckNotNullOrItemsNull("parameterDeclarations", parameterDeclarations);

            _function              = function;
            _variables             = new NameObjectCollection();
            _parameterDeclarations = parameterDeclarations;
            _actualParameters      = actualParameters;
        }
Ejemplo n.º 18
0
        public void ExecuteFunction(WxeFunction function, Control sender, WxeCallOptions options)
        {
            ArgumentUtility.CheckNotNull("function", function);
            // sender can be null
            ArgumentUtility.CheckNotNull("options", options);

            WxePermaUrlOptions permaUrlOptions = options.PermaUrlOptions;
            WxeRepostOptions   repostOptions   = WxeRepostOptions.DoRepost(sender);

            _wxePageInfo.CurrentPageStep.ExecuteFunction(new PreProcessingSubFunctionStateParameters(_page, function, permaUrlOptions), repostOptions);
        }
 public static void ExecuteFunctionExternal(
     this IWxePage page,
     WxeFunction function,
     bool createPermaUrl,
     bool useParentPermaUrl,
     NameValueCollection urlParameters,
     bool returnToCaller,
     NameValueCollection callerUrlParameters)
 {
     throw new NotSupportedException("ExecuteFunctionExternal for redirects requires a sender to be specified. (1.13.180)");
 }
 /// <summary>
 ///   Executes a <see cref="WxeFunction"/> outside the current function's context (i.e. asynchron) using the
 ///   specified window or frame through javascript window.open(...).
 /// </summary>
 /// <include file='..\..\doc\include\ExecutionEngine\WxePageExtensions.xml' path='WxePageExtensions/ExecuteFunctionExternal/param[@name="page" or @name="function" or @name="target" or @name="sender" or @name="returningPostback" or @name="createPermaUrl" or @name="useParentPermaUrl" or @name="urlParameters"]' />
 public static void ExecuteFunctionExternal(
     this IWxePage page,
     WxeFunction function,
     string target,
     Control sender,
     bool returningPostback,
     bool createPermaUrl,
     bool useParentPermaUrl,
     NameValueCollection urlParameters)
 {
     ExecuteFunctionExternal(page, function, target, null, sender, returningPostback, createPermaUrl, useParentPermaUrl, urlParameters);
 }
Ejemplo n.º 21
0
        public void ExecuteFunctionNoRepost(WxeFunction function, Control sender, WxeCallOptionsNoRepost options)
        {
            ArgumentUtility.CheckNotNull("function", function);
            ArgumentUtility.CheckNotNull("sender", sender);
            ArgumentUtility.CheckNotNull("options", options);

            bool usesEventTarget = options.UsesEventTarget ?? UsesEventTarget;
            WxePermaUrlOptions permaUrlOptions = options.PermaUrlOptions;
            WxeRepostOptions   repostOptions   = WxeRepostOptions.SuppressRepost(sender, usesEventTarget);

            _wxePageInfo.CurrentPageStep.ExecuteFunction(new PreProcessingSubFunctionStateParameters(_page, function, permaUrlOptions), repostOptions);
        }
 /// <summary>
 ///   Executes a <see cref="WxeFunction"/> outside the current function's context (i.e. asynchron) using the
 ///   specified window or frame through javascript window.open(...).
 /// </summary>
 /// <include file='..\..\doc\include\ExecutionEngine\WxePageExtensions.xml' path='WxePageExtensions/ExecuteFunctionExternal/param[@name="page" or @name="function" or @name="target" or @name="features" or @name="sender" or @name="returningPostback" or @name="createPermaUrl" or @name="useParentPermaUrl"]' />
 public static void ExecuteFunctionExternal(
     this IWxePage page,
     WxeFunction function,
     string target,
     string features,
     Control sender,
     bool returningPostback,
     bool createPermaUrl,
     bool useParentPermaUrl)
 {
     ExecuteFunctionExternal(page, function, target, features, sender, returningPostback, createPermaUrl, useParentPermaUrl, null);
 }
        public void HasAccess_ViaDomainObjectParameter_WithFunctionalHasAccessFalse_ReturnsFalse()
        {
            FunctionalSecurityStrategyStub
            .Stub(
                stub => stub.HasAccess(
                    Arg.Is(typeof(SecurableDomainObject)),
                    Arg.Is(SecurityProviderStub),
                    Arg.Is(SecurityPrincipalStub),
                    Arg <IReadOnlyList <AccessType> > .List.Equal(new[] { TestAccessTypeValue })))
            .Return(false);

            Assert.That(WxeFunction.HasAccess(typeof(FunctionWithSecuredDomainObjectParameter)), Is.False);
        }
        // methods and properties

        public bool HasAccess(ISecurableObject securableObject, Delegate handler)
        {
            if (handler == null)
            {
                return(true);
            }

            if (SecurityFreeSection.IsActive)
            {
                return(true);
            }

            List <DemandTargetPermissionAttribute> attributes = GetPermissionAttributes(handler.GetInvocationList());

            bool hasAccess = true;

            foreach (DemandTargetPermissionAttribute attribute in attributes)
            {
                switch (attribute.PermissionSource)
                {
                case PermissionSource.WxeFunction:
                    hasAccess &= WxeFunction.HasAccess(attribute.FunctionType);
                    break;

                case PermissionSource.SecurableObject:
                    SecurityClient securityClient = SecurityClient.CreateSecurityClientFromConfiguration();
                    if (securableObject == null)
                    {
                        hasAccess &= securityClient.HasStatelessMethodAccess(attribute.SecurableClass, attribute.MethodName);
                    }
                    else
                    {
                        hasAccess &= securityClient.HasMethodAccess(securableObject, attribute.MethodName);
                    }
                    break;

                default:
                    throw new InvalidOperationException(string.Format(
                                                            "Value '{0}' is not supported by the PermissionSource property of the DemandTargetPermissionAttribute.",
                                                            attribute.PermissionSource));
                }

                if (!hasAccess)
                {
                    break;
                }
            }

            return(hasAccess);
        }
Ejemplo n.º 25
0
        public void HasStatelessAccessGrantedWithoutWxeSecurityProvider()
        {
            var serviceLocator = DefaultServiceLocator.Create();

            serviceLocator.RegisterMultiple <IWxeSecurityAdapter>();
            using (new ServiceLocatorScope(serviceLocator))
            {
                _mockRepository.ReplayAll();

                bool hasAccess = WxeFunction.HasAccess(typeof(TestFunction));

                _mockRepository.VerifyAll();
                Assert.That(hasAccess, Is.True);
            }
        }
Ejemplo n.º 26
0
        public override TransactionStrategyBase CreateTransactionStrategy(WxeFunction function, WxeContext context)
        {
            ArgumentUtility.CheckNotNull("function", function);
            ArgumentUtility.CheckNotNull("context", context);

            if (function.ParentFunction != null)
            {
                var childTransactionStrategy = function.ParentFunction.TransactionStrategy.CreateChildTransactionStrategy(AutoCommit, function, context);
                if (childTransactionStrategy != null)
                {
                    return(childTransactionStrategy);
                }
            }

            return(base.CreateTransactionStrategy(function, context));
        }
        /// <summary>
        ///   Executes a <see cref="WxeFunction"/> outside the current function's context (i.e. asynchron) using the
        ///   current window or frame. The execution engine uses a redirect request to transfer the execution to the new function.
        /// </summary>
        /// <include file='..\..\doc\include\ExecutionEngine\WxePageExtensions.xml' path='WxePageExtensions/ExecuteFunctionExternal/param[@name="page" or @name="function" or @name="sender" or @name="createPermaUrl" or @name="useParentPermaUrl" or @name="urlParameters" or @name="returnToCaller" or @name="callerUrlParameters"]' />
        public static void ExecuteFunctionExternal(
            this IWxePage page,
            WxeFunction function,
            Control sender,
            bool createPermaUrl,
            bool useParentPermaUrl,
            NameValueCollection urlParameters,
            bool returnToCaller,
            NameValueCollection callerUrlParameters)
        {
            var permaUrlOptions = CreatePermaUrlOptions((createPermaUrl || urlParameters != null), useParentPermaUrl, urlParameters);
            var options         = new WxeCallOptionsExternalByRedirect(permaUrlOptions, returnToCaller, callerUrlParameters);
            var arguments       = new WxeCallArguments(sender, options);

            Execute(page, function, arguments);
        }
        /// <summary>
        ///   Executes a <see cref="WxeFunction"/> outside the current function's context (i.e. asynchron) using the
        ///   specified window or frame through javascript window.open(...).
        /// </summary>
        /// <include file='..\..\doc\include\ExecutionEngine\WxePageExtensions.xml' path='WxePageExtensions/ExecuteFunctionExternal/param[@name="page" or @name="function" or @name="target" or @name="features" or @name="sender" or @name="returningPostback" or @name="createPermaUrl" or @name="useParentPermaUrl" or @name="urlParameters"]' />
        public static void ExecuteFunctionExternal(
            this IWxePage page,
            WxeFunction function,
            string target,
            string features,
            Control sender,
            bool returningPostback,
            bool createPermaUrl,
            bool useParentPermaUrl,
            NameValueCollection urlParameters)
        {
            var permaUrlOptions = CreatePermaUrlOptions(createPermaUrl, useParentPermaUrl, urlParameters);
            var options         = new WxeCallOptionsExternal(target, features, returningPostback, permaUrlOptions);
            var arguments       = new WxeCallArguments(sender, options);

            Execute(page, function, arguments);
        }
 private void ExecuteWxeFunction(WxeFunction function, object sender, bool shouldExecuteAsSubFunction)
 {
     if (shouldExecuteAsSubFunction)
     {
         ExecuteFunction(function, new WxeCallArguments((Control)sender, new WxeCallOptions()));
     }
     else
     {
         try
         {
             ExecuteFunction(function, new WxeCallArguments((Control)sender, new WxeCallOptionsExternal("_self")));
         }
         catch (WxeCallExternalException)
         {
             // ReSharper disable once RedundantJumpStatement
             return;
         }
     }
 }
Ejemplo n.º 30
0
        public void ExecuteFunctionExternalByRedirect(WxeFunction function, Control sender, WxeCallOptionsExternalByRedirect options)
        {
            ArgumentUtility.CheckNotNull("function", function);
            ArgumentUtility.CheckNotNull("sender", sender);
            ArgumentUtility.CheckNotNull("options", options);

            WxeReturnOptions returnOptions;

            if (options.ReturnToCaller)
            {
                returnOptions = new WxeReturnOptions(options.CallerUrlParameters ?? _page.GetPermanentUrlParameters());
            }
            else
            {
                returnOptions = WxeReturnOptions.Null;
            }

            WxePermaUrlOptions permaUrlOptions = options.PermaUrlOptions;

            _wxePageInfo.CurrentPageStep.ExecuteFunctionExternalByRedirect(new PreProcessingSubFunctionStateParameters(_page, function, permaUrlOptions), returnOptions);
        }