• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IPrincipal类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IPrincipal的典型用法代码示例。如果您正苦于以下问题:C# IPrincipal类的具体用法?C# IPrincipal怎么用?C# IPrincipal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IPrincipal类属于命名空间,在下文中一共展示了IPrincipal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AspNetRequest

 public AspNetRequest(HttpRequestBase request, IPrincipal user)
 {
     _request = request;
     Cookies = new HttpCookieCollectionWrapper(request.Cookies);
     User = user;
     ResolveFormAndQueryString();
 }
开发者ID:robink-teleopti,项目名称:SignalR,代码行数:7,代码来源:AspNetRequest.cs


示例2: UserInGroup

        public static bool UserInGroup(IPrincipal user, params AdGroup[] groups)
        {
            using (WindowsImpersonationContextFacade impersonationContext
                = new WindowsImpersonationContextFacade(
                    nc))
            {
                var context = new PrincipalContext(ContextType.Domain);
                var userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName,
                    user.Identity.Name);

                if (userPrincipal.IsMemberOf(context, IdentityType.Sid, AdUserGroup.GetSidByAdGroup(AdGroup.SuperAdmin)))
                {
                    return true;
                } //Если юзер Суперадмин
                if (userPrincipal.IsMemberOf(context, IdentityType.Sid,
                    AdUserGroup.GetSidByAdGroup(AdGroup.SpeCalcKontroler)))
                {
                    return true;
                } //Если юзер Контролер

                foreach (var grp in groups)
                {
                    if (userPrincipal.IsMemberOf(context, IdentityType.Sid, AdUserGroup.GetSidByAdGroup(grp)))
                    {
                        return true;
                    }
                }

                return false;
            }
        }
开发者ID:aleks19921015,项目名称:TenderProcessing,代码行数:31,代码来源:AdHelper.cs


示例3: GetUserInbox

        public UserInboxViewModel GetUserInbox(IPrincipal requestingUser)
        {
            UserInboxViewModel retVal = null;

            //get the requesting sender
            User user = GetUser(requestingUser.Identity.Name);

            if (user != null)
            {
                //get all their active conversations
                var activeConversations = user.Conversations.ToList();
                retVal = new UserInboxViewModel();
                foreach (var conversation in activeConversations)
                {
                    var users = conversation.Users.ToList();
                    users.Remove(user);
                    var sender = users.Single();
                    var conv = new UserInboxViewModel.ConversationViewModel
                    {
                        Id = conversation.Id,
                        HasUnreadMessages = conversation.HasNewMessagesFor(user),
                        SenderImage = sender.ProfileImage != null ? sender.ProfileImage.ImageData.ThumbFileName : Constants.DEFAULT_PROFILE_IMAGE,
                        Sender = sender.Username,
                        LastMessage = conversation.Messages.First().Text
                    };
                    retVal.Conversations.Add(conv);
                }
                FillBaseProperties(retVal, user, requestingUser);
            }

            return retVal;
        }
开发者ID:scottccoates,项目名称:CliqFlip,代码行数:32,代码来源:UserProfileQuery.cs


示例4: Get

 public static ProfileUser Get(this IProfileRepository repository, IPrincipal user)
 {
     string username = GetUserName(user);
     if (string.IsNullOrEmpty(username))
         return new ProfileUser { Name = "Anonymous" };
     return repository.Get(username);
 }
开发者ID:EzyWebwerkstaden,项目名称:n2cms,代码行数:7,代码来源:IProfileRepository.cs


示例5: IsAuthorized

 private static bool IsAuthorized(object possiblySecurable, IPrincipal user, ContentItem item)
 {
     var securable = possiblySecurable as ISecurable;
     if (securable != null && securable.AuthorizedRoles != null && !PermissionMap.IsInRoles(user, securable.AuthorizedRoles))
         return false;
     return true;
 }
开发者ID:FloatLeft,项目名称:n2cms,代码行数:7,代码来源:SecurableExtensions.cs


