principal

Thread.CurrentPrincipal in .NET console application

拜拜、爱过 提交于 2019-12-06 18:06:41
问题 Here is a trivial console application that i run in command prompt: using System; using System.Threading; namespace Test { internal class Runner { [STAThread] static void Main(string[] args) { Console.WriteLine(Thread.CurrentPrincipal.GetType().Name); Console.WriteLine(Thread.CurrentPrincipal.Identity.Name); } } } The output is 'GenericPrincipal' and empty string as identity name. Why the run-time constructs GenericPrincipal instead of WindowsPrincipal ? How do i force it to construct

Custom principal in ASP.NET MVC

余生长醉 提交于 2019-12-06 08:22:14
问题 I want to be able to access custom properties for an authenticated user like UserId and FirstName without querying the database each time. I found this site through a post on Stack Overflow and I like the approach - but I use IoC / repositories and decided not to try and get global.asax to communicate with the database for fear that it would be incompatible with the repository pattern. Instead, I created an interface to CustomPrincipal and I use IoC (Castle) to create an instance and pass it

WCF Service - Custom Principal

大憨熊 提交于 2019-12-06 06:38:11
问题 In the constructor of my WCF service class I am setting the current principal to be that of the principal passed in the header of the message: Thread.CurrentPrincipal = OperationContext.Current.IncomingMessageHeaders.GetHeader<BBPrincipal>("bbPrincipal", "ns"); This seems to work fine, however when I come to reference the principal in a method, the Thread.CurrentPrincipal has reverted to a WindowsPrincipal. Presumably the method is firing on a different thread. How can I ensure that the

Spring 3 MVC Controller integration test - inject Principal into method

ぃ、小莉子 提交于 2019-12-06 02:07:46
问题 As part of Spring 3 MVC it is possible to inject the currently logged in user (Principle) object into a controller method. E.g. @Controller public class MyController { @RequestMapping(value="/update", method = RequestMethod.POST) public String update(ModelMap model, Principal principal) { String name = principal.getName(); ... the rest here } } This is documented as part of the Spring 3 documentation here: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc

Thread.CurrentPrincipal in .NET console application

蹲街弑〆低调 提交于 2019-12-04 23:38:00
Here is a trivial console application that i run in command prompt: using System; using System.Threading; namespace Test { internal class Runner { [STAThread] static void Main(string[] args) { Console.WriteLine(Thread.CurrentPrincipal.GetType().Name); Console.WriteLine(Thread.CurrentPrincipal.Identity.Name); } } } The output is 'GenericPrincipal' and empty string as identity name. Why the run-time constructs GenericPrincipal instead of WindowsPrincipal ? How do i force it to construct WindowsPrincipal from the security token of the starting process (cmd.exe in my case)? You have to tell your

Problem using custom principal and identity with WCF services

旧城冷巷雨未停 提交于 2019-12-04 15:54:00
问题 We are using a custom principal and identity type (ProdigyPrincipal/ProdigyIdentity) because we need extra information within our programs and services. In the program we set the principal and identity. When communicating with a WCF service the principal and identity are set, but after casting to our own type the principal and identity are null. I noticed that there is a difference between running in Debug mode and Unit Test mode. In Debug mode the type of the principal and identity are of

WCF Service - Custom Principal

人走茶凉 提交于 2019-12-04 14:31:51
In the constructor of my WCF service class I am setting the current principal to be that of the principal passed in the header of the message: Thread.CurrentPrincipal = OperationContext.Current.IncomingMessageHeaders.GetHeader<BBPrincipal>("bbPrincipal", "ns"); This seems to work fine, however when I come to reference the principal in a method, the Thread.CurrentPrincipal has reverted to a WindowsPrincipal. Presumably the method is firing on a different thread. How can I ensure that the method is using the principal set in the constructor of the service? I've just found the answer to my

Custom principal in ASP.NET MVC

做~自己de王妃 提交于 2019-12-04 13:45:48
I want to be able to access custom properties for an authenticated user like UserId and FirstName without querying the database each time. I found this site through a post on Stack Overflow and I like the approach - but I use IoC / repositories and decided not to try and get global.asax to communicate with the database for fear that it would be incompatible with the repository pattern. Instead, I created an interface to CustomPrincipal and I use IoC (Castle) to create an instance and pass it to the controllers (and subsequently to my base controller). The base controller uses methods I created

Spring 3 MVC Controller integration test - inject Principal into method

那年仲夏 提交于 2019-12-04 06:19:08
As part of Spring 3 MVC it is possible to inject the currently logged in user (Principle) object into a controller method. E.g. @Controller public class MyController { @RequestMapping(value="/update", method = RequestMethod.POST) public String update(ModelMap model, Principal principal) { String name = principal.getName(); ... the rest here } } This is documented as part of the Spring 3 documentation here: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-arguments . This works in the production code. However I don't know how to

How I get Active Directory User Properties with System.DirectoryServices.AccountManagement Namespace?

本秂侑毒 提交于 2019-12-04 04:36:18
I want do get Active Directory Properties from a user and I want to use System.DirectoryServices.AccountManagement . my code: public static void GetUserProperties(string dc,string user) { PrincipalContext ctx = new PrincipalContext(ContextType.Domain, dc); UserPrincipal u = UserPrincipal.FindByIdentity(ctx, user); string firstname = u.GivenName; string lastname = u.Surname; string email = u.EmailAddress; string telephone = u.VoiceTelephoneNumber; ...//how I can get company and other properties? } You can transition into the DirectoryServices namespace to get any property you need.