replace HttpWebRequest by HttpClient on another place

This commit is contained in:
UbitUmarov
2023-05-16 22:57:23 +01:00
parent 7860e2d861
commit 19229aff64
8 changed files with 244 additions and 59 deletions

View File

@@ -33,6 +33,7 @@ using System.Reflection;
using Nini.Config;
using log4net;
using System.Net.Http.Headers;
namespace OpenSim.Framework.ServiceAuth
{
@@ -54,14 +55,13 @@ namespace OpenSim.Framework.ServiceAuth
public BasicHttpAuthentication(IConfigSource config, string section)
{
// remove_me = section;
m_Username = Util.GetConfigVarFromSections<string>(config, "HttpAuthUsername", new string[] { "Network", section }, string.Empty);
m_Password = Util.GetConfigVarFromSections<string>(config, "HttpAuthPassword", new string[] { "Network", section }, string.Empty);
string str = m_Username + ":" + m_Password;
byte[] encData_byte = Util.UTF8.GetBytes(str);
m_CredentialsB64 = Convert.ToBase64String(encData_byte);
// m_log.DebugFormat("[HTTP BASIC AUTH]: {0} {1} [{2}]", m_Username, m_Password, section);
//m_log.DebugFormat("[HTTP BASIC AUTH]: {0} {1} [{2}]", m_Username, m_Password, section);
}
public void AddAuthorization(NameValueCollection headers)
@@ -70,6 +70,12 @@ namespace OpenSim.Framework.ServiceAuth
headers["Authorization"] = "Basic " + m_CredentialsB64;
}
public void AddAuthorization(HttpRequestHeaders headers)
{
//m_log.DebugFormat("[HTTP BASIC AUTH]: Adding authorization for {0}", remove_me);
headers.TryAddWithoutValidation("Authorization","Basic " + m_CredentialsB64);
}
public bool Authenticate(string data)
{
string recovered = Util.Base64ToString(data);

View File

@@ -30,6 +30,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
namespace OpenSim.Framework.ServiceAuth
{
@@ -62,6 +63,12 @@ namespace OpenSim.Framework.ServiceAuth
auth.AddAuthorization(headers);
}
public void AddAuthorization(HttpRequestHeaders headers)
{
foreach (IServiceAuth auth in m_authentications)
auth.AddAuthorization(headers);
}
public bool Authenticate(string data)
{
return m_authentications.TrueForAll(a => a.Authenticate(data));

View File

@@ -28,6 +28,7 @@
using System;
using System.Collections.Specialized;
using System.Net;
using System.Net.Http.Headers;
namespace OpenSim.Framework.ServiceAuth
{
@@ -35,7 +36,8 @@ namespace OpenSim.Framework.ServiceAuth
{
public string Name { get { return "DisallowllHTTPRequest"; } }
public void AddAuthorization(NameValueCollection headers) {}
public void AddAuthorization(NameValueCollection headers) { }
public void AddAuthorization(HttpRequestHeaders headers) { }
public bool Authenticate(string data)
{

View File

@@ -29,6 +29,7 @@ using System;
using System.Net;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net.Http.Headers;
namespace OpenSim.Framework.ServiceAuth
{
@@ -44,5 +45,6 @@ namespace OpenSim.Framework.ServiceAuth
bool Authenticate(string data);
bool Authenticate(NameValueCollection headers, AddHeaderDelegate d, out HttpStatusCode statusCode);
void AddAuthorization(NameValueCollection headers);
void AddAuthorization(HttpRequestHeaders headers);
}
}