public bool Delete(ServerDto serverDto, string tenant, ExternalIdentityProviderDto externalIdentityProvider, Token token) { var url = string.Format(ServiceConfigManager.ExternalIdentityProviderEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant, externalIdentityProvider.EntityID); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Delete, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return string.IsNullOrEmpty(response); }
public string GetStatus(ServerDto server, Token token) { var url = string.Format(ServiceConfigManager.GetServerStatusPostEndPoint, server.Protocol, server.ServerName, server.Port); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); return response; }
public IList<ComputerDto> GetComputers(ServerDto server, Token token) { var url = string.Format(ServiceConfigManager.GetServerComputersPostEndPoint, server.Protocol, server.ServerName, server.Port); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); var computers = JsonConvert.Deserialize<List<ComputerDto>>(response); return computers.Select(computer => new ComputerDto { DomainController = computer.DomainController, HostName = computer.HostName }).ToList(); }
public List<ExternalIdentityProviderDto> GetAll(ServerDto serverDto, string tenantName, Token token) { tenantName = Uri.EscapeDataString(tenantName); var url = string.Format(ServiceConfigManager.GetExternalIdentityProvidersPostEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenantName); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); return JsonConvert.Deserialize<List<ExternalIdentityProviderDto>>(response, true); }
public string Delete(ServerDto serverDto, string tenantName, UserDto user, Token token) { var name = Uri.EscapeDataString(user.Name + "@" + user.Domain); tenantName = Uri.EscapeDataString(tenantName); var url = string.Format(ServiceConfigManager.UserEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenantName, name); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Delete, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); return _webRequestManager.GetResponse(url, requestConfig, headers, null, json); }
public OidcClientDto Get(ServerDto serverDto, string tenant, OidcClientDto oidcClientDto, Token token) { tenant = Uri.EscapeDataString(tenant); var clientId = Uri.EscapeDataString(oidcClientDto.ClientId); var url = string.Format(ServiceConfigManager.OidcClientPostEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant, clientId); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return JsonConvert.Deserialize<OidcClientDto>(response); }
public bool Delete(ServerDto serverDto, string tenant, GroupDto groupDto, Token token) { var principalName = Uri.EscapeDataString(groupDto.GroupName + "@" + groupDto.GroupDomain); tenant = Uri.EscapeDataString(tenant); var url = string.Format(ServiceConfigManager.GroupEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant, principalName); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Delete, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return string.IsNullOrEmpty(response); }
public ActiveDirectoryJoinInfoDto GetActiveDirectory(ServerDto server, Token token) { var url = string.Format(ServiceConfigManager.PostAdfEndPoint, server.Protocol, server.ServerName, server.Port); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); //var authorization = string.Format("{0} {1}", token.TokenType, token.AccessToken); //headers.Add(HttpRequestHeader.Authorization, authorization); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); return JsonConvert.Deserialize<ActiveDirectoryJoinInfoDto>(response); }
public bool LeaveActiveDirectory(ServerDto serverDto, CredentialsDto credentialsDto, Token token) { var url = string.Format(ServiceConfigManager.AdfEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port); var json = JsonConvert.Serialize(credentialsDto); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Delete, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); //var authorization = string.Format("{0} {1}", token.TokenType, token.AccessToken); //headers.Add(HttpRequestHeader.Authorization, authorization); json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower() + "&" + json; var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return string.IsNullOrEmpty(response); }
public RelyingPartyDto Create(ServerDto server, string tenant, RelyingPartyDto relyingParty, Token token) { tenant = Uri.EscapeDataString(tenant); var url = string.Format(ServiceConfigManager.RelyingPartysEndPoint, server.Protocol, server.ServerName, server.Port, tenant); var json = JsonConvert.Serialize(relyingParty); json = SerializationJsonHelper.Cleanup (json); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower() + "&" + json; var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return JsonConvert.Deserialize<RelyingPartyDto>(response); }
public ExternalIdentityProviderDto Create(ServerDto server, string tenantName, ExternalIdentityProviderDto externalIdentityProvider, Token token) { tenantName = Uri.EscapeDataString(tenantName); var url = string.Format(ServiceConfigManager.ExternalIdentityProvidersEndPoint, server.Protocol, server.ServerName, server.Port, tenantName); var dto = typeof(ExternalIdentityProviderDto).Assembly; var json = JsonConvert.Serialize(externalIdentityProvider, true); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower() + "&" + json; var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return JsonConvert.Deserialize<ExternalIdentityProviderDto>(response); }
public TenantDto Create(ServerDto server, TenantDto tenant, Token token) { tenant.Username = tenant.Username + "@" + tenant.Name; var url = string.Format(ServiceConfigManager.TenantsEndPoint, server.Protocol, server.ServerName, server.Port); var json = JsonConvert.Serialize(tenant); json = Cleanup (json); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower() + "&" + json; var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return JsonConvert.Deserialize<TenantDto>(response); }
public UserDto Create(ServerDto serverDto, string tenantName, UserDto userDto, Token token) { tenantName = Uri.EscapeDataString(tenantName); var json = JsonConvert.Serialize(userDto); var url = string.Format(ServiceConfigManager.UsersEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenantName); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(); headers[HttpRequestHeader.Accept] = ServiceConfigManager.JsonContentType; headers[HttpRequestHeader.ContentType] = ServiceConfigManager.JsonContentType; json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower() + "&" + json; var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return JsonConvert.Deserialize<UserDto>(response); }
private WebRequest Compose(string uri, RequestSettings settings, IDictionary<HttpRequestHeader, string> headers, IDictionary<string, string> customHeaders, string postData) { //var url = new Uri (uri); var request = (HttpWebRequest)WebRequest.Create(uri); if (settings != null) { request.Method = settings.Method.ToString().ToUpper(); } if (headers != null) { foreach (var header in headers) { switch (header.Key) { case HttpRequestHeader.UserAgent: request.UserAgent = headers[HttpRequestHeader.UserAgent]; break; case HttpRequestHeader.ContentType: request.ContentType = headers[HttpRequestHeader.ContentType]; break; case HttpRequestHeader.Authorization: request.Headers.Add(HttpRequestHeader.Authorization, headers[HttpRequestHeader.Authorization]); break; case HttpRequestHeader.Accept: request.Accept = headers[HttpRequestHeader.Accept]; break; } } } if (customHeaders != null) { foreach (var header in customHeaders) { request.Headers.Add(header.Key, header.Value); } } if (!string.IsNullOrEmpty(postData)) { HttpWebRequestHelper.WriteStringToRequestStream(request, postData); } return request; }
public ExternalIdentityProviderDto Get(ServerDto serverDto, string tenantName, ExternalIdentityProviderDto externalIdentityProvider, Token token) { var name = Uri.EscapeDataString(externalIdentityProvider.EntityID); tenantName = Uri.EscapeDataString(tenantName); var url = string.Format(ServiceConfigManager.GetExternalIdentityProviderPostEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenantName, externalIdentityProvider.EntityID); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); response = SerializationJsonHelper.JsonToDictionary("subjectFormats", response); var dto = typeof(ExternalIdentityProviderDto).Assembly; return JsonConvert.Deserialize<ExternalIdentityProviderDto>(response, "root", dto.GetTypes(), true); }
public Token Refresh(ServerDto serverDto, LoginDto loginDto, Token tokenToRefresh) { var tenant = Uri.EscapeDataString(loginDto.TenantName); var url = string.Format(ServiceConfigManager.RefreshTokenEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var data = string.Format(ServiceConfigManager.RefreshTokenArguments, tokenToRefresh.RefreshToken, tokenToRefresh.ClientId); var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(); var result = _webRequestManager.GetResponse(url, requestConfig, headers, null, data); var token = JsonConvert.Deserialize<Token>(result); token.RefreshToken = tokenToRefresh.RefreshToken; token.ClientId = tokenToRefresh.ClientId; return token; }
public AuthTokenDto Authenticate(ServerDto serverDto, LoginDto loginDto, string clientId) { var url = string.Format(ServiceConfigManager.SamlLegacyEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, serverDto.StsUrl + "/" + loginDto.TenantName); string soapString = XmlResourceHelper.GetResourceXml("Vmware.Tools.RestSsoAdminSnapIn.Service.xml.SAMLRequest.xml"); int lifeInSeconds = 300; var dt = DateTime.Now; dt = TimeZoneInfo.ConvertTimeToUtc(dt); var dtEnd = dt.AddSeconds(lifeInSeconds); string format = "yyyy-MM-ddTHH:mm:ss.fffZ"; var pass = WrapInCDATA(loginDto.Pass); var principalName = loginDto.User + "@" + loginDto.DomainName; soapString = string.Format(soapString, dt.ToString(format), dtEnd.ToString(format), principalName, pass, dt.ToString(format), dtEnd.ToString(format)); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; //var data = string.Format(ServiceConfigManager.LoginArguments, loginDto.User, loginDto.Pass, loginDto.DomainName, clientId); var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders("text/xml"); var customHeaders = new Dictionary<string,string>(); customHeaders.Add("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue"); var responseFromServer = _webRequestManager.GetResponse(url, requestConfig, headers, customHeaders, soapString); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; using (var reader = new StringReader(responseFromServer)) doc.Load(reader); var node = doc.GetElementsByTagName("saml2:Assertion")[0]; var signature = doc.GetElementsByTagName("ds:SignatureValue")[0]; var rawToken = string.Empty; if (node != null) { rawToken = node.OuterXml; } byte[] bytes = System.Text.Encoding.UTF8.GetBytes(rawToken); rawToken = Convert.ToBase64String(bytes); var token = new Token(rawToken, serverDto.TokenType) { Raw = rawToken, ClientId = clientId, Signature = signature.InnerXml,TokenType = TokenType.SAML.ToString()}; return new AuthTokenDto(Refresh) { Token = token, ClaimsPrincipal = null, Login = loginDto, ServerDto = serverDto }; throw new Exception(responseFromServer); }
public AuthTokenDto Authenticate(ServerDto serverDto, LoginDto loginDto, string clientId) { var tenant = Uri.EscapeDataString(loginDto.TenantName); var url = string.Format(ServiceConfigManager.LoginEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var data = string.Format(ServiceConfigManager.LoginArguments, loginDto.User, loginDto.Pass, loginDto.DomainName, clientId); var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(); var result = _webRequestManager.GetResponse(url, requestConfig, headers, null, data); var token = JsonConvert.Deserialize<Token>(result); token.Raw = result; token.ClientId = clientId; token.TokenType = TokenType.Bearer.ToString(); var certificates = GetCertificates(serverDto, loginDto.TenantName, CertificateScope.TENANT, token); var claimsPrincipal = Validate(serverDto, loginDto.User + "@" + loginDto.DomainName, certificates[certificates.Count - 1], loginDto.TenantName, token.IdToken); if (claimsPrincipal != null) return new AuthTokenDto(Refresh) { Token = token, ClaimsPrincipal = claimsPrincipal, Login = loginDto, ServerDto = serverDto }; return new AuthTokenDto(Refresh) { Token = token, ClaimsPrincipal = claimsPrincipal, Login = loginDto, ServerDto = serverDto }; //throw new AuthenticationException(@"Login Failure: Invalid username or password"); }
public GroupMembershipDto GetMembers(ServerDto serverDto, string tenant, GroupDto groupDto, GroupMemberType type, Token token) { var principalName = Uri.EscapeDataString(groupDto.GroupName + "@" + groupDto.GroupDomain); tenant = Uri.EscapeDataString(tenant); var url = string.Format(ServiceConfigManager.GetAllMembersOfGroupPostEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant, principalName, type); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); return JsonConvert.Deserialize<GroupMembershipDto>(response); }
public GroupDto Update(ServerDto serverDto, string tenant, GroupDto groupDto, Token token) { var principalName = Uri.EscapeDataString(groupDto.GroupName + "@" + groupDto.GroupDomain); tenant = Uri.EscapeDataString(tenant); var url = string.Format(ServiceConfigManager.GroupEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant, principalName); var g = new GroupDto() { GroupDetails = new GroupDetailsDto { Description = groupDto.GroupDetails.Description } }; var json = JsonConvert.Serialize(g); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Put, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower() + "&" + json; var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return JsonConvert.Deserialize<GroupDto>(response); }
public IdentityProviderDto Probe(ServerDto server, string tenant, IdentityProviderDto provider, Token token) { var schemaSerialized = SerializeSchema(provider.Schema); var attributeSerailized = SerializeAttributes (provider.AttributesMap, "attributesMap"); provider.Schema = null; provider.AttributesMap = null; tenant = Uri.EscapeDataString(tenant); var url = string.Format(ServiceConfigManager.IdentityProvidersEndPoint, server.Protocol, server.ServerName, server.Port, tenant); url += "?probe=true"; var dto = typeof(IdentityProviderDto).Assembly; var json = JsonConvert.Serialize(provider,"root", dto.GetTypes(), true); json = SerializationJsonHelper.Cleanup (json); json = json.Substring (0, json.Length - 1); var attributeString = "\"attributesMap\":null,"; if (json.Contains (attributeString)) json = json.Replace (attributeString, attributeSerailized + (string.IsNullOrEmpty(attributeSerailized)? string.Empty : ",")); else json += attributeSerailized; var schemaString = "\"schema\":null,"; if (json.Contains (schemaString)) json = json.Replace (schemaString, schemaSerialized + (string.IsNullOrEmpty(schemaSerialized)? string.Empty : ",")); else json += schemaSerialized; json += "}"; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower() + "&" + json; var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); response = SerializationJsonHelper.JsonToDictionary("attributesMap",response); response = CleanupSchemaJson (response); return JsonConvert.Deserialize<IdentityProviderDto>(response,"root", dto.GetTypes(), true); }
public IdentityProviderDto Get(ServerDto server, string tenant, string provider, Token token) { tenant = Uri.EscapeDataString(tenant); provider = Uri.EscapeDataString(provider); var url = string.Format(ServiceConfigManager.GetIdentityProviderPostEndPoint, server.Protocol, server.ServerName, server.Port, tenant, provider); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); //response = SerializationJsonHelper.JsonToDictionary("attributesMap",response); //response = SchemaJsonToDictionary (response); // response = CleanupSchemaJson(response); // var dto = typeof(IdentityProviderDto).Assembly; // return JsonConvert.Deserialize<IdentityProviderDto>(response,"root", dto.GetTypes(), true); return DeSerialize(response); }
public bool AddUsers(ServerDto serverDto, string tenant, GroupDto groupDto, IList<UserDto> users, Token token) { var principalName = Uri.EscapeDataString(groupDto.GroupName + "@" + groupDto.GroupDomain); tenant = Uri.EscapeDataString(tenant); var queryString = users.Select(x => "members=" + Uri.EscapeDataString(x.Name + "@" + x.Domain)).Aggregate((x, y) => string.Format("{0}&{1}", x, y)); var url = string.Format(ServiceConfigManager.MembersOfGroupEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant, principalName, queryString, GroupMemberType.USER); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Put, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return response != null; }
public string GetSamlTokenFromGss(ServerDto serverDto, string bet, int lifeTimeSeconds=300) { var soapString = XmlResourceHelper.GetResourceXml("Vmware.Tools.RestSsoAdminSnapIn.Service.xml.BETLoginRequest.xml"); var dt = DateTime.Now; dt = TimeZoneInfo.ConvertTimeToUtc(dt); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var dtEnd = dt.AddSeconds(lifeTimeSeconds); string format = "yyyy-MM-ddTHH:mm:ss.fffZ"; var dt1 = dt.ToString(format); var dt2 = dtEnd.ToString(format); soapString = string.Format(soapString, dt1, dt2, dt1, dt2, bet); var customHeaders = new Dictionary<string, string>(); customHeaders.Add("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue"); var headers = ServiceHelper.AddHeaders("text/xml"); var url = serverDto.Url; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var responseFromServer = _webRequestManager.GetResponse(url, requestConfig, headers, customHeaders, soapString); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; using (var reader = new StringReader(responseFromServer)) doc.Load(reader); var node = doc.GetElementsByTagName("saml2:Assertion")[0]; if (node != null) return node.OuterXml; else throw new Exception(responseFromServer); }
public GroupMembershipDto Search(ServerDto serverDto, string tenant, string domain, MemberType memberType, SearchType searchType, Token token, string searchString = null, int limit = 100) { tenant = Uri.EscapeDataString(tenant); var searchValue = string.IsNullOrEmpty(searchString) ? string.Empty : Uri.EscapeDataString(searchString); var queryString = string.Format("?domain={0}&limit={1}&type={2}&searchBy={3}&query={4}", domain, limit, memberType, searchType, searchValue); var url = string.Format(ServiceConfigManager.GetTenantSearchPostEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant); url = url + queryString; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); return JsonConvert.Deserialize<GroupMembershipDto>(response); }
private WebRequest Compose(string uri, RequestSettings settings, IDictionary<HttpRequestHeader, string> headers, string postData) { var request = Compose(uri, settings, headers, null, postData); HttpWebRequestHelper.WriteStringToRequestStream(request, postData); return request; }
public string GetResponse(string uri, RequestSettings settings, IDictionary<HttpRequestHeader, string> headers, IDictionary<string, string> customHeaders, string postData) { Exception error = null; HttpResponse response = null; var request = Compose(uri, settings, headers, customHeaders, postData); var httpRequest = new HttpRequest((HttpWebRequest)request) { Data = postData }; try { response = GetResponse(request); } catch (Exception exception) { error = exception; } var messageId = Guid.NewGuid(); Notify(messageId, httpRequest, response, error); if (error != null) throw error; else return response.Data; }
public TenantConfigurationDto GetConfig(ServerDto serverDto, string tenant, Token token, TenantConfigType type) { tenant = Uri.EscapeDataString(tenant); var url = string.Format(ServiceConfigManager.GetTenantConfigPostEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenant); url += "?type=" + type; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var postData = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, postData); return JsonConvert.Deserialize<TenantConfigurationDto>(response); }
public string GetSamlTokenFromCertificate(ServerDto serverDto, X509Certificate2 cert, RSACryptoServiceProvider rsaKey) { var soapString = XmlResourceHelper.GetResourceXml("Vmware.Tools.RestSsoAdminSnapIn.Service.xml.SamlTokenByCertificate.xml"); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; string signed = ""; var dt = DateTime.Now; var dtStart = TimeZoneInfo.ConvertTimeToUtc(dt); var dtEnd = dtStart.AddMinutes(10); string format = "yyyy-MM-ddTHH:mm:ss.fffZ"; var certString = Convert.ToBase64String(cert.RawData); string dtStartStr = dtStart.ToString(format); string dtEndStr = dtEnd.ToString(format); soapString = string.Format(soapString, dtStartStr, dtEndStr, certString, dtStartStr, dtEndStr); signed = SigningHelper.SignXmlFile(soapString, rsaKey); string xml2 = XmlResourceHelper.GetResourceXml("Vmware.Tools.RestSsoAdminSnapIn.Service.xml.SamlTokenByCertificate2.xml"); xml2 = string.Format(xml2, dtStartStr, dtEndStr, certString, signed, dtStartStr, dtEndStr); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml(xml2); soapString = doc.InnerXml; var customHeaders = new Dictionary<string, string>(); customHeaders.Add("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue"); var headers = ServiceHelper.AddHeaders("text/xml"); var url = serverDto.Url; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var token = _webRequestManager.GetResponse(url, requestConfig, headers, customHeaders, soapString); XmlDocument doc2 = new XmlDocument(); doc2.PreserveWhitespace = false; doc2.LoadXml(token); var node = doc2.GetElementsByTagName("saml2:Assertion")[0]; if (node != null) return node.OuterXml; else throw new Exception(token); }
public string GetSamlTokenFromToken(ServerDto serverDto, string tokenXML, X509Certificate2 cert, RSACryptoServiceProvider rsaKey) { var soapString = XmlResourceHelper.GetResourceXml("Vmware.Tools.RestSsoAdminSnapIn.Service.xml.SamlTokenByToken.xml"); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; string signed = ""; var dt = DateTime.Now; var dtStart = TimeZoneInfo.ConvertTimeToUtc(dt); var dtEnd = dtStart.AddMinutes(10); string format = "yyyy-MM-ddTHH:mm:ss.fffZ"; var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(tokenXML); var samlAssertion = xmlDoc.GetElementsByTagName("Assertion", "urn:oasis:names:tc:SAML:2.0:assertion"); var certString = Convert.ToBase64String(cert.RawData); string dtStartStr = dtStart.ToString(format); string dtEndStr = dtEnd.ToString(format); soapString = string.Format(soapString, dtStartStr, dtEndStr, certString, samlAssertion[0].OuterXml, dtStartStr, dtEndStr); //var rsaKey = PrivateKeyHelper.DecodeRSAPrivateKey(Convert.FromBase64String(keyString)); //var rsaKey = (RSACryptoServiceProvider)cert.PrivateKey; signed = SigningHelper.SignXmlFile(soapString, rsaKey); string xml2 = XmlResourceHelper.GetResourceXml("Vmware.Tools.RestSsoAdminSnapIn.Service.xml.SamlTokenByToken2.xml"); xml2 = string.Format(xml2, dtStartStr, dtEndStr, certString, samlAssertion[0].OuterXml, signed, dtStartStr, dtEndStr); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml(xml2); soapString = doc.InnerXml; var customHeaders = new Dictionary<string, string>(); customHeaders.Add("SOAPAction", "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue"); var headers = ServiceHelper.AddHeaders("text/xml"); var url = serverDto.Url; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var response = _webRequestManager.GetResponse(url, requestConfig, headers, customHeaders, soapString); return response; }