TENCOKACISTROMY: Tak uz jsem (po nekolika hodinach, jak je to u SP zvykem) nasel reseni. Sice mi to tak trosku pripada, jako bezpecnostni dira ze strany SP, ale co se da delat.
Problem je/byl v tom, ze konstruktor SPSite si z nejakyho duvodu neprebere aktualniho uzivatele v pripade, ze je vytvorena ve webservice, a musi se ji predat SPUserToken explicitne.
Jake bylo moje prekvapeni, ze se takto da ziskat i SPUserToken systemu:
public static SPUserToken GetSystemToken(SPSite site) {
SPUserToken token = null;
bool tempCADE = site.CatchAccessDeniedException;
try {
site.CatchAccessDeniedException = false;
token = site.SystemAccount.UserToken;
}
catch (UnauthorizedAccessException) {
SPSecurity.RunWithElevatedPrivileges(() => {
using (SPSite elevSite = new SPSite(site.ID))
token = elevSite.SystemAccount.UserToken;
});
}
finally {
site.CatchAccessDeniedException = tempCADE;
}
return token;
}
public static Microsoft.SharePoint.SPSite ConnectToSharepoint() {
string urlSharepointSite;
var ret = ConnectToSharepoint(out urlSharepointSite);
return ret;
}
public static Microsoft.SharePoint.SPSite ConnectToSharepoint(out string urlSharepointSite) {
urlSharepointSite = "http://www.domain.org";
var site = new Microsoft.SharePoint.SPSite( urlSharepointSite );
return site;
}
public static Microsoft.SharePoint.SPSite ConnectToSharepointAsSystem() {
string urlSharepointSite;
Microsoft.SharePoint.SPUserToken userToken = null;
using (var tmpSite = CSharepointNastroje.PripojitNaSharepoint( out urlSharepointSite )) {
userToken = GetSystemToken(tmpSite);
}
var site = new Microsoft.SharePoint.SPSite(urlSharepointSite, userToken);
return site;
}
Kdyz se zavola "ConnectToSharepointAsSystem()", tak mate pristup vsude.