当前位置: 首页>>代码示例>>C#>>正文


C# IPrincipal类代码示例

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


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


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