473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Web service Impersonatation?

When I set up impersonation in the web.config file and specify a user and
password I get strange results. This line of code will get me the user
account I set to impersonate:
System.Security.Principal.WindowsIdentity.GetCurre nt().Name

This line of code will get me my user account ever time:

System.Threading.Thread.CurrentPrincipal.Identity. Name

What's the difference? shouldn't they both be the user I am trying to
impersonate?

Thanks
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m
Jul 21 '05 #1
7 1277
Frank,

No, they should not. When you impersonate through the WindowsIdentity
object, it does not change the current principal on the thread. The reason
for this is that you can have different implementations of IPrincipal which
don't necessarily map to windows users and groups. To that end, having
WindowsIdentity change the current thread's principal would be wrong.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41**********@Usenet.com...
When I set up impersonation in the web.config file and specify a user and
password I get strange results. This line of code will get me the user
account I set to impersonate:
System.Security.Principal.WindowsIdentity.GetCurre nt().Name

This line of code will get me my user account ever time:

System.Threading.Thread.CurrentPrincipal.Identity. Name

What's the difference? shouldn't they both be the user I am trying to
impersonate?

Thanks
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m

Jul 21 '05 #2
Thanks Nicholas,

But how do you know which Principal is being used by your code. Lets say I
have a routine that writes a file to the local directory, how do I ensure
that code is using my impersonated users rights?

--
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Frank,

No, they should not. When you impersonate through the WindowsIdentity
object, it does not change the current principal on the thread. The reason for this is that you can have different implementations of IPrincipal which don't necessarily map to windows users and groups. To that end, having
WindowsIdentity change the current thread's principal would be wrong.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41**********@Usenet.com...
When I set up impersonation in the web.config file and specify a user and password I get strange results. This line of code will get me the user
account I set to impersonate:
System.Security.Principal.WindowsIdentity.GetCurre nt().Name

This line of code will get me my user account ever time:

System.Threading.Thread.CurrentPrincipal.Identity. Name

What's the difference? shouldn't they both be the user I am trying to
impersonate?

Thanks
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m


Jul 21 '05 #3
is your server trusted for delegation?

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41**********@Usenet.com...
When I set up impersonation in the web.config file and specify a user and
password I get strange results. This line of code will get me the user
account I set to impersonate:
System.Security.Principal.WindowsIdentity.GetCurre nt().Name

This line of code will get me my user account ever time:

System.Threading.Thread.CurrentPrincipal.Identity. Name

What's the difference? shouldn't they both be the user I am trying to
impersonate?

Thanks
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m

Jul 21 '05 #4
Frank,

The code will use the rights of whomever the thread is currently running
under. If you always want to base this on the Windows identity, you can
call the static GetCurrent method on the WindowsIdentity type, passing true
for the ifImpersonating parameter.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41**********@Usenet.com...
Thanks Nicholas,

But how do you know which Principal is being used by your code. Lets say
I
have a routine that writes a file to the local directory, how do I ensure
that code is using my impersonated users rights?

--
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Frank,

No, they should not. When you impersonate through the
WindowsIdentity
object, it does not change the current principal on the thread. The

reason
for this is that you can have different implementations of IPrincipal

which
don't necessarily map to windows users and groups. To that end, having
WindowsIdentity change the current thread's principal would be wrong.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41**********@Usenet.com...
> When I set up impersonation in the web.config file and specify a user and > password I get strange results. This line of code will get me the user
> account I set to impersonate:
> System.Security.Principal.WindowsIdentity.GetCurre nt().Name
>
> This line of code will get me my user account ever time:
>
> System.Threading.Thread.CurrentPrincipal.Identity. Name
>
> What's the difference? shouldn't they both be the user I am trying to
> impersonate?
>
> Thanks
>
>
> Frank Wisniewski MCSE 4.0, MCP+I, A+
> f p w 2 3 @ h o t m a i l . c o m
>
>



