public AuthorizationNavigationManager(Frame frame, AuthorizationNavigationMode navigationMode)
        {
            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }
            this._frame         = frame;
            this.NavigationMode = navigationMode;

            // Since there is no reliable way to determine if a control is loaded, we have to assume it
            // is loaded until told otherwise
            this.IsLoaded = true;

            this.InitializeBindings();
        }
        private AuthorizationNavigationMode GetContentNavigationMode(object content)
        {
            AuthorizationNavigationMode navigationMode = AuthorizationNavigationMode.None;

            DependencyObject contentDo = content as DependencyObject;

            if (contentDo != null)
            {
                navigationMode = Authorization.GetNavigationMode(contentDo);
            }

            if (navigationMode == AuthorizationNavigationMode.None)
            {
                navigationMode = Authorization.GetNavigationMode(this._frame);
            }

            return(navigationMode);
        }
        private void HandleLoadCompleted(IAsyncResult asyncResult)
        {
            AuthorizationAsyncResult result = (AuthorizationAsyncResult)asyncResult.AsyncState;

            if (!result.CancellationRequested)
            {
                try
                {
                    result.LoadResult = this._loader.EndLoad(result.InnerAsyncResult);
                    AuthorizationNavigationMode navigationMode = this.GetContentNavigationMode(result.LoadResult.LoadedContent);

                    if (Authorization.Authorize(result.LoadResult.LoadedContent) == AuthorizationResult.Allowed)
                    {
                        // Direct the user to the requested page
                        result.Complete();
                    }
                    else if (WebContextBase.Current.Authentication.User.Identity.IsAuthenticated ||
                             (navigationMode == AuthorizationNavigationMode.Redirect))
                    {
                        // If the user is authenticated but not authorized, he needs to be redirected
                        result.LoadResult = new LoadResult(this.DefaultSource);
                        result.Complete();
                    }
                    else if (navigationMode == AuthorizationNavigationMode.Prompt)
                    {
                        if (Authorization.Prompter == null)
                        {
                            throw new InvalidOperationException("Authorization.Prompter cannot be null when the navigationMode is 'Prompt'.");
                        }
                        // If the user is not authenticated, we need to prompt for re-authentication or redirect
                        Authorization.Prompter.RequestAuthentication(this.HandleRequestAuthenticationCompleted, result);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    result.Error = ex;
                    result.Complete();
                }
            }
        }
        private void AuthorizeFrameContent()
        {
            if (!AuthorizationNavigationManager.IsAuthorized(this.GetCurrentUri(), this._frame.Content))
            {
                AuthorizationNavigationMode navigationMode = this.GetContentNavigationMode(this._frame.Content);

                if (WebContextBase.Current.Authentication.User.Identity.IsAuthenticated ||
                    (navigationMode == AuthorizationNavigationMode.Redirect))
                {
                    // If the user is authenticated but not authorized, he needs to be redirected
                    this.Redirect();
                }
                else if (navigationMode == AuthorizationNavigationMode.Prompt)
                {
                    if (Authorization.Prompter == null)
                    {
                        throw new InvalidOperationException("Authorization.Prompter cannot be null when the navigationMode is 'Prompt'.");
                    }
                    // If the user is not authenticated, we need to prompt for re-authentication or redirect
                    Authorization.Prompter.RequestAuthentication(this.HandleRequestAuthenticationCompleted, null);
                }
            }
        }
Ejemplo n.º 5
0
 public static void SetNavigationMode(DependencyObject target, AuthorizationNavigationMode value)
 {
     target.SetValue(Authorization.NavigationModeProperty, value);
 }