/// <summary> /// Retrieves authentication information from a WSUS server. /// </summary> /// <returns>List of supported authentication methods</returns> private async Task <AuthPlugInInfo[]> GetAuthenticationInfo() { GetAuthConfigResponse authConfigResponse; var httpBinding = new System.ServiceModel.BasicHttpBinding(); var upstreamEndpoint = new System.ServiceModel.EndpointAddress(UpstreamEndpoint.ServerSyncURI); if (upstreamEndpoint.Uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) { httpBinding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport; } // Create a WSUS server sync client IServerSyncWebService serverSyncClient = new ServerSyncWebServiceClient(httpBinding, upstreamEndpoint); // Retrieve the authentication information authConfigResponse = await serverSyncClient.GetAuthConfigAsync(new GetAuthConfigRequest()); if (authConfigResponse == null) { throw new Exception("Authentication config response was null."); } else if (authConfigResponse.GetAuthConfigResponse1.GetAuthConfigResult.AuthInfo == null) { throw new Exception("Authentication config payload was null."); } return(authConfigResponse.GetAuthConfigResponse1.GetAuthConfigResult.AuthInfo); }
private static void RefreshTarget(string server, string login, string password) { try { LogHelper.Debug <ExtendedDistributedCallingService>("Refreshing " + server); using (var cacheRefresher = new ServerSyncWebServiceClient(server)) cacheRefresher.RefreshAll(new Guid(DistributedCache.PageCacheRefresherId), login, password); } catch (Exception ex) { LogHelper.Error <ExtendedDistributedCallingService>("Could not refresh " + server, ex); } }
/// <summary> /// Retrieves a server access cookie based on an authentication cookie. /// </summary> /// <param name="authCookie">The auth cookie to use when requesting the access cookie</param> /// <returns>An access cookie</returns> private async Task <Cookie> GetServerAccessCookie(WebServices.DssAuthentication.AuthorizationCookie authCookie) { var httpBinding = new System.ServiceModel.BasicHttpBinding(); var upstreamEndpoint = new System.ServiceModel.EndpointAddress(UpstreamEndpoint.ServerSyncURI); if (upstreamEndpoint.Uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) { httpBinding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport; } // Create a service client on the default Microsoft upstream server. IServerSyncWebService serverSyncClient = new ServerSyncWebServiceClient(httpBinding, upstreamEndpoint); // Create an access cookie request using the authentication cookie parameter. var cookieRequest = new GetCookieRequest(); cookieRequest.GetCookie = new GetCookieRequestBody(); cookieRequest.GetCookie.authCookies = new WebServices.ServerSync.AuthorizationCookie[] { new WebServices.ServerSync.AuthorizationCookie() }; cookieRequest.GetCookie.authCookies[0].CookieData = authCookie.CookieData; cookieRequest.GetCookie.authCookies[0].PlugInId = authCookie.PlugInId; cookieRequest.GetCookie.oldCookie = null; cookieRequest.GetCookie.protocolVersion = "1.7"; GetCookieResponse cookieResponse; try { cookieResponse = await serverSyncClient.GetCookieAsync(cookieRequest); } catch (System.ServiceModel.FaultException ex) { throw new UpstreamServerException(ex); } if (cookieResponse == null || cookieResponse.GetCookieResponse1.GetCookieResult.EncryptedData == null) { throw new Exception("Failed to get access cookie. Response or cookie is null."); } return(cookieResponse.GetCookieResponse1.GetCookieResult); }