Re: Windows Identity simple question ????



if you look at Thread.CurrentPrincipal.Identity in the debugger - what the type?


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)

hello again.

here is what I have in my remote component for checking my client
context:

1-
WindowsIdentity identity =
System.Threading.Thread.CurrentPrincipal.Identity
Doing this I get following error :
Cannot implicitly convert type 'System.Security.Principal.IIdentity'
to 'System.Security.Principal.WindowsIdentity'. An explicit conversion
exists (are you missing a cast?)

Then I change my line as follow :
WindowsIdentity identity =
(WindowsIdentity)System.Threading.Thread.CurrentPrincipal.Identity;
No compile error but casting erro at runtime...

:-(
serge
"Dominick Baier" wrote:
Are you using remoting? do you have the secure=true switch?

Then you should find a WindowsIdentity on
Thread.CurrentPrincipal.Identity.

-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications
(http://www.microsoft.com/mspress/books/9989.asp)

This is what I need because I am using using a client applciation
which use services from a remote component host in a windows
service.

What I need to get is retrive credential of client user, to know if
it has rights to call my remote component and for that I cannot not
use the method you sugest otherwise I will only get the user which
runs my Windows service instead the client context.

What I am wondering is why it say that it retrun a GenericIdentity
type when it runs, and in code when you call the Help file it says
that it return a IIdentity object ??

regards
serge
"Henning Krause [MVP - Exchange]" wrote:
Hello,

the Thread.CurrentPrincipal.Identity does not necessarily contain
the currently logged on user. Use WindowsIdentity.GetCurrent() for
this (or, in case you are using ASP.NET with Integrated
authentication but without impersonation, user
HttpContext.Current.User).

Best regards,
Henning Krause
"calderara" <calderara@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C7202059-F1F7-4AAC-89E0-35F88870E36E@xxxxxxxxxxxxxxxx
Dear all,

I am using .NEt.2.0 and trying to get the current identity in
order
to
retrive the role that my user belongs to.
For that I am using the following code
WindowsIdentity identity =
(WindowsIdentity)Thread.CurrentPrincipal.Identity;
WindowsPrincipal
pc = new WindowsPrincipal(identity);
When runing that code I hve a runtime excpetion saying that I have
an invalid cast.

identity is a WindowsIdentity object
Thread.CurrentPrincipal.Identity is retruning a GenericIdentity
onject ???
which is strange becaseu the class definition says that Identity
should
retrun an IIdentidy object but not a generic
What happen here ?
Thnaks for help
regards
serge


.



Relevant Pages

  • Re: Windows Identity simple question ????
    ... WindowsIdentity identity = System.Threading.Thread.CurrentPrincipal.Identity ... which use services from a remote component host in a windows service. ... Windows service instead the client context. ...
    (microsoft.public.dotnet.security)
  • Re: Get role for any given user name
    ... have a look at the ctor of WindowsIdentity that takes a string. ... Dominick Baier - DevelopMentor ...
    (microsoft.public.dotnet.security)
  • Re: Other than BuiltIn groups for Windows Authentication
    ... Web config ... WindowsIdentity identity = winPrincipal.Identity as WindowsIdentity; ... >> I am using windows authentication on my ASP.Net application. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Basic Authentication/Custom Login page
    ... > c) validate the user against AD (e.g. using LogonUser) in your logon page ... > in a WindowsIdentity, wrap WindowsIdentity with WindowsPrincipal, replace ... > Dominick Baier - DevelopMentor ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: How to get user company
    ... I believe you mean User Group or User Role. ... You can get a WindowsIdentity from the user running the code with ... WindowsIdentity wi = WindowsIdentity.GetCurrent; ... public static stringGetWindowsIdentityRoles(WindowsIdentity identity) ...
    (microsoft.public.dotnet.languages.csharp)