iprincipal

What is the idea behind IIdentity and IPrincipal in .NET

我们两清 提交于 2019-12-20 08:34:53
问题 So, what is the purpose for existence of both IIdentity and IPrincipal , and not some IIdentityMergedWithPrincipal ? When is it not enough to implement both in same class? Also, to understand purpose, I'd like to know where this concept comes from: It is originated in .Net There is concept of Identity/Principal as design pattern, which System.Security.Principal implemented in those interfaces It is originated somewhere else and supported for compatibility Therefore, does UserPrincipal from

Store user id in Principal or Identity? ASP.Net/OpenID

被刻印的时光 ゝ 提交于 2019-12-10 18:20:51
问题 I have an ASP.Net MVC web application using forms authentication. I am using OpenID for authentication. At the moment the moment I'm storing the openID url inside the Name of the standard GenericIdentity . I would also like to have easy access to the database id for the user. I can make a custom provider or identity by overriding the Application_AuthenticateRequest function. My question is should the database uid for the user go into the principal or the identity? Should the Name property of

How to do ASP.NET Web API integration tests with custom authentication and in-memory hosting

爷,独闯天下 提交于 2019-12-10 11:35:15
问题 A similar question has been answered here but the answer doesn't seem to work in my case. I want to test the authentication/authorization process in my Web Api which is using a JWT authentication. My authentication is handled through a custom MessageHandler that I add to my HttpConfiguration . Authorization in handled by a simple [Authorize] Attribute on Controller/Methods I want to restrict access to. I'm setting the principal I've extracted from my token this way during authentication (in

Obtaining the current Principal outside of the Web tier

北城以北 提交于 2019-12-10 03:26:53
问题 I have the following ntier app: MVC > Services > Repository > Domain. I am using Forms authentication. Is it safe to use Thread.CurrentPrincipal outside of my MVC layer to get the currently logged in user of my application or should I be using HttpContext.Current.User? The reason I ask is there seems to be some issues around Thread.CurrentPrincipal, but I am cautious to add a reference to System.Web outside of my MVC layer in case I need to provide a non web font end in the future. Update I

How can I make accessing my custom IPrincipal easier in ASP.NET MVC?

烈酒焚心 提交于 2019-12-09 09:42:32
问题 I've written a custom principal object which contains a few additional fields (email and userid in addition to the username). In order to access these properties I have to cast the Context.User object as my custom principal. @Html.GetGravitarImage((User as CustomPrincipal).Email) This custom principal is created / deserialized via the Application_AuthenticateRequest in my global.ascx. You can see this question I asked here for more information. private void Application_AuthenticateRequest

Unit Testing, how to set Thread.CurrentPrincipal and IsAuthenticated

懵懂的女人 提交于 2019-12-07 19:26:31
问题 I am trying to perform a unit test of an n-tier application, service layer, repository layer and web api controllers. My repositories are checking the Thread.CurrentPrincipal object to get the current user. This is where I have a problem, when I create the implementation class that inherits from IPrincipal it does allow me to set the IsUserAuthenticated. Is there a way to simulate this for my unit tests. I would like to set the Thread.CurrentPrincipal to my implementation object. How would I

Selective IPrincipal Injection via StructureMap with SignalR

时光怂恿深爱的人放手 提交于 2019-12-07 18:37:32
问题 StructureMap is configured to inject HttpContext.Current.User when an IPrincipal is requested for any ASP.NET MVC web request, like so: For<IPrincipal>().Use(x => HttpContext.Current.User); But when my SignalR hub asks for a service that depends on an IPrincipal , injection fails because HttpContext.Current is null. Instead, SignalR already has a HubCallerContext property that exposes the current IPrincipal via Context.User . How do I configure StructureMap to always inject a valid IPrincipal

asp.net extending IPrincipal

我怕爱的太早我们不能终老 提交于 2019-12-06 23:49:39
问题 I would like to extend IPrincipal in asp.net to allow me to get the usertype that I will define. I would like to make it possible to do this in a controller string type = User.UserType then in my extension method i will have a method like public string UserType() { // do some database access return userType } how can I do this? is it possible? Thanks! 回答1: You can make an extension method: public static string UserType(this IPrincipal principal) { // do some database access return something;

How to do ASP.NET Web API integration tests with custom authentication and in-memory hosting

时间秒杀一切 提交于 2019-12-06 13:38:42
A similar question has been answered here but the answer doesn't seem to work in my case. I want to test the authentication/authorization process in my Web Api which is using a JWT authentication. My authentication is handled through a custom MessageHandler that I add to my HttpConfiguration . Authorization in handled by a simple [Authorize] Attribute on Controller/Methods I want to restrict access to. I'm setting the principal I've extracted from my token this way during authentication (in my custom MessageHandler ): Thread.CurrentPrincipal = principal; if (HttpContext.Current != null) {

Unit Testing, how to set Thread.CurrentPrincipal and IsAuthenticated

北战南征 提交于 2019-12-06 10:25:20
I am trying to perform a unit test of an n-tier application, service layer, repository layer and web api controllers. My repositories are checking the Thread.CurrentPrincipal object to get the current user. This is where I have a problem, when I create the implementation class that inherits from IPrincipal it does allow me to set the IsUserAuthenticated. Is there a way to simulate this for my unit tests. I would like to set the Thread.CurrentPrincipal to my implementation object. How would I simulate a user in this way? In my RepositoryBase code, I call the following to determine if user is