示例#1
0
 public static Func <IEnumerable <string>, AllowUserAccess> CheckPublicAccessFunction(
     IPublicAccessService accessService, IContentService contentService)
 {
     return((IEnumerable <string> roles) =>
     {
         return (documentId) =>
         {
             return accessService.HasAccess(documentId, contentService, roles);
         };
     });
 }
示例#2
0
    public async Task <PublicAccessStatus> HasMemberAccessToContentAsync(int publishedContentId)
    {
        HttpContext    httpContext   = _httpContextAccessor.GetRequiredHttpContext();
        IMemberManager memberManager = httpContext.RequestServices.GetRequiredService <IMemberManager>();

        if (httpContext.User.Identity == null || !httpContext.User.Identity.IsAuthenticated)
        {
            return(PublicAccessStatus.NotLoggedIn);
        }

        MemberIdentityUser?currentMember = await memberManager.GetUserAsync(httpContext.User);

        if (currentMember == null)
        {
            return(PublicAccessStatus.NotLoggedIn);
        }

        var            username  = currentMember.UserName;
        IList <string> userRoles = await memberManager.GetRolesAsync(currentMember);

        if (!currentMember.IsApproved)
        {
            return(PublicAccessStatus.NotApproved);
        }

        if (currentMember.IsLockedOut)
        {
            return(PublicAccessStatus.LockedOut);
        }

        if (!_publicAccessService.HasAccess(publishedContentId, _contentService, username, userRoles))
        {
            return(PublicAccessStatus.AccessDenied);
        }

        return(PublicAccessStatus.AccessAccepted);
    }
示例#3
0
 /// <summary>
 /// This will check if the member has access to this path
 /// </summary>
 /// <param name="path"></param>
 /// <param name="roleProvider"></param>
 /// <returns></returns>
 private bool HasAccess(string path, RoleProvider roleProvider)
 {
     return(_publicAccessService.HasAccess(path, CurrentUserName, roleProvider.GetRolesForUser));
 }
 public static bool HasAccess(this IPublicAccessService publicAccessService, string path, MembershipUser member, RoleProvider roleProvider)
 {
     return(publicAccessService.HasAccess(path, member.UserName, roleProvider.GetRolesForUser));
 }
 /// <summary>
 /// This will check if the member has access to this path
 /// </summary>
 /// <param name="path"></param>
 /// <param name="roleProvider"></param>
 /// <returns></returns>
 /// <remarks>
 /// This is essentially the same as the PublicAccessServiceExtensions.HasAccess however this will use the PCR cache
 /// of the already looked up roles for the member so this doesn't need to happen more than once.
 /// This does a safety check in case of things like unit tests where there is no PCR and if that is the case it will use
 /// lookup the roles directly.
 /// </remarks>
 private bool HasAccess(string path, RoleProvider roleProvider)
 {
     return(UmbracoContext.PublishedRequest == null
         ? _publicAccessService.HasAccess(path, CurrentUserName, roleProvider.GetRolesForUser)
         : _publicAccessService.HasAccess(path, CurrentUserName, _publishedRouter.GetRolesForLogin));
 }