コード例 #1
0
        public static void EnsureIsAuthorized(
            string articleSlugParamName,
            ArticleAccessType accessType,
            HttpControllerContext controllerContext,
            IDictionary<string, object> actionArguments)
        {
            string slugValue = GetSlugValue(articleSlugParamName, actionArguments);

            var repository = controllerContext.GetRepository();

            EnsureIsAuthorizedInternal(slugValue, repository, accessType, controllerContext.RequestContext.Principal);
        }
コード例 #2
0
ファイル: ArticleAccess.cs プロジェクト: sebnilsson/WikiDown
        public void AssertCanAccess(ArticleSlug articleSlug, IPrincipal principal, ArticleAccessType accessType)
        {
            if (articleSlug == null)
            {
                throw new ArgumentOutOfRangeException("articleSlug");
            }

            bool canAccess = this.GetCanAccess(principal, accessType);
            if (!canAccess)
            {
                throw new ArticleAccessException(articleSlug);
            }
        }
コード例 #3
0
ファイル: ArticleAccess.cs プロジェクト: sebnilsson/WikiDown
 public bool GetCanAccess(IPrincipal principal, ArticleAccessType accessType)
 {
     switch (accessType)
     {
         case ArticleAccessType.CanRead:
             return this.GetCanRead(principal);
         case ArticleAccessType.CanEdit:
             return this.GetCanEdit(principal);
         case ArticleAccessType.CanAdmin:
             return this.GetCanAdmin(principal);
         default:
             throw new ArgumentOutOfRangeException("accessType");
     }
 }
コード例 #4
0
        private static void EnsureIsAuthorizedInternal(
            string slugValue,
            Repository repository,
            ArticleAccessType accessType,
            IPrincipal principal)
        {
            var articleSlug = new ArticleSlug(slugValue ?? string.Empty);
            var article = (articleSlug.HasValue) ? repository.GetArticle(articleSlug) : null;
            var articleAccess = (article != null) ? article.ArticleAccess : null;

            articleAccess = articleAccess ?? ArticleAccess.Default();

            articleAccess.AssertCanAccess(articleSlug, principal, accessType);
        }
コード例 #5
0
        public static void AssertCanAccess(this Article article, IPrincipal principal, ArticleAccessType accessType)
        {
            AssertArticle(article);

            article.ArticleAccess.AssertCanAccess(article.Slug, principal, accessType);
        }
コード例 #6
0
 public static Article EnsureAccess(this Article article, IPrincipal principal, ArticleAccessType accessType)
 {
     return (article != null && article.CanAccess(principal, accessType)) ? article : null;
 }
コード例 #7
0
        public static bool CanAccess(this Article article, IPrincipal principal, ArticleAccessType accessType)
        {
            AssertArticle(article);

            return article.ArticleAccess.GetCanAccess(principal, accessType);
        }
コード例 #8
0
 public AuthorizeArticleAttribute(ArticleAccessType accessType)
 {
     this.accessType = accessType;
     this.ParamName = AuthorizeArticleHelper.DefaultArticleSlugParamName;
 }
コード例 #9
0
ファイル: Repository.cs プロジェクト: sebnilsson/WikiDown
        private Article TryGetArticle(ArticleSlug articleSlug, ArticleAccessType accessType = ArticleAccessType.CanRead)
        {
            var articles =
                this.CurrentSession.Query<ArticlesIndex.Result, ArticlesIndex>()
                    .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                    .Where(
                        x => this.CurrentPrincipalAccessLevel >= x.CanReadAccess && x.ArticleSlug == articleSlug.Slug)
                    .OfType<Article>();

            var article = articles.FirstOrDefaultHandled();

            return article.EnsureAccess(this.currentPrincipal, accessType);
        }
コード例 #10
0
ファイル: Repository.cs プロジェクト: sebnilsson/WikiDown
        private Article GetOrCreateArticle(
            ArticleSlug articleSlug,
            ArticleAccessType accessType = ArticleAccessType.CanRead)
        {
            var article = this.TryGetArticle(articleSlug, accessType);
            if (article == null)
            {
                article = new Article(articleSlug);
                this.CurrentSession.Store(article);
            }

            return article;
        }
コード例 #11
0
ファイル: Repository.cs プロジェクト: sebnilsson/WikiDown
        private Article GetArticleAsserted(
            ArticleSlug articleSlug,
            ArticleAccessType accessType = ArticleAccessType.CanRead)
        {
            var article = this.TryGetArticle(articleSlug, accessType);
            if (article == null)
            {
                throw new ArticleNotFoundException(articleSlug);
            }

            return article;
        }