Added HTTP Authentication also to Groups and offline IM.

bullet-2.82
Diva Canto 2014-05-23 17:31:39 -07:00
parent 227685bea4
commit ff9da24465
6 changed files with 55 additions and 39 deletions

View File

@ -32,10 +32,12 @@ using System.Reflection;
using System.Text; using System.Text;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.ServiceAuth;
using OpenSim.Server.Base; using OpenSim.Server.Base;
using OpenMetaverse; using OpenMetaverse;
using log4net; using log4net;
using Nini.Config;
namespace OpenSim.Groups namespace OpenSim.Groups
{ {
@ -44,17 +46,33 @@ namespace OpenSim.Groups
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private string m_ServerURI; private string m_ServerURI;
private string m_SecretKey; private IServiceAuth m_Auth;
private object m_Lock = new object(); private object m_Lock = new object();
public GroupsServiceRemoteConnector(string url, string secret) public GroupsServiceRemoteConnector(IConfigSource config)
{ {
IConfig groupsConfig = config.Configs["Groups"];
string url = groupsConfig.GetString("GroupsServerURI", string.Empty);
if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
throw new Exception(string.Format("[Groups.RemoteConnector]: Malformed groups server URL {0}. Fix it or disable the Groups feature.", url));
m_ServerURI = url; m_ServerURI = url;
if (!m_ServerURI.EndsWith("/")) if (!m_ServerURI.EndsWith("/"))
m_ServerURI += "/"; m_ServerURI += "/";
m_SecretKey = secret; /// This is from BaseServiceConnector
m_log.DebugFormat("[Groups.RemoteConnector]: Groups server at {0}, secret key {1}", m_ServerURI, m_SecretKey); string authType = Util.GetConfigVarFromSections<string>(config, "AuthType", new string[] { "Network", "Groups" }, "None");
switch (authType)
{
case "BasicHttpAuthentication":
m_Auth = new BasicHttpAuthentication(config, "Groups");
break;
}
///
m_log.DebugFormat("[Groups.RemoteConnector]: Groups server at {0}, authentication {1}",
m_ServerURI, (m_Auth == null ? "None" : m_Auth.GetType().ToString()));
} }
public ExtendedGroupRecord CreateGroup(string RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, public ExtendedGroupRecord CreateGroup(string RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
@ -656,14 +674,13 @@ namespace OpenSim.Groups
private Dictionary<string, object> MakeRequest(string method, Dictionary<string, object> sendData) private Dictionary<string, object> MakeRequest(string method, Dictionary<string, object> sendData)
{ {
sendData["METHOD"] = method; sendData["METHOD"] = method;
if (m_SecretKey != string.Empty)
sendData["KEY"] = m_SecretKey;
string reply = string.Empty; string reply = string.Empty;
lock (m_Lock) lock (m_Lock)
reply = SynchronousRestFormsRequester.MakeRequest("POST", reply = SynchronousRestFormsRequester.MakeRequest("POST",
m_ServerURI + "groups", m_ServerURI + "groups",
ServerUtils.BuildQueryString(sendData)); ServerUtils.BuildQueryString(sendData),
m_Auth);
if (reply == string.Empty) if (reply == string.Empty)
return null; return null;

View File

@ -72,13 +72,7 @@ namespace OpenSim.Groups
private void Init(IConfigSource config) private void Init(IConfigSource config)
{ {
IConfig groupsConfig = config.Configs["Groups"]; m_GroupsService = new GroupsServiceRemoteConnector(config);
string url = groupsConfig.GetString("GroupsServerURI", string.Empty);
if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
throw new Exception(string.Format("[Groups.RemoteConnector]: Malformed groups server URL {0}. Fix it or disable the Groups feature.", url));
string secret = groupsConfig.GetString("SecretKey", string.Empty);
m_GroupsService = new GroupsServiceRemoteConnector(url, secret);
m_Scenes = new List<Scene>(); m_Scenes = new List<Scene>();
} }

View File

@ -36,6 +36,7 @@ using OpenSim.Framework;
using OpenSim.Server.Base; using OpenSim.Server.Base;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
using OpenSim.Framework.Servers.HttpServer; using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Framework.ServiceAuth;
using OpenSim.Server.Handlers.Base; using OpenSim.Server.Handlers.Base;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
@ -69,7 +70,9 @@ namespace OpenSim.Groups
m_GroupsService = new GroupsService(config); m_GroupsService = new GroupsService(config);
server.AddStreamHandler(new GroupsServicePostHandler(m_GroupsService, key)); IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
server.AddStreamHandler(new GroupsServicePostHandler(m_GroupsService, auth));
} }
} }
@ -78,13 +81,11 @@ namespace OpenSim.Groups
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private GroupsService m_GroupsService; private GroupsService m_GroupsService;
private string m_SecretKey = String.Empty;
public GroupsServicePostHandler(GroupsService service, string key) : public GroupsServicePostHandler(GroupsService service, IServiceAuth auth) :
base("POST", "/groups") base("POST", "/groups", auth)
{ {
m_GroupsService = service; m_GroupsService = service;
m_SecretKey = key;
} }
protected override byte[] ProcessRequest(string path, Stream requestData, protected override byte[] ProcessRequest(string path, Stream requestData,
@ -108,20 +109,6 @@ namespace OpenSim.Groups
string method = request["METHOD"].ToString(); string method = request["METHOD"].ToString();
request.Remove("METHOD"); request.Remove("METHOD");
if (!String.IsNullOrEmpty(m_SecretKey)) // Verification required
{
// Sender didn't send key
if (!request.ContainsKey("KEY") || (request["KEY"] == null))
return FailureResult("This service requires a secret key");
// Sender sent wrong key
if (!m_SecretKey.Equals(request["KEY"]))
return FailureResult("Provided key does not match existing one");
// OK, key matches. Remove it.
request.Remove("KEY");
}
m_log.DebugFormat("[Groups.Handler]: {0}", method); m_log.DebugFormat("[Groups.Handler]: {0}", method);
switch (method) switch (method)
{ {

View File

@ -66,7 +66,7 @@ namespace OpenSim.OfflineIM
if (serviceLocation == string.Empty) if (serviceLocation == string.Empty)
m_OfflineIMService = new OfflineIMService(config); m_OfflineIMService = new OfflineIMService(config);
else else
m_OfflineIMService = new OfflineIMServiceRemoteConnector(serviceLocation); m_OfflineIMService = new OfflineIMServiceRemoteConnector(config);
m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages); m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages);
m_log.DebugFormat("[OfflineIM.V2]: Offline messages enabled by {0}", Name); m_log.DebugFormat("[OfflineIM.V2]: Offline messages enabled by {0}", Name);

View File

@ -32,6 +32,7 @@ using System.Reflection;
using System.Text; using System.Text;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.ServiceAuth;
using OpenSim.Server.Base; using OpenSim.Server.Base;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
@ -46,6 +47,7 @@ namespace OpenSim.OfflineIM
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private string m_ServerURI = string.Empty; private string m_ServerURI = string.Empty;
private IServiceAuth m_Auth;
private object m_Lock = new object(); private object m_Lock = new object();
public OfflineIMServiceRemoteConnector(string url) public OfflineIMServiceRemoteConnector(string url)
@ -65,6 +67,18 @@ namespace OpenSim.OfflineIM
m_ServerURI = cnf.GetString("OfflineMessageURL", string.Empty); m_ServerURI = cnf.GetString("OfflineMessageURL", string.Empty);
/// This is from BaseServiceConnector
string authType = Util.GetConfigVarFromSections<string>(config, "AuthType", new string[] { "Network", "Messaging" }, "None");
switch (authType)
{
case "BasicHttpAuthentication":
m_Auth = new BasicHttpAuthentication(config, "Messaging");
break;
}
///
m_log.DebugFormat("[OfflineIM.V2.RemoteConnector]: Offline IM server at {0} with auth {1}",
m_ServerURI, (m_Auth == null ? "None" : m_Auth.GetType().ToString()));
} }
#region IOfflineIMService #region IOfflineIMService
@ -143,7 +157,8 @@ namespace OpenSim.OfflineIM
lock (m_Lock) lock (m_Lock)
reply = SynchronousRestFormsRequester.MakeRequest("POST", reply = SynchronousRestFormsRequester.MakeRequest("POST",
m_ServerURI + "/offlineim", m_ServerURI + "/offlineim",
ServerUtils.BuildQueryString(sendData)); ServerUtils.BuildQueryString(sendData),
m_Auth);
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse( Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
reply); reply);

View File

@ -36,6 +36,7 @@ using OpenSim.Framework;
using OpenSim.Server.Base; using OpenSim.Server.Base;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
using OpenSim.Framework.Servers.HttpServer; using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Framework.ServiceAuth;
using OpenSim.Server.Handlers.Base; using OpenSim.Server.Handlers.Base;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
@ -59,7 +60,9 @@ namespace OpenSim.OfflineIM
m_OfflineIMService = new OfflineIMService(config); m_OfflineIMService = new OfflineIMService(config);
server.AddStreamHandler(new OfflineIMServicePostHandler(m_OfflineIMService)); IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
server.AddStreamHandler(new OfflineIMServicePostHandler(m_OfflineIMService, auth));
} }
} }
@ -69,8 +72,8 @@ namespace OpenSim.OfflineIM
private IOfflineIMService m_OfflineIMService; private IOfflineIMService m_OfflineIMService;
public OfflineIMServicePostHandler(IOfflineIMService service) : public OfflineIMServicePostHandler(IOfflineIMService service, IServiceAuth auth) :
base("POST", "/offlineim") base("POST", "/offlineim", auth)
{ {
m_OfflineIMService = service; m_OfflineIMService = service;
} }