As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
string URI = "http://alfrescoserver/alfresco/wcservice/mg/util/login"; string UPN = "username@domain"; HttpWebRequest request = WebRequest.Create(URI) as HttpWebRequest; WindowsIdentity identity = new WindowsIdentity(UPN); WindowsImpersonationContext context = null; try { context = identity.Impersonate(); request.Credentials = CredentialCache.DefaultNetworkCredentials; } catch (Exception e) { return e.Message + Environment.NewLine + e.StackTrace; } finally { if (context != null) { context.Undo(); } } IWebProxy proxy = new WebProxy(proxyServer, proxyPort); proxy.Credentials = new NetworkCredential(proxyUsername, proxyPassword); request.Proxy = proxy; try { using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader sr = new StreamReader(response.GetResponseStream()); return sr.ReadToEnd(); } } catch (Exception e) { return (e.Message + Environment.NewLine + e.StackTrace); }
string URI = "http://alfrescoserver/alfresco/wcservice/mg/util/login"; string UPN = "username@domain"; // Make a request to a Uniform Resource Identifier (URI) WebRequest request = WebRequest.Create(URI); // Initializes a new instance of the WindowsIdentity class for the user represented by the specified User Principal Name (UPN) WindowsIdentity identity = new WindowsIdentity(UPN); // Represents the Windows user prior to an impersonation operation WindowsImpersonationContext context = null; try { // Start impersonating. Allows code to impersonate a different Windows user context = identity.Impersonate(); // Now impersonating // Access resources using the identity of the authenticated user // Sets the network credentials used for authenticating the request with the Internet resource request.Credentials = CredentialCache.DefaultNetworkCredentials; } catch (Exception e) { return e.Message + Environment.NewLine + e.StackTrace; } finally { if (context != null) { // Revert impersonation. Reverts the user context to the Windows user represented by this object context.Undo(); } } try { // Returns a response to an Internet request using (WebResponse response = request.GetResponse()) { StreamReader sr = new StreamReader(response.GetResponseStream()); return sr.ReadToEnd(); } } catch (Exception e) { return (e.Message + Environment.NewLine + e.StackTrace); }
string URI = "http://alfrescoserver/alfresco/wcservice/mg/util/login"; string UPN = "username@domain"; // Make a request to a Uniform Resource Identifier (URI) WebRequest request = WebRequest.Create(URI); request.CookieContainer = new CookieContainer(1); request.Credentials = new NetworkCredential("username", "p@ssw0rd"); try { // Returns a response to an Internet request using (WebResponse response = request.GetResponse()) { StreamReader sr = new StreamReader(response.GetResponseStream()); return sr.ReadToEnd(); } } catch (Exception e) { return (e.Message + Environment.NewLine + e.StackTrace); }
I've solved the problem!I believe that we had a double-hop problem (http://blogs.msdn.com/b/knowledgecast/archive/2007/01/31/the-double-hop-problem.aspx).This is what had to be done to solve this problem: 1. User that runs my DLL must be Windows Server 2003 domain user 2. Service that uses my DLL must have registered Service Principal Name in Domain controller with user that runs it (user that runs my DLL) 3. User that runs my DLL must not have Account is sensitive and cannot be delegated option selected in Domain controller 4. User that runs my DLL must have Trust this user for delegation to any service (Kerberos only) or Trust this user for delegation to specified services only option selected in Domain controller (if the user is in Windows Server 2003 functional domain this option is available only when you register Service Principal Name with this user) 5. Computer that runs service that uses my DLL must have Trust computer for delegation to any service (Kerberos only) or Trust computer for delegation to specified services only option selected in Domain ControllerThis all (and more) is explained in Microsoft document Troubleshooting Kerberos Delegation. It contains: * checklist for Active Directory, * checklist for Client application, * checklist for Middle tier, * checklist for Back-endplus * configuration examples for common scenarios.You can read more about Windows Authentication in ASP.NET 2.0 (http://msdn.microsoft.com/en-us/library/ff647076.aspx).