all groups > sql server reporting services > may 2007 >
You're in the

sql server reporting services

group:

Impersonation not working correctly in custom code module


Impersonation not working correctly in custom code module Jason
5/31/2007 10:55:01 AM
sql server reporting services:
I have a Reporting Server setup in a lab and one setup on my development
machine. Both use to run Reporting Services 2000. We recently upgraded to
Reporting Services 2005. I am having a problem on both machines impersonating
the logged-in user in my custom assembly that is called from the report.

Details
--------

In many of my reports, I call a custom module that filters data based on the
logged-in user. This worked well when running under 2000. Now, after the
upgrade, I don't seem to be impersonating the user correctly.

In my custom code, I call:

WindowsIdentity winUser = WindowsIndentity.GetCurrent();

This used to get me the logged in user. Now, it always gets me
MACHINENAME\ASPNET.

The Reports web application is configured for Window Integrated
Authentication (and no other methods). The ReportServer\web.config file
specifies Windows Authentication and Impersonate = "true".

I don't know if there is a difference in the new platform or there is a
configuration problem after the upgrade that I haven't been able to track
down. Any help would be GREATLY appreciated. I've spent several days on this
already and can't find any reason that I am 'ASPNET' when I get to my custom
code.

RE: Impersonation not working correctly in custom code module weilu NO[at]SPAM online.microsoft.com
6/1/2007 7:21:10 AM
Hello Bob,

Have you changed the correct web.config file?

Also, did you follow this article to deploy the custom assembly correctly?

http://msdn2.microsoft.com/en-us/library/ms155034.aspx

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
RE: Impersonation not working correctly in custom code module Jason
6/1/2007 7:57:00 AM
Wie,

Thanks for your reply.

Yes. I think I checked the correct web.config file. I checked both the
ReportServer\web.config and the ReportManager\web.config. Incidentially, I
get the same issue wether I hit the Report Manager or the Report Service
directly.

As for code deployment, I think it is correct. I can debug into my
custom code. So I'm pretty sure it's in the right place. Also, I had it
running fine under 2000.

I did have to add a bunch of permissions to a permission set and assert
them. That was new. (I didn't have them under 2000 and was running.) I
stepped through the code and deteremined what wasn't working and added
permissions to the set until I was running. I don't know if this could be a
manifestation of a missing permission. But I don't know how to run down which
one. The permissions I am asserting are as follows:

- UnmanagedCode (attribute on the method)
- ControlPrincipal (attribute on the method)
- SqlClientPermission (I am checking for region-specific rights in the
database)
- FileIOPermission (I am reading from the web.config file)
- PrincipalPermission (I think this is the one that should allow me to
impersonate?)
- DirectoryServicesPermission (I need to lookup the logged-in user
against the AD to check for regions, etc)

I do the actual AD lookup and database access in another assembly called
by this one. I don't think I need to also assert in that assembly, right? It
should pass down the call stack. Also, when I do the
WindowsIdentity.GetCurrent in this (parent) assembly, it still gives me
ASPNET, even before I call the other assembly. So I just don't think it is
working correctly at all.

Sorry for the long-winded response. I appreciate any help you can give
and want to acurately describe what I've done so far.

I also ran down the "is this a delegation issue" road, even though that
should be impossible (it's all running on the same machine). No luck there.

I'm almost sure it's either a permission issue or a configuration issue.
But I am beating myself up and can't find evidence of either.

Thanks again,

Jason


[quoted text, click to view]
RE: Impersonation not working correctly in custom code module weilu NO[at]SPAM online.microsoft.com
6/4/2007 6:18:40 AM
Hello Jason,

I would like to check the Httpcontext.Current.User.Identity.

If you use this in the custom code, what did you get? Also, did you set the
Report Virtual Directory to integrated windows authentication?

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
RE: Impersonation not working correctly in custom code module Jason
6/4/2007 10:58:04 AM
Wei,

HttpContext.Current.User.Identity gives the correct user. So the user is
logged in, but for whatever reason, the impersonation doesn't seem to be
happening at this point. The virtual directory is set to Windows
Authentication. And the web config file is set to Windows Authentication and
impersonation=true.

The good news is that by using the HttpContext object, I am able to get
what I need done. (I have to impersonate a known user to query the AD, but we
already have a user created and secured for only that right for use with the
DirectorySearcher class, anyway.)

I appreciate your help greatly. This was a real stumper. I would still
be curious why the impersonation seems to be failing at this level.

Again, thank you very much.

Jason

[quoted text, click to view]
RE: Impersonation not working correctly in custom code module weilu NO[at]SPAM online.microsoft.com
6/5/2007 3:12:47 AM
Hello Jason,

My pleasure. I guess this issue is because that when your custom assebly
runs to the Line where Windows Indetity is, it did not impersonated yet.

If you have any question, please feel free to let me know.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
AddThis Social Bookmark Button