示例6: GetEmailAddress

        public async Task<string> GetEmailAddress(IPrincipal user)
        {
            try
            {
                var identities = await (user as ServiceUser).GetIdentitiesAsync();

                //Check if the user has logged in using Google as Identity provider
                var google = identities.OfType<GoogleCredentials>().FirstOrDefault();
                if (google != null)
                {
                    var cachedEmail = LookupEmailFromToken(google.AccessToken);
                    if (!string.IsNullOrEmpty(cachedEmail))
                    {
                        return cachedEmail;
                    }

                    var googleInfo = await GetProviderInfo(google.AccessToken);
                    var userEmail = googleInfo.Value<string>("email");

                    await StoreToken(google.AccessToken, userEmail);

                    return userEmail;
                }
            }
            catch(HttpRequestException requestException)
            {
                // Swallow error and return null
            }
            return null;
        }
开发者ID:Ogadai,项目名称:MyHomeSecureWeb,代码行数:30,代码来源:LookupToken.cs


示例7: DoTheSaving

 protected void DoTheSaving(IPrincipal user, IItemEditor editor)
 {
     using (mocks.Playback())
     {
         editManager.Save(editor.CurrentItem, editor.AddedEditors, editor.VersioningMode, user);
     }
 }
开发者ID:JohnsonYuan,项目名称:n2cms,代码行数:7,代码来源:EditManagerTests.cs


示例8: GetApprovedDatabases

		public List<string> GetApprovedDatabases(IPrincipal user)
		{
			var oAuthUser = user as OAuthPrincipal;
			if (oAuthUser == null)
				return new List<string>();
			return oAuthUser.GetApprovedDatabases();
		}
开发者ID:joshball,项目名称:ravendb,代码行数:7,代码来源:OAuthRequestAuthorizer.cs


示例9: Index

      //[Authorize(Roles=TadmapRoles.Collector)]
      public ActionResult Index(IPrincipal principal)
      {
         if (Request.IsAuthenticated)
         {
            List<ImageItem> images = ImageRepository.GetAllImages()
             .IsOwnedBy((principal.Identity as TadmapIdentity).Id)
             .Select(i =>
               new ImageItem
               {
                  Id = i.Id,
                  Title = i.Title,
                  Description = i.Description,
                  SquareUrl = BinaryRepository.GetUrl(i.ImageSet.Square),
                  IconAvailable = i.HasIcon
               }
            ).ToList();

            ViewData.Model = images;

            return View();
         }
         else
         {
            return new RedirectResult(FormsAuthentication.LoginUrl);
         }
      }
开发者ID:trevorpower,项目名称:tadmap,代码行数:27,代码来源:UserImagesController.cs


示例10: CheckRegionAllowed

        public static void CheckRegionAllowed(IPrincipal principal,DbContext db, string regionID)
        {
            String userID = ((KawalDesaIdentity)principal.Identity).User.Id;
            if (userID == null)
                throw new ApplicationException("region is not allowed for thee");

            var region = db.Set<Region>()
                .AsNoTracking()
                .Include(r => r.Parent)
                .Include(r => r.Parent.Parent)
                .Include(r => r.Parent.Parent.Parent)
                .Include(r => r.Parent.Parent.Parent.Parent)
                .First(r => r.Id == regionID);

            var regionIDs = new List<string>();
            var current = region;
            while(current != null)
            {
                regionIDs.Add(current.Id);
                current = current.Parent;
            }

            var allowed = db.Set<UserScope>()
                .Any(s => s.fkUserId == userID && regionIDs.Contains(s.fkRegionId));
            if (!allowed)
                throw new ApplicationException("region is not allowed for thee");
        }
开发者ID:ekospinach,项目名称:kawaldesa,代码行数:27,代码来源:KawalDesaController.cs


