A
asadim
I have gone through the ProjTool SDK app as well as the SDK documentation on
Impersonation but still haven't figured out how to login with another user
accout. Here's my Impersonation function (exactly taken from the SDK):
private static void Impersonate(string userAccount)
{
try
{
// PWAGUID is a const already defined
Guid siteId = new Guid(PWAGUID);
// Get the GUID of the user to impersonate.
Guid userGuid = GetResourceUid(userAccount);
Console.WriteLine("User GUID to impersonate: " +
userGuid.ToString());
bool isWindowsUser = true;
if (userAccount.Contains("aspnetsqlmembershipprovider"))
isWindowsUser = false;
ResourceDerived.SetImpersonationContext(isWindowsUser,
userAccount,
userGuid, Guid.Empty, siteId, "1033");
// To get the GUID of the user we are impersonating,
// call GetCurrentUserUid in the Resource Web service.
Guid impersonatedUserGuid = resProxyBySSP.GetCurrentUserUid();
Console.WriteLine(string.Format("\nImpersonating
'{0}':\n\tResourceProxy.Url:\n\t{1}",
userAccount, resProxyBySSP.Url));
Console.Write("\nImpersonated user GUID: ");
Console.WriteLine(impersonatedUserGuid.ToString());
}
catch {...}
}
The later on in my code I have a login function again taken from the SDK:
public static bool LogonPS(bool isWindowsUser, string userAccount, string
baseUrl)
{
bool logonSucceeded = false;
// Assumption made is that this particular app won't need Forms
Auth.
if (!isWindowsUser)
{
Console.WriteLine("Forms Authentications is not supported.");
Console.WriteLine("Application terminated.");
return logonSucceeded;
}
Settings.SetURL(baseUrl);
Settings.SetCredentials();
try
{
string currentUser;
currentUser =
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
if (currentUser != userAccount)
{
Impersonate(userAccount);
}
if (loginWindows.Login())
{
logonSucceeded = true;
}
}
catch {...}
return logonSucceeded;
}
And I call login() like follows:
static void Main()
{
string baseURL = "http://server/pwa/";
string userAccount = "DOMAIN\\User";
bool logonResult;
logonResult = LogonPS(true, userAccount, baseURL);
if (logonResult)
{
// do some tasks
}
}
The thing is that, the user I try to login with does get impersonated but it
won't login to PS with that user. Like, after logging in with another user I
still get my own user as the one who's logged in. Am I doing this process
correctly? As I said I wrote the whole program with the aid of the SDK and as
I mentioned the program does impersonate the user but doesn't login with that
user.
Impersonation but still haven't figured out how to login with another user
accout. Here's my Impersonation function (exactly taken from the SDK):
private static void Impersonate(string userAccount)
{
try
{
// PWAGUID is a const already defined
Guid siteId = new Guid(PWAGUID);
// Get the GUID of the user to impersonate.
Guid userGuid = GetResourceUid(userAccount);
Console.WriteLine("User GUID to impersonate: " +
userGuid.ToString());
bool isWindowsUser = true;
if (userAccount.Contains("aspnetsqlmembershipprovider"))
isWindowsUser = false;
ResourceDerived.SetImpersonationContext(isWindowsUser,
userAccount,
userGuid, Guid.Empty, siteId, "1033");
// To get the GUID of the user we are impersonating,
// call GetCurrentUserUid in the Resource Web service.
Guid impersonatedUserGuid = resProxyBySSP.GetCurrentUserUid();
Console.WriteLine(string.Format("\nImpersonating
'{0}':\n\tResourceProxy.Url:\n\t{1}",
userAccount, resProxyBySSP.Url));
Console.Write("\nImpersonated user GUID: ");
Console.WriteLine(impersonatedUserGuid.ToString());
}
catch {...}
}
The later on in my code I have a login function again taken from the SDK:
public static bool LogonPS(bool isWindowsUser, string userAccount, string
baseUrl)
{
bool logonSucceeded = false;
// Assumption made is that this particular app won't need Forms
Auth.
if (!isWindowsUser)
{
Console.WriteLine("Forms Authentications is not supported.");
Console.WriteLine("Application terminated.");
return logonSucceeded;
}
Settings.SetURL(baseUrl);
Settings.SetCredentials();
try
{
string currentUser;
currentUser =
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
if (currentUser != userAccount)
{
Impersonate(userAccount);
}
if (loginWindows.Login())
{
logonSucceeded = true;
}
}
catch {...}
return logonSucceeded;
}
And I call login() like follows:
static void Main()
{
string baseURL = "http://server/pwa/";
string userAccount = "DOMAIN\\User";
bool logonResult;
logonResult = LogonPS(true, userAccount, baseURL);
if (logonResult)
{
// do some tasks
}
}
The thing is that, the user I try to login with does get impersonated but it
won't login to PS with that user. Like, after logging in with another user I
still get my own user as the one who's logged in. Am I doing this process
correctly? As I said I wrote the whole program with the aid of the SDK and as
I mentioned the program does impersonate the user but doesn't login with that
user.