本文整理汇总了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();
}
示例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;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例7: DoTheSaving
protected void DoTheSaving(IPrincipal user, IItemEditor editor)
{
using (mocks.Playback())
{
editManager.Save(editor.CurrentItem, editor.AddedEditors, editor.VersioningMode, user);
}
}
示例8: GetApprovedDatabases
public List<string> GetApprovedDatabases(IPrincipal user)
{
var oAuthUser = user as OAuthPrincipal;
if (oAuthUser == null)
return new List<string>();
return oAuthUser.GetApprovedDatabases();
}
示例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);
}
}
示例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");
}
示例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))
)
);
}
示例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;
}
示例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;
}
示例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);
}