示例11: VisibleTo

        internal static IQueryable<Agreement> VisibleTo(this IQueryable<Agreement> agreements, IPrincipal principal, IEnumerable<int> ownedTenantIds)
        {
            if (agreements == null) return null;
            if (principal == null) throw new ArgumentNullException("principal");
            if (ownedTenantIds == null) throw new ArgumentNullException("ownedTenantIds");

            // when user is not an agreement admin, filter out private agreements
            // and protected agreements that the user does not own
            if (!principal.IsInAnyRole(RoleName.AgreementManagers))
            {
                return agreements.Where(x => Public.Equals(x.VisibilityText, StringComparison.OrdinalIgnoreCase)
                    || (
                        Protected.Equals(x.VisibilityText, StringComparison.OrdinalIgnoreCase)
                        &&
                        x.Participants.Any(y => y.IsOwner && ownedTenantIds.Contains(y.EstablishmentId))
                    )
                );
            }

            // when user is an agreement admin, include all agreements they own
            return agreements.Where(x => Public.Equals(x.VisibilityText, StringComparison.OrdinalIgnoreCase)
                || (
                    x.Participants.Any(y => y.IsOwner && ownedTenantIds.Contains(y.EstablishmentId))
                )
            );
        }
开发者ID:ucosmic,项目名称:UCosmicAlpha,代码行数:26,代码来源:QueryAgreements.cs


示例12: OperationPermitted

        public virtual bool OperationPermitted(PamContext context, IPrincipal principal, string operation, object target, bool allowIfNoRule)
        {
            if (this.Catalog == null)
                throw new ApplicationException("Catalog is undefined");

            if (principal == null)
                throw new ArgumentNullException("principal");

            if (operation == null)
                throw new ArgumentNullException("operation");

            var ctx = context ?? new PamContext(principal, operation, target);
            ctx["RawTarget"] = target;

            try
            {
                this.Catalog[operation].Execute(ctx);
            }
            catch (Zetetic.Chain.NoSuchCommandException)
            {
                this.OnResult(ctx, operation, allowIfNoRule, true);
                return allowIfNoRule;
            }

            this.OnResult(ctx, operation, ctx.Permit, false);
            return ctx.Permit;
        }
开发者ID:skradel,项目名称:Zetetic.Chain,代码行数:27,代码来源:RbacProvider.cs


