Task update With Impersonation

P

Parth

Hi,
I had written a piece of code for updating the task using impersonation and
code is as follows:
which has Derived class for the statusing :

StatusingDerived.SetImpersonationContext(isWindowsUser,userAccount,
myUserId, Guid.Empty, siteId, "1033");

then it goes to the set impersonation menthod:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services;
using System.Net;
using Microsoft.Office.Project.Server.Library;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace WPSI
{
class StatusingDerived: Statusing
{
private static String contextString = String.Empty;

protected override WebRequest GetWebRequest(Uri uri)
{
//here we are overriding the GetWebRequest method and adding the
2 web request headers
WebRequest webRequest = base.GetWebRequest(uri);
if (contextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
//bool isImpersonating =
(System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
//isImpersonating = true;
webRequest.Credentials =
CredentialCache.DefaultNetworkCredentials;
webRequest.Headers.Add("PjAuth", contextString);
webRequest.Headers.Add("ForwardFrom",
"/_vti_bin/psi/statusing.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
}
public static void SetImpersonationContext(bool isWindowsUser,
String userAccount,
Guid userGuid, Guid
trackingGuid, Guid pwaSiteId, String lcid)
{
contextString = GetImpersonationContext(isWindowsUser,
userAccount,
userGuid, trackingGuid, pwaSiteId, lcid);
}

private static String GetImpersonationContext(bool isWindowsUser,
String userAccount,
Guid userGuid, Guid trackingGuid, Guid pwaSiteId, String lcid)
{
PSLibrary.PSContextInfo contextInfo = new
PSLibrary.PSContextInfo(isWindowsUser, userAccount,
userGuid, trackingGuid, pwaSiteId, lcid);
String contextString =
PSLibrary.PSContextInfo.SerializeToString(contextInfo);
return contextString;
}
}
}

and then
Guid assn = new Guid("DB4E1B8C-0D55-4E61-98D2-AE3D1BCD7EF3");
Guid proj = new Guid("8612CF19-2C96-47EE-9939-B32823369CA9");

changexml = "<Changes>" +
"<Proj ID=\"" + proj+ "\">" +
"<Assn ID=\"" + assn + "\">" +
"<Change
PID=\"251658274\">5</Change>" +
"</Assn>" +
"</Proj>" +
"</Changes>";
staProxy.UpdateStatus(changexml);
staProxy.SubmitStatus(new Guid[] { assn }, "" +
"hiiiiii" + "");

Now I'm getting the Error saying that :

System.Web.Services.Protocols.SoapException: ProjectServerError(s)
LastError=GeneralSecurityAccessDenied Instructions: Pass this into
PSClientError constructor to access all error information
at
Microsoft.Office.Project.Server.WebService.Statusing.UpdateStatus(String
changexml)

Please some one tell me that where i am making mistakes...!!?
 
S

Stephen Sanderlin [MVP]

I don't see any code where you're instantiating and configuring an
object of type StatusingDerived or setting the impersonation context...
can you please post?

--
Stephen Sanderlin, Project MVP
VP of Technology
MSProjectExperts

For Project Server Consulting: http://www.msprojectexperts.com
For Project Server Training: http://www.projectservertraining.com

Read our blog at: http://www.projectserverhelp.com



Hi,
I had written a piece of code for updating the task using impersonation and
code is as follows:
which has Derived class for the statusing :

StatusingDerived.SetImpersonationContext(isWindowsUser,userAccount,
myUserId, Guid.Empty, siteId, "1033");

then it goes to the set impersonation menthod:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services;
using System.Net;
using Microsoft.Office.Project.Server.Library;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace WPSI
{
class StatusingDerived: Statusing
{
private static String contextString = String.Empty;

protected override WebRequest GetWebRequest(Uri uri)
{
//here we are overriding the GetWebRequest method and adding the
2 web request headers
WebRequest webRequest = base.GetWebRequest(uri);
if (contextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
//bool isImpersonating =
(System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
//isImpersonating = true;
webRequest.Credentials =
CredentialCache.DefaultNetworkCredentials;
webRequest.Headers.Add("PjAuth", contextString);
webRequest.Headers.Add("ForwardFrom",
"/_vti_bin/psi/statusing.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
}
public static void SetImpersonationContext(bool isWindowsUser,
String userAccount,
Guid userGuid, Guid
trackingGuid, Guid pwaSiteId, String lcid)
{
contextString = GetImpersonationContext(isWindowsUser,
userAccount,
userGuid, trackingGuid, pwaSiteId, lcid);
}

private static String GetImpersonationContext(bool isWindowsUser,
String userAccount,
Guid userGuid, Guid trackingGuid, Guid pwaSiteId, String lcid)
{
PSLibrary.PSContextInfo contextInfo = new
PSLibrary.PSContextInfo(isWindowsUser, userAccount,
userGuid, trackingGuid, pwaSiteId, lcid);
String contextString =
PSLibrary.PSContextInfo.SerializeToString(contextInfo);
return contextString;
}
}
}

and then
Guid assn = new Guid("DB4E1B8C-0D55-4E61-98D2-AE3D1BCD7EF3");
Guid proj = new Guid("8612CF19-2C96-47EE-9939-B32823369CA9");

changexml = "<Changes>" +
"<Proj ID=\"" + proj+ "\">" +
"<Assn ID=\"" + assn + "\">" +
"<Change
PID=\"251658274\">5</Change>" +
"</Assn>" +
"</Proj>" +
"</Changes>";
staProxy.UpdateStatus(changexml);
staProxy.SubmitStatus(new Guid[] { assn }, "" +
"hiiiiii" + "");

Now I'm getting the Error saying that :

System.Web.Services.Protocols.SoapException: ProjectServerError(s)
LastError=GeneralSecurityAccessDenied Instructions: Pass this into
PSClientError constructor to access all error information
at
Microsoft.Office.Project.Server.WebService.Statusing.UpdateStatus(String
changexml)

Please some one tell me that where i am making mistakes...!!?
 
P

Parth

Hi,
What i will do is i will post all of my code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using PSLibrary = Microsoft.Office.Project.Server.Library;
using System.Configuration;
using System.Web.Services.Protocols;
using System.Security.Authentication;
using System.Net;
using Microsoft.Office.Project.Server.Library;
using System.Globalization;
using Microsoft.SharePoint;

namespace WPSI
{
public partial class Form1 : Form
{
public static string str1 =
ConfigurationSettings.AppSettings["connection"];
public static SqlConnection con1 = new SqlConnection(str1);
SqlCommand cmd = new SqlCommand();
private const string PSI_RESOURCE_SSP = "http://epm:56737/Prject
Server/PSI/Resource.asmx";
private const string SSP_URI_STATUSING = "http://epm:56737/Project
Server";

string PROJECT_SERVER_URI = "http://epm/Projects";
string LOGINWINDOWS = "LoginWindows.asmx";
string STATUSWEBSERVICE = "/_vti_bin/psi/statusing.asmx";
//string SECURITYSERVICE = "security.asmx";
string RESOURCE_SERVICE_PATH = "resource.asmx";
//string PSI_RESOURCE_SSP
="http://ServerName:56737/SSPName/PSI/Resource.asmx";


WbSvcLogin.LoginWindows login = new WPSI.WbSvcLogin.LoginWindows();
WbSvcStatus.Statusing sta = new WPSI.WbSvcStatus.Statusing();
WbSvcResource.Resource resourceSvc = new
WPSI.WbSvcResource.Resource();

//WbSvcSecurity.Security security = new WPSI.WbSvcSecurity.Security();
static ResourceDerived resProxyBySSP=new ResourceDerived();
static StatusingDerived staProxy = new StatusingDerived();

private const string PWA_SITE_GUID =
"36a409ce-0763-423e-9f65-64f8e03fc37a";

string userAccount = @"epm\PM";
private SqlDataAdapter da;
private SqlConnection conn;
BindingSource bsource = new BindingSource();
DataSet ds = null;
string sql;
public Form1()
{
InitializeComponent();

/*string connectionString = "Data Source=EPM\\PS;Initial
Catalog=Master;Persist Security Info=True;User ID=sa;Password=pass@word1;";
conn = new SqlConnection(connectionString);
sql = "SELECT * from PSIDATA";
conn.Open();
da = new SqlDataAdapter(sql, conn);
conn.Close();
conn.Open();
ds = new DataSet();
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(da);
da.Fill(ds, "psi");*/

string changexml = "";
CookieContainer cookiecontainer = new CookieContainer();
//security.Url = PROJECT_SERVER_URI + SECURITYSERVICE;
//security.CookieContainer = cookiecontainer;
//security.UseDefaultCredentials = true;
login.Credentials = System.Net.CredentialCache.DefaultCredentials;
login.Url = "http://epm/projects/_vti_bin/PSI/" + LOGINWINDOWS;
login.CookieContainer = cookiecontainer;
login.UseDefaultCredentials = true;
bool abc=login.Login();
staProxy.Credentials =
System.Net.CredentialCache.DefaultCredentials;
//staProxy.Url = "http://epm/projects/_vti_bin/PSI/" +
"Statusing.asmx";

resourceSvc.Url = "http://epm/projects/_vti_bin/PSI/" +
RESOURCE_SERVICE_PATH;
resourceSvc.UseDefaultCredentials = true;

//staProxy.Credentials =
System.Net.CredentialCache.DefaultCredentials;
staProxy.Url = "http://epm:56737/Prject
Server/PSI/statusing.asmx";

Guid myUserId = new Guid("00331B2D-E41C-4EBE-A0B2-E64DD22AF9B8");
Guid psUID = PSSecurityGlobalPermission.LogOn;
//Microsoft.SharePoint.SPSite site = new
SPSite(SSP_URI_STATUSING);
//Guid siteId = site.ID;
//resProxyBySSP.Credentials =
System.Net.CredentialCache.DefaultCredentials;

//PSSecurityGlobalPermission.UpdateAndStatusProjectTasks;
Guid siteId = new Guid(PWA_SITE_GUID);

bool isWindowsUser = true;
if (userAccount.Contains("aspnetsqlmembershipprovider"))
isWindowsUser = false;

//ResourceDerived.SetImpersonationContext(isWindowsUser,"epm\\administrator",myUserId, Guid.Empty, siteId, "1033");
//Guid impersonatedUserGuid = resProxyBySSP.GetCurrentUserUid();
//WPSI.excep
//ResourceDerived.SetImpersonationContext(isWindowsUser,
userAccount, myUserId, Guid.Empty, siteId, "1033");

StatusingDerived.SetImpersonationContext(isWindowsUser,userAccount, myUserId,
Guid.Empty, siteId, "1033");
//StatusingDerived.

try
{
//for(int i=0;i<ds.Tables[0].Rows.Count;i++)
// {
Guid assn = new Guid("DB4E1B8C-0D55-4E61-98D2-AE3D1BCD7EF3");
Guid proj = new Guid("8612CF19-2C96-47EE-9939-B32823369CA9");

changexml = "<Changes>" +
"<Proj ID=\"" + proj+ "\">" +
"<Assn ID=\"" + assn + "\">" +
"<Change
PID=\"251658274\">5</Change>" +
"</Assn>" +
"</Proj>" +
"</Changes>";
staProxy.UpdateStatus(changexml);
staProxy.SubmitStatus(new Guid[] { assn }, "" +
"hiiiiii" + "");
//}
}
catch (Exception ex)
{
ex.ToString();
}
}
}
}
-----------------------------------------------------------------------------------------------
and Now below is my StatusingDerived.cs File:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services;
using System.Net;
using Microsoft.Office.Project.Server.Library;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace WPSI
{
class StatusingDerived: Statusing
{
private static String contextString = String.Empty;

protected override WebRequest GetWebRequest(Uri uri)
{
//here we are overriding the GetWebRequest method and adding the
2 web request headers
WebRequest webRequest = base.GetWebRequest(uri);
if (contextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
//bool isImpersonating =
(System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
//isImpersonating = true;
webRequest.Credentials =
CredentialCache.DefaultNetworkCredentials;
webRequest.Headers.Add("PjAuth", contextString);
webRequest.Headers.Add("ForwardFrom",
"/_vti_bin/psi/statusing.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
}
public static void SetImpersonationContext(bool isWindowsUser,
String userAccount,
Guid userGuid, Guid
trackingGuid, Guid pwaSiteId, String lcid)
{
contextString = GetImpersonationContext(isWindowsUser,
userAccount,
userGuid, trackingGuid, pwaSiteId, lcid);
}

private static String GetImpersonationContext(bool isWindowsUser,
String userAccount,
Guid userGuid, Guid trackingGuid, Guid pwaSiteId, String lcid)
{
PSLibrary.PSContextInfo contextInfo = new
PSLibrary.PSContextInfo(isWindowsUser, userAccount,
userGuid, trackingGuid, pwaSiteId, lcid);
String contextString =
PSLibrary.PSContextInfo.SerializeToString(contextInfo);
return contextString;
}
}
}

Hope this will give you some idea , that where i'm Blundering.. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top