From faf9ba53fc10d8abcc9e58e98cc887c1f0f49696 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 12 May 2014 19:20:00 +0100 Subject: In SynchronousRestObjectRequester.MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections) actually set timeout on WebRequest if given. Previously, we were doing nothing with this parameter. No effect on current code since none of the 6 callers attempt to use the timeout. --- OpenSim/Framework/WebUtil.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 70fab77..2a309a7 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -1116,6 +1116,8 @@ namespace OpenSim.Framework WebRequest request = WebRequest.Create(requestUrl); HttpWebRequest ht = (HttpWebRequest)request; + ht.Timeout = pTimeout; + if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) ht.ServicePoint.ConnectionLimit = maxConnections; -- cgit v1.1 From 7db4336f1cf612ac8694cd6bd20624d97cf4a7ff Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 12 May 2014 22:05:02 +0100 Subject: minor: Add method doc to SynchronousRestObjectRequester.MakeRequest() methods --- OpenSim/Framework/WebUtil.cs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 2a309a7..37ecd46 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -1085,21 +1085,43 @@ namespace OpenSim.Framework /// /// /// - /// - /// - /// - /// Thrown if we encounter a network issue while posting - /// the request. You'll want to make sure you deal with this as they're not uncommon + /// + /// + /// The response. If there was an internal exception, then the default(TResponse) is returned. + /// public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj) { return MakeRequest(verb, requestUrl, obj, 0); } + /// + /// Perform a synchronous REST request. + /// + /// + /// + /// + /// Request timeout in milliseconds. + /// + /// The response. If there was an internal exception or the request timed out, + /// then the default(TResponse) is returned. + /// public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout) { return MakeRequest(verb, requestUrl, obj, pTimeout, 0); } + /// + /// Perform a synchronous REST request. + /// + /// + /// + /// + /// Request timeout in milliseconds. + /// + /// + /// The response. If there was an internal exception or the request timed out, + /// then the default(TResponse) is returned. + /// public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections) { int reqnum = WebUtil.RequestNumber++; -- cgit v1.1 From bbc1dc6bceb18cc1970109c5069724fba84e9c83 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 12 May 2014 22:37:07 +0100 Subject: Replace existing 0 timeout in internal overloaded SynchronousRestObjectRequester.MakeRequest() methods with proper Timeout.Infinite (-1) instead. Triggered by recent faf9ba53 though this was wrong in the code before, it's just that we didn't actually try to set the timeout given. --- OpenSim/Framework/WebUtil.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 37ecd46..3b73520 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -36,6 +36,7 @@ using System.Net; using System.Net.Security; using System.Reflection; using System.Text; +using System.Threading; using System.Web; using System.Xml; using System.Xml.Serialization; @@ -1091,7 +1092,7 @@ namespace OpenSim.Framework /// public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj) { - return MakeRequest(verb, requestUrl, obj, 0); + return MakeRequest(verb, requestUrl, obj, Timeout.Infinite); } /// @@ -1100,7 +1101,7 @@ namespace OpenSim.Framework /// /// /// - /// Request timeout in milliseconds. + /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. /// /// The response. If there was an internal exception or the request timed out, /// then the default(TResponse) is returned. @@ -1116,7 +1117,7 @@ namespace OpenSim.Framework /// /// /// - /// Request timeout in milliseconds. + /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. /// /// /// The response. If there was an internal exception or the request timed out, -- cgit v1.1 From 4569c595bf9f56662c8d434917e78db60514396e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 13 May 2014 22:21:20 +0100 Subject: Fix behaviour change in recent commit bbc1dc6 so that SynchronousRestObjectRequester.MakeRequest() calls with no timeout specified use the default HttpWebRequest timeout as previously. I mistakenly thought that that default request timeout was inifite rather than 100 seconds, restoring previously behaviour. As per http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout%28v=vs.100%29.aspx Relates to http://opensimulator.org/mantis/view.php?id=7165 --- OpenSim/Framework/WebUtil.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 3b73520..0970fd1 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -36,7 +36,6 @@ using System.Net; using System.Net.Security; using System.Reflection; using System.Text; -using System.Threading; using System.Web; using System.Xml; using System.Xml.Serialization; @@ -1092,7 +1091,7 @@ namespace OpenSim.Framework /// public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj) { - return MakeRequest(verb, requestUrl, obj, Timeout.Infinite); + return MakeRequest(verb, requestUrl, obj, 0); } /// @@ -1101,7 +1100,9 @@ namespace OpenSim.Framework /// /// /// - /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. + /// + /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds) + /// /// /// The response. If there was an internal exception or the request timed out, /// then the default(TResponse) is returned. @@ -1117,7 +1118,9 @@ namespace OpenSim.Framework /// /// /// - /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. + /// + /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds) + /// /// /// /// The response. If there was an internal exception or the request timed out, @@ -1139,7 +1142,9 @@ namespace OpenSim.Framework WebRequest request = WebRequest.Create(requestUrl); HttpWebRequest ht = (HttpWebRequest)request; - ht.Timeout = pTimeout; + + if (pTimeout != 0) + ht.Timeout = pTimeout; if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) ht.ServicePoint.ConnectionLimit = maxConnections; -- cgit v1.1 From 882af7195ca6d7ac5f36f4121f65aab1302ad272 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Fri, 16 May 2014 13:18:04 +0300 Subject: Better error-handling and logging in case User Profile requests fail --- .../Servers/HttpServer/JsonRpcRequestManager.cs | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs index ed6a14c..2fe1a7d 100644 --- a/OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs @@ -90,14 +90,14 @@ namespace OpenSim.Framework.Servers.HttpServer } catch (Exception e) { - m_log.Debug(string.Format("JsonRpc request '{0}' failed", method), e); + m_log.Debug(string.Format("JsonRpc request '{0}' to {1} failed", method, uri), e); return false; } if (!response.ContainsKey("_Result")) { - m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}", - method, OSDParser.SerializeJsonString(response)); + m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}", + method, uri, OSDParser.SerializeJsonString(response)); return false; } response = (OSDMap)response["_Result"]; @@ -107,15 +107,15 @@ namespace OpenSim.Framework.Servers.HttpServer if (response.ContainsKey("error")) { data = response["error"]; - m_log.DebugFormat("JsonRpc request '{0}' returned an error: {1}", - method, OSDParser.SerializeJsonString(data)); + m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an error: {2}", + method, uri, OSDParser.SerializeJsonString(data)); return false; } if (!response.ContainsKey("result")) { - m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}", - method, OSDParser.SerializeJsonString(response)); + m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}", + method, uri, OSDParser.SerializeJsonString(response)); return false; } @@ -161,14 +161,14 @@ namespace OpenSim.Framework.Servers.HttpServer } catch (Exception e) { - m_log.Debug(string.Format("JsonRpc request '{0}' failed", method), e); + m_log.Debug(string.Format("JsonRpc request '{0}' to {1} failed", method, uri), e); return false; } if (!response.ContainsKey("_Result")) { - m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}", - method, OSDParser.SerializeJsonString(response)); + m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}", + method, uri, OSDParser.SerializeJsonString(response)); return false; } response = (OSDMap)response["_Result"]; @@ -176,8 +176,8 @@ namespace OpenSim.Framework.Servers.HttpServer if (response.ContainsKey("error")) { data = response["error"]; - m_log.DebugFormat("JsonRpc request '{0}' returned an error: {1}", - method, OSDParser.SerializeJsonString(data)); + m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an error: {2}", + method, uri, OSDParser.SerializeJsonString(data)); return false; } -- cgit v1.1 From 251b93d97eb6d8d56c4deb1f6f56dbe2092c2976 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Wed, 21 May 2014 19:05:20 +0300 Subject: Store the Teleport Flags in the Circuit. This doesn't seem to be necessary, because everything has worked so far, but it's the right thing to do. --- OpenSim/Framework/AgentCircuitData.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs index f2fe494..0d053e4 100644 --- a/OpenSim/Framework/AgentCircuitData.cs +++ b/OpenSim/Framework/AgentCircuitData.cs @@ -321,6 +321,8 @@ namespace OpenSim.Framework Mac = args["mac"].AsString(); if (args["id0"] != null) Id0 = args["id0"].AsString(); + if (args["teleport_flags"] != null) + teleportFlags = args["teleport_flags"].AsUInteger(); if (args["start_pos"] != null) Vector3.TryParse(args["start_pos"].AsString(), out startpos); -- cgit v1.1 From fbcb76383d5083a7a1b4c4ba75d37b247859a87d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 23 May 2014 20:57:50 +0100 Subject: Allow console output to be multiline by making colourization regex RegexOptions.SingleLine --- OpenSim/Framework/Console/LocalConsole.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs index a967db6..b17b8e0 100644 --- a/OpenSim/Framework/Console/LocalConsole.cs +++ b/OpenSim/Framework/Console/LocalConsole.cs @@ -283,7 +283,7 @@ namespace OpenSim.Framework.Console { string regex = @"^(?.*?)\[(?[^\]]+)\]:?(?.*)"; - Regex RE = new Regex(regex, RegexOptions.Multiline); + Regex RE = new Regex(regex, RegexOptions.Singleline); MatchCollection matches = RE.Matches(text); if (matches.Count == 1) -- cgit v1.1 From f55e15363665ac885b51fa549c9c1566e9ea0cc6 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 23 May 2014 21:09:48 +0100 Subject: Compile the regex that extract categories for colourization just once rather than on every single log. Compiling every time is unnecessary since Regex is thread-safe. --- OpenSim/Framework/Console/LocalConsole.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs index b17b8e0..260a86f 100644 --- a/OpenSim/Framework/Console/LocalConsole.cs +++ b/OpenSim/Framework/Console/LocalConsole.cs @@ -46,6 +46,11 @@ namespace OpenSim.Framework.Console // private readonly object m_syncRoot = new object(); private const string LOGLEVEL_NONE = "(none)"; + // Used to extract categories for colourization. + private Regex m_categoryRegex + = new Regex( + @"^(?.*?)\[(?[^\]]+)\]:?(?.*)", RegexOptions.Singleline | RegexOptions.Compiled); + private int m_cursorYPosition = -1; private int m_cursorXPosition = 0; private StringBuilder m_commandLine = new StringBuilder(); @@ -280,11 +285,8 @@ namespace OpenSim.Framework.Console string outText = text; if (level != LOGLEVEL_NONE) - { - string regex = @"^(?.*?)\[(?[^\]]+)\]:?(?.*)"; - - Regex RE = new Regex(regex, RegexOptions.Singleline); - MatchCollection matches = RE.Matches(text); + { + MatchCollection matches = m_categoryRegex.Matches(text); if (matches.Count == 1) { -- cgit v1.1 From 20f20895cf1444071d5edc42e11a1fb94b1b1079 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 23 May 2014 16:19:43 -0700 Subject: Adds optional HTTP Basic Authentication to Robust service connectors. --- OpenSim/Framework/Communications/RestClient.cs | 29 ++++++-- .../Servers/HttpServer/BaseStreamHandler.cs | 19 +++++- .../ServiceAuth/BasicHttpAuthentication.cs | 79 ++++++++++++++++++++++ OpenSim/Framework/ServiceAuth/IServiceAuth.cs | 15 ++++ OpenSim/Framework/ServiceAuth/ServiceAuth.cs | 23 +++++++ OpenSim/Framework/WebUtil.cs | 75 ++++++++++++++++++-- 6 files changed, 231 insertions(+), 9 deletions(-) create mode 100644 OpenSim/Framework/ServiceAuth/BasicHttpAuthentication.cs create mode 100644 OpenSim/Framework/ServiceAuth/IServiceAuth.cs create mode 100644 OpenSim/Framework/ServiceAuth/ServiceAuth.cs (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs index e7f0ca8..89e6aa1 100644 --- a/OpenSim/Framework/Communications/RestClient.cs +++ b/OpenSim/Framework/Communications/RestClient.cs @@ -35,6 +35,8 @@ using System.Threading; using System.Web; using log4net; +using OpenSim.Framework.ServiceAuth; + namespace OpenSim.Framework.Communications { /// @@ -297,7 +299,7 @@ namespace OpenSim.Framework.Communications /// /// Perform a synchronous request /// - public Stream Request() + public Stream Request(IServiceAuth auth) { lock (_lock) { @@ -307,6 +309,8 @@ namespace OpenSim.Framework.Communications _request.Timeout = 200000; _request.Method = RequestMethod; _asyncException = null; + if (auth != null) + auth.AddAuthorization(_request.Headers); // IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); try @@ -358,7 +362,7 @@ namespace OpenSim.Framework.Communications } } - public Stream Request(Stream src) + public Stream Request(Stream src, IServiceAuth auth) { _request = (HttpWebRequest) WebRequest.Create(buildUri()); _request.KeepAlive = false; @@ -367,6 +371,8 @@ namespace OpenSim.Framework.Communications _request.Method = RequestMethod; _asyncException = null; _request.ContentLength = src.Length; + if (auth != null) + auth.AddAuthorization(_request.Headers); m_log.InfoFormat("[REST]: Request Length {0}", _request.ContentLength); m_log.InfoFormat("[REST]: Sending Web Request {0}", buildUri()); @@ -384,7 +390,22 @@ namespace OpenSim.Framework.Communications length = src.Read(buf, 0, 1024); } - _response = (HttpWebResponse) _request.GetResponse(); + try + { + _response = (HttpWebResponse)_request.GetResponse(); + } + catch (WebException e) + { + m_log.WarnFormat("[REST]: Request {0} {1} failed with status {2} and message {3}", + RequestMethod, _request.RequestUri, e.Status, e.Message); + } + catch (Exception e) + { + m_log.WarnFormat( + "[REST]: Request {0} {1} failed with exception {2} {3}", + RequestMethod, _request.RequestUri, e.Message, e.StackTrace); + } + // IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); @@ -423,7 +444,7 @@ namespace OpenSim.Framework.Communications try { // Perform the operation; if sucessful set the result - Stream s = Request(); + Stream s = Request(null); ar.SetAsCompleted(s, false); } catch (Exception e) diff --git a/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs b/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs index 252cc2a..f160734 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs @@ -26,6 +26,8 @@ */ using System.IO; +using System.Net; +using OpenSim.Framework.ServiceAuth; namespace OpenSim.Framework.Servers.HttpServer { @@ -37,15 +39,30 @@ namespace OpenSim.Framework.Servers.HttpServer /// public abstract class BaseStreamHandler : BaseRequestHandler, IStreamedRequestHandler { - protected BaseStreamHandler(string httpMethod, string path) : this(httpMethod, path, null, null) {} + protected IServiceAuth m_Auth; + + protected BaseStreamHandler(string httpMethod, string path) : this(httpMethod, path, null, null) { } protected BaseStreamHandler(string httpMethod, string path, string name, string description) : base(httpMethod, path, name, description) {} + protected BaseStreamHandler(string httpMethod, string path, IServiceAuth auth) + : base(httpMethod, path, null, null) + { + m_Auth = auth; + } + public virtual byte[] Handle( string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { RequestsReceived++; + if (m_Auth != null && !m_Auth.Authenticate(httpRequest.Headers, httpResponse.AddHeader)) + { + + httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized; + httpResponse.ContentType = "text/plain"; + return new byte[0]; + } byte[] result = ProcessRequest(path, request, httpRequest, httpResponse); diff --git a/OpenSim/Framework/ServiceAuth/BasicHttpAuthentication.cs b/OpenSim/Framework/ServiceAuth/BasicHttpAuthentication.cs new file mode 100644 index 0000000..f33a045 --- /dev/null +++ b/OpenSim/Framework/ServiceAuth/BasicHttpAuthentication.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Reflection; + +using Nini.Config; +using log4net; + +namespace OpenSim.Framework.ServiceAuth +{ + public class BasicHttpAuthentication : IServiceAuth + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private string m_Username, m_Password; + private string m_CredentialsB64; + + private string remove_me; + + public string Credentials + { + get { return m_CredentialsB64; } + } + + public BasicHttpAuthentication(IConfigSource config, string section) + { + remove_me = section; + m_Username = Util.GetConfigVarFromSections(config, "HttpAuthUsername", new string[] { "Network", section }, string.Empty); + m_Password = Util.GetConfigVarFromSections(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); + } + + public void AddAuthorization(NameValueCollection headers) + { + //m_log.DebugFormat("[HTTP BASIC AUTH]: Adding authorization for {0}", remove_me); + headers["Authorization"] = "Basic " + m_CredentialsB64; + } + + public bool Authenticate(string data) + { + string recovered = Util.Base64ToString(data); + if (!String.IsNullOrEmpty(recovered)) + { + string[] parts = recovered.Split(new char[] { ':' }); + if (parts.Length >= 2) + { + return m_Username.Equals(parts[0]) && m_Password.Equals(parts[1]); + } + } + + return false; + } + + public bool Authenticate(NameValueCollection requestHeaders, AddHeaderDelegate d) + { + //m_log.DebugFormat("[HTTP BASIC AUTH]: Authenticate in {0}", remove_me); + if (requestHeaders != null) + { + string value = requestHeaders.Get("Authorization"); + if (value != null) + { + value = value.Trim(); + if (value.StartsWith("Basic ")) + { + value = value.Replace("Basic ", string.Empty); + if (Authenticate(value)) + return true; + } + } + } + d("WWW-Authenticate", "Basic realm = \"Asset Server\""); + return false; + } + } +} diff --git a/OpenSim/Framework/ServiceAuth/IServiceAuth.cs b/OpenSim/Framework/ServiceAuth/IServiceAuth.cs new file mode 100644 index 0000000..415dc12 --- /dev/null +++ b/OpenSim/Framework/ServiceAuth/IServiceAuth.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; + +namespace OpenSim.Framework.ServiceAuth +{ + public delegate void AddHeaderDelegate(string key, string value); + + public interface IServiceAuth + { + bool Authenticate(string data); + bool Authenticate(NameValueCollection headers, AddHeaderDelegate d); + void AddAuthorization(NameValueCollection headers); + } +} diff --git a/OpenSim/Framework/ServiceAuth/ServiceAuth.cs b/OpenSim/Framework/ServiceAuth/ServiceAuth.cs new file mode 100644 index 0000000..bc32d90 --- /dev/null +++ b/OpenSim/Framework/ServiceAuth/ServiceAuth.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; + +using Nini.Config; + +namespace OpenSim.Framework.ServiceAuth +{ + public class ServiceAuth + { + public static IServiceAuth Create(IConfigSource config, string section) + { + string authType = Util.GetConfigVarFromSections(config, "AuthType", new string[] { "Network", section }, "None"); + + switch (authType) + { + case "BasicHttpAuthentication": + return new BasicHttpAuthentication(config, section); + } + + return null; + } + } +} diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 0970fd1..e614fd5 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -45,6 +45,8 @@ using Nwc.XmlRpc; using OpenMetaverse.StructuredData; using XMLResponseHelper = OpenSim.Framework.SynchronousRestObjectRequester.XMLResponseHelper; +using OpenSim.Framework.ServiceAuth; + namespace OpenSim.Framework { /// @@ -773,6 +775,13 @@ namespace OpenSim.Framework string requestUrl, TRequest obj, Action action, int maxConnections) { + MakeRequest(verb, requestUrl, obj, action, maxConnections, null); + } + + public static void MakeRequest(string verb, + string requestUrl, TRequest obj, Action action, + int maxConnections, IServiceAuth auth) + { int reqnum = WebUtil.RequestNumber++; if (WebUtil.DebugLevel >= 3) @@ -786,6 +795,10 @@ namespace OpenSim.Framework WebRequest request = WebRequest.Create(requestUrl); HttpWebRequest ht = (HttpWebRequest)request; + + if (auth != null) + auth.AddAuthorization(ht.Headers); + if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) ht.ServicePoint.ConnectionLimit = maxConnections; @@ -969,7 +982,7 @@ namespace OpenSim.Framework /// /// Thrown if we encounter a network issue while posting /// the request. You'll want to make sure you deal with this as they're not uncommon - public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs) + public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs, IServiceAuth auth) { int reqnum = WebUtil.RequestNumber++; @@ -984,6 +997,10 @@ namespace OpenSim.Framework request.Method = verb; if (timeoutsecs > 0) request.Timeout = timeoutsecs * 1000; + + if (auth != null) + auth.AddAuthorization(request.Headers); + string respstring = String.Empty; using (MemoryStream buffer = new MemoryStream()) @@ -1068,10 +1085,20 @@ namespace OpenSim.Framework return respstring; } + public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs) + { + return MakeRequest(verb, requestUrl, obj, timeoutsecs, null); + } + public static string MakeRequest(string verb, string requestUrl, string obj) { return MakeRequest(verb, requestUrl, obj, -1); } + + public static string MakeRequest(string verb, string requestUrl, string obj, IServiceAuth auth) + { + return MakeRequest(verb, requestUrl, obj, -1, auth); + } } public class SynchronousRestObjectRequester @@ -1094,6 +1121,10 @@ namespace OpenSim.Framework return MakeRequest(verb, requestUrl, obj, 0); } + public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, IServiceAuth auth) + { + return MakeRequest(verb, requestUrl, obj, 0, auth); + } /// /// Perform a synchronous REST request. /// @@ -1112,7 +1143,11 @@ namespace OpenSim.Framework return MakeRequest(verb, requestUrl, obj, pTimeout, 0); } - /// + public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout, IServiceAuth auth) + { + return MakeRequest(verb, requestUrl, obj, pTimeout, 0, auth); + } + /// Perform a synchronous REST request. /// /// @@ -1128,6 +1163,25 @@ namespace OpenSim.Framework /// public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections) { + return MakeRequest(verb, requestUrl, obj, pTimeout, maxConnections, null); + } + + /// + /// Perform a synchronous REST request. + /// + /// + /// + /// + /// + /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds) + /// + /// + /// + /// The response. If there was an internal exception or the request timed out, + /// then the default(TResponse) is returned. + /// + public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections, IServiceAuth auth) + { int reqnum = WebUtil.RequestNumber++; if (WebUtil.DebugLevel >= 3) @@ -1143,6 +1197,9 @@ namespace OpenSim.Framework WebRequest request = WebRequest.Create(requestUrl); HttpWebRequest ht = (HttpWebRequest)request; + if (auth != null) + auth.AddAuthorization(ht.Headers); + if (pTimeout != 0) ht.Timeout = pTimeout; @@ -1221,8 +1278,18 @@ namespace OpenSim.Framework { using (HttpWebResponse hwr = (HttpWebResponse)e.Response) { - if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound) - return deserial; + if (hwr != null) + { + if (hwr.StatusCode == HttpStatusCode.NotFound) + return deserial; + if (hwr.StatusCode == HttpStatusCode.Unauthorized) + { + m_log.Error(string.Format( + "[SynchronousRestObjectRequester]: Web request {0} requires authentication ", + requestUrl)); + return deserial; + } + } else m_log.Error(string.Format( "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} ", -- cgit v1.1 From 33cc847c4ac78b890f8ac175c479ab1b1c56cbbf Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Mon, 26 May 2014 15:19:20 +0300 Subject: When saving an OAR in "Publish" mode, also discard Group information --- .../Serialization/External/LandDataSerializer.cs | 18 +++++++++--------- .../Serialization/Tests/LandDataSerializerTests.cs | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index 709b516..4b5326a 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -213,8 +213,13 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("ClaimDate", Convert.ToString(landData.ClaimDate)); xtw.WriteElementString("ClaimPrice", Convert.ToString(landData.ClaimPrice)); xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); - xtw.WriteElementString("GroupID", landData.GroupID.ToString()); - xtw.WriteElementString("IsGroupOwned", Convert.ToString(landData.IsGroupOwned)); + + UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.GroupID; + xtw.WriteElementString("GroupID", groupID.ToString()); + + bool isGroupOwned = options.ContainsKey("wipe-owners") ? false : landData.IsGroupOwned; + xtw.WriteElementString("IsGroupOwned", Convert.ToString(isGroupOwned)); + xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap)); xtw.WriteElementString("Description", landData.Description); xtw.WriteElementString("Flags", Convert.ToString((uint)landData.Flags)); @@ -227,13 +232,8 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("MediaURL", landData.MediaURL); xtw.WriteElementString("MusicURL", landData.MusicURL); - UUID ownerIdToWrite; - if (options != null && options.ContainsKey("wipe-owners")) - ownerIdToWrite = UUID.Zero; - else - ownerIdToWrite = landData.OwnerID; - - xtw.WriteElementString("OwnerID", ownerIdToWrite.ToString()); + UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.OwnerID; + xtw.WriteElementString("OwnerID", ownerID.ToString()); xtw.WriteStartElement("ParcelAccessList"); foreach (LandAccessEntry pal in landData.ParcelAccessList) diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index ea100ee..e81cb78 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -121,7 +121,8 @@ namespace OpenSim.Framework.Serialization.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, null)); + Dictionary options = new Dictionary(); + LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, options)); Assert.That(ld, Is.Not.Null, "Deserialize(string) returned null"); // Assert.That(ld.AABBMax, Is.EqualTo(land.AABBMax)); // Assert.That(ld.AABBMin, Is.EqualTo(land.AABBMin)); -- cgit v1.1