示例13: Authorize

        /// <summary>
        /// Evaluates the specified authority against the specified context that is either a task or operation in Authorization Manager. If the context is an operation it should be prefixed by "O".
        /// </summary>
        /// <param name="principal">Principal object containing a windows identity.</param>
        /// <param name="context">Name of the task or operation to evaluate.</param>
        /// <returns><strong>True</strong> if AzMan evaluates to true,
        /// otherwise <strong>false</strong>.</returns>
        public bool Authorize(IPrincipal principal, string context)
        {
            ArgumentValidation.CheckForNullReference(principal, "principal");
            ArgumentValidation.CheckForNullReference(context, "context");

            SecurityAuthorizationCheckEvent.Fire(principal.Identity.Name, context);
            AzManAuthorizationProviderData data = GetConfigurationData();

            string auditIdentifier = data.AuditIdentifierPrefix + principal.Identity.Name + ":" + context;

            bool result = false;
            bool operation = false;
            if (context.IndexOf(OperationContextPrefix) == 0)
            {
                operation = true;
                context = context.Substring(OperationContextPrefix.Length);
            }

            if (operation)
            {
                string[] operations = new string[] {context};
                result = CheckAccessOperations(data, auditIdentifier, principal.Identity, operations);
            }
            else
            {
                string[] tasks = new string[] {context};
                result = CheckAccessTasks(data, auditIdentifier, principal.Identity, tasks);
            }

            if (result == false)
            {
                SecurityAuthorizationFailedEvent.Fire(principal.Identity.Name, context);
            }
            return result;
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:42,代码来源:AzManAuthorizationProvider.cs


示例14: CreateResultWithThisPrincipal

 private PrincipalProviderResult CreateResultWithThisPrincipal(IPrincipal principal)
 {
     return new PrincipalProviderResult
                {
                    Principal = principal,
                };
 }
开发者ID:ferrislucas,项目名称:MvcTurbine.MembershipProvider,代码行数:7,代码来源:MembershipService_ValidateUserTests.cs


示例15: GetUserIdAsync

        /// <inheritdoc />
        public Task<string> GetUserIdAsync(IPrincipal user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            string id = null;
            ClaimsPrincipal principal = user as ClaimsPrincipal;
            if (principal != null)
            {
                Claim claim = principal.FindFirst(_claimsType);
                if (claim != null)
                {
                    id = claim.Value;
                }
            }

            // Fall back to name property
            if (id == null && user.Identity != null)
            {
                id = user.Identity.Name;
            }

            if (id == null)
            {
                string msg = CustomResources.Manager_NoUser;
                throw new InvalidOperationException(msg);
            }

            return Task.FromResult(id);
        }
开发者ID:itomek,项目名称:WebHooks,代码行数:33,代码来源:WebHookUser.cs


示例16: GetApprovedDatabases

		public override List<string> GetApprovedDatabases(IPrincipal user, IHttpContext context = null)
		{
			var oAuthUser = user as OAuthPrincipal;
			if (oAuthUser == null)
				return new List<string>();
			return oAuthUser.GetApprovedDatabases();
		}
开发者ID:phinett,项目名称:ravendb,代码行数:7,代码来源:OAuthRequestAuthorizer.cs


示例17: GetHtml

        public string GetHtml(IPrincipal currentPrincipal, string returnUrl)
        {
            if (currentPrincipal == null) throw new ArgumentNullException(nameof(currentPrincipal));
            if (returnUrl == null) throw new ArgumentNullException(nameof(returnUrl));

            return GetHtmlInternal(currentPrincipal, returnUrl);
        }
开发者ID:whoiskevinrich,项目名称:stuntman,代码行数:7,代码来源:UserPicker.cs


示例18: IsInVirtualRole

        public override bool IsInVirtualRole(IPrincipal principal, object context)
        {
            var httpContext = HttpContext.Current;
            if (httpContext == null)
                return false;

            var queryStringToken = httpContext.Request.QueryString["token"];
            if (string.IsNullOrEmpty(queryStringToken))
                return false;

            if (!ParseGuid(queryStringToken))
                return false;

            var pageRef = new PageReference(httpContext.Request.QueryString["id"]);
            var pageLanguage = httpContext.Request.QueryString["epslanguage"];
            
            var tokenGuid = new Guid(queryStringToken);
            if (tokenGuid == Guid.Empty)
                return false;

            Logger.InfoFormat("Token present and has the correct format {0}", tokenGuid);

            var tokenStore = new AccessTokenDataStore();
            return tokenStore.PresentToken(tokenGuid, pageRef.ID, pageRef.WorkID, pageLanguage);
        }
开发者ID:markeverard,项目名称:POSSIBLE.TokenBasedAccess,代码行数:25,代码来源:AccessTokenRole.cs


示例19: PostController

 public PostController(IPrincipal principal, IUserTasks userTasks, IPostOverviewQuery postOverviewQuery, IPostTasks postTasks)
 {
     _principal = principal;
     _userTasks = userTasks;
     _postOverviewQuery = postOverviewQuery;
     _postTasks = postTasks;
 }
开发者ID:scottccoates,项目名称:CliqFlip,代码行数:7,代码来源:PostController.cs


示例20: ExecutionContext

 /// <summary>
 /// Initializes an instance of <see cref="ExecutionContext"/>
 /// </summary>
 /// <param name="principal"><see cref="IPrincipal"/> to populate with</param>
 /// <param name="cultureInfo"><see cref="CultureInfo"/> for the <see cref="ExecutionContext"/></param>
 /// <param name="detailsPopulator">Callback that gets called for populating the details of the <see cref="ExecutionContext"/></param>
 /// <param name="system">Name of the system that is running</param>
 public ExecutionContext(IPrincipal principal, CultureInfo cultureInfo, ExecutionContextPopulator detailsPopulator, string system)
 {
     Principal = principal;
     Culture = cultureInfo;
     System = system;
     Details = new WriteOnceExpandoObject(d => detailsPopulator(this,d));
 }
开发者ID:ProCoSys,项目名称:Bifrost,代码行数:14,代码来源:ExecutionContext.cs



注:本文中的IPrincipal类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IProcedure4类代码示例发布时间:2022-05-24
下一篇:
C# IPriceFormatter类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap