473,394 Members | 1,642 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,394 software developers and data experts.

COM+ permissions

At the place that I work to gain access to one of the databases we have
been supplied with a COM+ proxy that will allow us to connect. To
access the database we have impersonate a user to which they have
granted access to. Unfortunately the way that we were told to do this
was to write another COM+ class that will run as the user to which they
have granted access to, and allow this COM+ object to be accessed by
the user to which our web application runs under.

This sounded like a lot of work for nothing so I have tried to setup
the required impersonations within a class that exists within my
current project, just before the method call, but I have not been able
to make it work

I did do a search to try to find something that would help me out to
acheive what I want to do and below is the code that I found (along
with a couple tweaks). Unfortunately, calling on the methods within
the class does not do what I need it to do, since when I make the calll
to one of the methods in the COM+ class that I was supplied it gives me
an "Access Denied" error, and tells me that I am still running as the
ASPNET user.

If anyone knows of a way around this I would really appreciate some
input.

Thanks
namespace Mariner.WebParts.Security
{
/// <summary>
/// Jay Nathan - MARINER, LLC. - http://www.mariner-usa.com
///
/// Impersonator class allows client code to impersonate another
domain user account
/// by handling underlying account authentication and security
context manipulation
/// </summary>
public class Impersonator
{
public WindowsIdentity CurrentIdentity;

// private members for holding domain user account credentials
private string username = String.Empty;
private string password = String.Empty;
private string domain = String.Empty;
// this will hold the security context for reverting back to the
client after impersonation operations are complete
private WindowsImpersonationContext impersonationContext = null;

// disable instantiation via default constructor
private Impersonator() {}
public Impersonator(string username, string domain, string password)
{
// set the properties used for domain user account
this.username = username;
this.domain = domain;
this.password = password;
}
private WindowsIdentity Logon()
{
IntPtr handle = new IntPtr(0);
handle = IntPtr.Zero;

const int LOGON32_LOGON_NETWORK = 3;
const int LOGON32_PROVIDER_DEFAULT = 0;

// attempt to authenticate domain user account
bool logonSucceeded = LogonUser(this.username, this.domain,
this.password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, ref
handle);

if(!logonSucceeded)
{
// if the logon failed, get the error code and throw an exception
int errorCode = Marshal.GetLastWin32Error();
throw new Exception("User logon failed. Error Number: " +
errorCode);
}

// if logon succeeds, create a WindowsIdentity instance
CurrentIdentity = new WindowsIdentity(handle);

// close the open handle to the authenticated account
CloseHandle(handle);

return CurrentIdentity;
}
public void Impersonate()
{
// authenticates the domain user account and begins impersonating it
this.impersonationContext = this.Logon().Impersonate();
CoImpersonateClient();

WindowsPrincipal princ = new WindowsPrincipal(CurrentIdentity);
System.Threading.Thread.CurrentPrincipal = princ;
}
public void Undo()
{
// rever back to original security context which was store in the
WindowsImpersonationContext instance
this.impersonationContext.Undo();
CoRevertToSelf();
}
[DllImport("ole32.dll")]
static extern int CoImpersonateClient () ;

[DllImport("ole32.dll")]
static extern int CoRevertToSelf () ;

public string WhoAmI()
{
// int i = CoImpersonateClient();
// if (i==0)
// {
//this returns the caller identity
string l_identity = Thread.CurrentPrincipal.Identity.Name ;
//CoRevertToSelf();
return l_identity ;
// }
// else
// throw new Exception ("CoImpersonateClient returned " + i.ToString
());
}
[DllImport("advapi32.dll", SetLastError=true)]
private static extern bool LogonUser(string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private static extern bool CloseHandle(IntPtr handle);

}
}

Jun 7 '06 #1
0 1084

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

Similar topics

0
by: Tracy Tripp | last post by:
I'm working on a program that takes files by path and moves them into new locations, and then back again if the user intends. Everything is great so far except I cannot figure out how to keep...
4
by: Dave Kolb | last post by:
If I make ASPNET a member of the admins group it can launch my COM+ object but I do not want to do that. What permissions do I need to set for the lowly ASPNET user so that it can launch a COM+...
12
by: D. Shane Fowlkes | last post by:
This most likely belongs in another forum but I thought I'd start here. I have a COM Object written in VB6. The DLL will access MS Excel and use it's Object Library to write a customized report...
12
by: Griff | last post by:
I have a two tier system. I've created a COM+ package on the data tier (Win2003) and exported it as a COM+proxy (v 1.0 compliant) and installed this onto a Win2000 web application. I've...
7
by: none | last post by:
Hello: I had a nice php application running on my server here at home, and I uploaded it to a shared public type server and it started to break all over the place. It turns out that some...
13
by: MLH | last post by:
Invalid qualifier error displays at compile time on this A97 example from Permissions Property HELP. What's wrong with the strContainerName assignment line? (6th line) Sub...
8
by: jporter188 | last post by:
Hello, I am working on a project to manipulate XML files. All of the files, the code, and the output are on network drives. When I run my program I get an exception (see below). I tried giving...
3
by: palepimp | last post by:
Hello all, I have searched far and wide for a solution to my issue. In short, here is the problem: 1. 3 PC's enter data into an Access 2003 database (PC's are running Vista w/ Office 2007...
1
by: beary | last post by:
Hello everyone, I'm not sure if this is the correct forum for this, and apologies for the length of this question, but I'm desperate for some good advice... I'm in way over my head with file...
2
by: beary | last post by:
Hello everyone, I posted this in unix/linux but it received no replies, so I assume it was the wrong forum. I'm trying here. I'm in way over my head with file permissions. The directory and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.