Jul 21 '05 #5
asp.net seperates the thread identity from the authenicated user identity.
when the user is authenicated (not anonymous), your have three options:

1) the thread runs as the asp.net account (default)
2) the thread impersonates the authenication account (must use windows
authenication). set impersonate=true in web config
3) the thread impersonates the account specified in the web config.

you picked the third option, so the CurrentPrincipal is the authenicated
account and WindowsIdentity is the thread identity.

note: CurrentPrincipal is a WindowsIdentity only if windows authenication is
used.

-- bruce (sqlwork.com)

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41**********@Usenet.com...
| When I set up impersonation in the web.config file and specify a user and
| password I get strange results. This line of code will get me the user
| account I set to impersonate:
| System.Security.Principal.WindowsIdentity.GetCurre nt().Name
|
| This line of code will get me my user account ever time:
|
| System.Threading.Thread.CurrentPrincipal.Identity. Name
|
| What's the difference? shouldn't they both be the user I am trying to
| impersonate?
|
| Thanks
|
|
| Frank Wisniewski MCSE 4.0, MCP+I, A+
| f p w 2 3 @ h o t m a i l . c o m
|
|
Jul 21 '05 #6
I am running it from my local machine which is part of the domain, is that
what you are asking?

--
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m
"Consultant" <consultant_mcngp@yahoodotcom> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
is your server trusted for delegation?

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41**********@Usenet.com...
When I set up impersonation in the web.config file and specify a user and password I get strange results. This line of code will get me the user
account I set to impersonate:
System.Security.Principal.WindowsIdentity.GetCurre nt().Name

This line of code will get me my user account ever time:

System.Threading.Thread.CurrentPrincipal.Identity. Name

What's the difference? shouldn't they both be the user I am trying to
impersonate?

Thanks
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m


Jul 21 '05 #7
no, in order for impersonation to work, the server must be trusted for
delegation within active directory

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41********@Usenet.com...
I am running it from my local machine which is part of the domain, is that
what you are asking?

--
Frank Wisniewski MCSE 4.0, MCP+I, A+
f p w 2 3 @ h o t m a i l . c o m
"Consultant" <consultant_mcngp@yahoodotcom> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
is your server trusted for delegation?

"Frank Wisniewski" <fp***@hotmail.com> wrote in message
news:41**********@Usenet.com...
> When I set up impersonation in the web.config file and specify a user and > password I get strange results. This line of code will get me the user
> account I set to impersonate:
> System.Security.Principal.WindowsIdentity.GetCurre nt().Name
>
> This line of code will get me my user account ever time:
>
> System.Threading.Thread.CurrentPrincipal.Identity. Name
>
> What's the difference? shouldn't they both be the user I am trying to
> impersonate?
>
> Thanks
>
>
> Frank Wisniewski MCSE 4.0, MCP+I, A+
> f p w 2 3 @ h o t m a i l . c o m
>
>



Jul 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hardy Wang | last post by:
Hi all: I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based ont the code...
7
by: Mike | last post by:
I want to create a windows service that will monitor another window service. what i need for the service to do is, if a service is stopped I need it to start the service back up example: ...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
3
by: Jeremy S. | last post by:
On my dev machine (XP/Pro with VS.NET 2003) I have been developing a Windows Service and installing it on the local machine by opening the Visual Studio Command Prompt and then executing . Now I...
2
by: letibal | last post by:
Hello, I have written a windows service and created an installer for it. The service runs under the system accounts. When started, it launches a GUI. By default, the InteractiveProcess property...
4
by: kkt49 | last post by:
# vim: et sw=4 ts=8 sts from wxPython.wx import * import sys, os, time import pywintypes import win32serviceutil import win32service import win32event import win32process
4
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a...
3
dmjpro
by: dmjpro | last post by:
plz send me a good link which can clearify me how the J2EE framework works i want the details information .... plz help thanx
20
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I was executing the steps given in http://suppor.microsoft.com/kb/308359 for testing a sample web service application. However, the following line gives a compilation error: localhost.Service1...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.