aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorJustin Clark-Casey2014-05-27 23:29:54 +0100
committerJustin Clark-Casey2014-05-27 23:29:54 +0100
commit3f703ae1cb02cbcb0efaff061d495bacca941de0 (patch)
tree3221068b4bc4119023b3dfa621c19e126c2eb3f3 /OpenSim/Framework
parentMerge branch 'master' into 0.8-post-fixes (diff)
parentminor: Comment out 2 error level debugging message in authentication code (diff)
downloadopensim-SC_OLD-3f703ae1cb02cbcb0efaff061d495bacca941de0.zip
opensim-SC_OLD-3f703ae1cb02cbcb0efaff061d495bacca941de0.tar.gz
opensim-SC_OLD-3f703ae1cb02cbcb0efaff061d495bacca941de0.tar.bz2
opensim-SC_OLD-3f703ae1cb02cbcb0efaff061d495bacca941de0.tar.xz
Merge branch 'master' into 0.8-post-fixes
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/AgentCircuitData.cs2
-rw-r--r--OpenSim/Framework/Communications/RestClient.cs29
-rw-r--r--OpenSim/Framework/Console/LocalConsole.cs12
-rw-r--r--OpenSim/Framework/Serialization/External/LandDataSerializer.cs18
-rw-r--r--OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs3
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs19
-rw-r--r--OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs24
-rw-r--r--OpenSim/Framework/ServiceAuth/BasicHttpAuthentication.cs79
-rw-r--r--OpenSim/Framework/ServiceAuth/IServiceAuth.cs15
-rw-r--r--OpenSim/Framework/ServiceAuth/ServiceAuth.cs23
-rw-r--r--OpenSim/Framework/WebUtil.cs113
11 files changed, 297 insertions, 40 deletions
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
321 Mac = args["mac"].AsString(); 321 Mac = args["mac"].AsString();
322 if (args["id0"] != null) 322 if (args["id0"] != null)
323 Id0 = args["id0"].AsString(); 323 Id0 = args["id0"].AsString();
324 if (args["teleport_flags"] != null)
325 teleportFlags = args["teleport_flags"].AsUInteger();
324 326
325 if (args["start_pos"] != null) 327 if (args["start_pos"] != null)
326 Vector3.TryParse(args["start_pos"].AsString(), out startpos); 328 Vector3.TryParse(args["start_pos"].AsString(), out startpos);
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;
35using System.Web; 35using System.Web;
36using log4net; 36using log4net;
37 37
38using OpenSim.Framework.ServiceAuth;
39
38namespace OpenSim.Framework.Communications 40namespace OpenSim.Framework.Communications
39{ 41{
40 /// <summary> 42 /// <summary>
@@ -297,7 +299,7 @@ namespace OpenSim.Framework.Communications
297 /// <summary> 299 /// <summary>
298 /// Perform a synchronous request 300 /// Perform a synchronous request
299 /// </summary> 301 /// </summary>
300 public Stream Request() 302 public Stream Request(IServiceAuth auth)
301 { 303 {
302 lock (_lock) 304 lock (_lock)
303 { 305 {
@@ -307,6 +309,8 @@ namespace OpenSim.Framework.Communications
307 _request.Timeout = 200000; 309 _request.Timeout = 200000;
308 _request.Method = RequestMethod; 310 _request.Method = RequestMethod;
309 _asyncException = null; 311 _asyncException = null;
312 if (auth != null)
313 auth.AddAuthorization(_request.Headers);
310 314
311// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); 315// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request);
312 try 316 try
@@ -358,7 +362,7 @@ namespace OpenSim.Framework.Communications
358 } 362 }
359 } 363 }
360 364
361 public Stream Request(Stream src) 365 public Stream Request(Stream src, IServiceAuth auth)
362 { 366 {
363 _request = (HttpWebRequest) WebRequest.Create(buildUri()); 367 _request = (HttpWebRequest) WebRequest.Create(buildUri());
364 _request.KeepAlive = false; 368 _request.KeepAlive = false;
@@ -367,6 +371,8 @@ namespace OpenSim.Framework.Communications
367 _request.Method = RequestMethod; 371 _request.Method = RequestMethod;
368 _asyncException = null; 372 _asyncException = null;
369 _request.ContentLength = src.Length; 373 _request.ContentLength = src.Length;
374 if (auth != null)
375 auth.AddAuthorization(_request.Headers);
370 376
371 m_log.InfoFormat("[REST]: Request Length {0}", _request.ContentLength); 377 m_log.InfoFormat("[REST]: Request Length {0}", _request.ContentLength);
372 m_log.InfoFormat("[REST]: Sending Web Request {0}", buildUri()); 378 m_log.InfoFormat("[REST]: Sending Web Request {0}", buildUri());
@@ -384,7 +390,22 @@ namespace OpenSim.Framework.Communications
384 length = src.Read(buf, 0, 1024); 390 length = src.Read(buf, 0, 1024);
385 } 391 }
386 392
387 _response = (HttpWebResponse) _request.GetResponse(); 393 try
394 {
395 _response = (HttpWebResponse)_request.GetResponse();
396 }
397 catch (WebException e)
398 {
399 m_log.WarnFormat("[REST]: Request {0} {1} failed with status {2} and message {3}",
400 RequestMethod, _request.RequestUri, e.Status, e.Message);
401 }
402 catch (Exception e)
403 {
404 m_log.WarnFormat(
405 "[REST]: Request {0} {1} failed with exception {2} {3}",
406 RequestMethod, _request.RequestUri, e.Message, e.StackTrace);
407 }
408
388 409
389// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); 410// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request);
390 411
@@ -423,7 +444,7 @@ namespace OpenSim.Framework.Communications
423 try 444 try
424 { 445 {
425 // Perform the operation; if sucessful set the result 446 // Perform the operation; if sucessful set the result
426 Stream s = Request(); 447 Stream s = Request(null);
427 ar.SetAsCompleted(s, false); 448 ar.SetAsCompleted(s, false);
428 } 449 }
429 catch (Exception e) 450 catch (Exception e)
diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs
index a967db6..260a86f 100644
--- a/OpenSim/Framework/Console/LocalConsole.cs
+++ b/OpenSim/Framework/Console/LocalConsole.cs
@@ -46,6 +46,11 @@ namespace OpenSim.Framework.Console
46 // private readonly object m_syncRoot = new object(); 46 // private readonly object m_syncRoot = new object();
47 private const string LOGLEVEL_NONE = "(none)"; 47 private const string LOGLEVEL_NONE = "(none)";
48 48
49 // Used to extract categories for colourization.
50 private Regex m_categoryRegex
51 = new Regex(
52 @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)", RegexOptions.Singleline | RegexOptions.Compiled);
53
49 private int m_cursorYPosition = -1; 54 private int m_cursorYPosition = -1;
50 private int m_cursorXPosition = 0; 55 private int m_cursorXPosition = 0;
51 private StringBuilder m_commandLine = new StringBuilder(); 56 private StringBuilder m_commandLine = new StringBuilder();
@@ -280,11 +285,8 @@ namespace OpenSim.Framework.Console
280 string outText = text; 285 string outText = text;
281 286
282 if (level != LOGLEVEL_NONE) 287 if (level != LOGLEVEL_NONE)
283 { 288 {
284 string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)"; 289 MatchCollection matches = m_categoryRegex.Matches(text);
285
286 Regex RE = new Regex(regex, RegexOptions.Multiline);
287 MatchCollection matches = RE.Matches(text);
288 290
289 if (matches.Count == 1) 291 if (matches.Count == 1)
290 { 292 {
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
213 xtw.WriteElementString("ClaimDate", Convert.ToString(landData.ClaimDate)); 213 xtw.WriteElementString("ClaimDate", Convert.ToString(landData.ClaimDate));
214 xtw.WriteElementString("ClaimPrice", Convert.ToString(landData.ClaimPrice)); 214 xtw.WriteElementString("ClaimPrice", Convert.ToString(landData.ClaimPrice));
215 xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); 215 xtw.WriteElementString("GlobalID", landData.GlobalID.ToString());
216 xtw.WriteElementString("GroupID", landData.GroupID.ToString()); 216
217 xtw.WriteElementString("IsGroupOwned", Convert.ToString(landData.IsGroupOwned)); 217 UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.GroupID;
218 xtw.WriteElementString("GroupID", groupID.ToString());
219
220 bool isGroupOwned = options.ContainsKey("wipe-owners") ? false : landData.IsGroupOwned;
221 xtw.WriteElementString("IsGroupOwned", Convert.ToString(isGroupOwned));
222
218 xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap)); 223 xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap));
219 xtw.WriteElementString("Description", landData.Description); 224 xtw.WriteElementString("Description", landData.Description);
220 xtw.WriteElementString("Flags", Convert.ToString((uint)landData.Flags)); 225 xtw.WriteElementString("Flags", Convert.ToString((uint)landData.Flags));
@@ -227,13 +232,8 @@ namespace OpenSim.Framework.Serialization.External
227 xtw.WriteElementString("MediaURL", landData.MediaURL); 232 xtw.WriteElementString("MediaURL", landData.MediaURL);
228 xtw.WriteElementString("MusicURL", landData.MusicURL); 233 xtw.WriteElementString("MusicURL", landData.MusicURL);
229 234
230 UUID ownerIdToWrite; 235 UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.OwnerID;
231 if (options != null && options.ContainsKey("wipe-owners")) 236 xtw.WriteElementString("OwnerID", ownerID.ToString());
232 ownerIdToWrite = UUID.Zero;
233 else
234 ownerIdToWrite = landData.OwnerID;
235
236 xtw.WriteElementString("OwnerID", ownerIdToWrite.ToString());
237 237
238 xtw.WriteStartElement("ParcelAccessList"); 238 xtw.WriteStartElement("ParcelAccessList");
239 foreach (LandAccessEntry pal in landData.ParcelAccessList) 239 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
121 TestHelpers.InMethod(); 121 TestHelpers.InMethod();
122// log4net.Config.XmlConfigurator.Configure(); 122// log4net.Config.XmlConfigurator.Configure();
123 123
124 LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, null)); 124 Dictionary<string, object> options = new Dictionary<string, object>();
125 LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, options));
125 Assert.That(ld, Is.Not.Null, "Deserialize(string) returned null"); 126 Assert.That(ld, Is.Not.Null, "Deserialize(string) returned null");
126// Assert.That(ld.AABBMax, Is.EqualTo(land.AABBMax)); 127// Assert.That(ld.AABBMax, Is.EqualTo(land.AABBMax));
127// Assert.That(ld.AABBMin, Is.EqualTo(land.AABBMin)); 128// Assert.That(ld.AABBMin, Is.EqualTo(land.AABBMin));
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 @@
26 */ 26 */
27 27
28using System.IO; 28using System.IO;
29using System.Net;
30using OpenSim.Framework.ServiceAuth;
29 31
30namespace OpenSim.Framework.Servers.HttpServer 32namespace OpenSim.Framework.Servers.HttpServer
31{ 33{
@@ -37,15 +39,30 @@ namespace OpenSim.Framework.Servers.HttpServer
37 /// </remarks> 39 /// </remarks>
38 public abstract class BaseStreamHandler : BaseRequestHandler, IStreamedRequestHandler 40 public abstract class BaseStreamHandler : BaseRequestHandler, IStreamedRequestHandler
39 { 41 {
40 protected BaseStreamHandler(string httpMethod, string path) : this(httpMethod, path, null, null) {} 42 protected IServiceAuth m_Auth;
43
44 protected BaseStreamHandler(string httpMethod, string path) : this(httpMethod, path, null, null) { }
41 45
42 protected BaseStreamHandler(string httpMethod, string path, string name, string description) 46 protected BaseStreamHandler(string httpMethod, string path, string name, string description)
43 : base(httpMethod, path, name, description) {} 47 : base(httpMethod, path, name, description) {}
44 48
49 protected BaseStreamHandler(string httpMethod, string path, IServiceAuth auth)
50 : base(httpMethod, path, null, null)
51 {
52 m_Auth = auth;
53 }
54
45 public virtual byte[] Handle( 55 public virtual byte[] Handle(
46 string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 56 string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
47 { 57 {
48 RequestsReceived++; 58 RequestsReceived++;
59 if (m_Auth != null && !m_Auth.Authenticate(httpRequest.Headers, httpResponse.AddHeader))
60 {
61
62 httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
63 httpResponse.ContentType = "text/plain";
64 return new byte[0];
65 }
49 66
50 byte[] result = ProcessRequest(path, request, httpRequest, httpResponse); 67 byte[] result = ProcessRequest(path, request, httpRequest, httpResponse);
51 68
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
90 } 90 }
91 catch (Exception e) 91 catch (Exception e)
92 { 92 {
93 m_log.Debug(string.Format("JsonRpc request '{0}' failed", method), e); 93 m_log.Debug(string.Format("JsonRpc request '{0}' to {1} failed", method, uri), e);
94 return false; 94 return false;
95 } 95 }
96 96
97 if (!response.ContainsKey("_Result")) 97 if (!response.ContainsKey("_Result"))
98 { 98 {
99 m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}", 99 m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}",
100 method, OSDParser.SerializeJsonString(response)); 100 method, uri, OSDParser.SerializeJsonString(response));
101 return false; 101 return false;
102 } 102 }
103 response = (OSDMap)response["_Result"]; 103 response = (OSDMap)response["_Result"];
@@ -107,15 +107,15 @@ namespace OpenSim.Framework.Servers.HttpServer
107 if (response.ContainsKey("error")) 107 if (response.ContainsKey("error"))
108 { 108 {
109 data = response["error"]; 109 data = response["error"];
110 m_log.DebugFormat("JsonRpc request '{0}' returned an error: {1}", 110 m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an error: {2}",
111 method, OSDParser.SerializeJsonString(data)); 111 method, uri, OSDParser.SerializeJsonString(data));
112 return false; 112 return false;
113 } 113 }
114 114
115 if (!response.ContainsKey("result")) 115 if (!response.ContainsKey("result"))
116 { 116 {
117 m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}", 117 m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}",
118 method, OSDParser.SerializeJsonString(response)); 118 method, uri, OSDParser.SerializeJsonString(response));
119 return false; 119 return false;
120 } 120 }
121 121
@@ -161,14 +161,14 @@ namespace OpenSim.Framework.Servers.HttpServer
161 } 161 }
162 catch (Exception e) 162 catch (Exception e)
163 { 163 {
164 m_log.Debug(string.Format("JsonRpc request '{0}' failed", method), e); 164 m_log.Debug(string.Format("JsonRpc request '{0}' to {1} failed", method, uri), e);
165 return false; 165 return false;
166 } 166 }
167 167
168 if (!response.ContainsKey("_Result")) 168 if (!response.ContainsKey("_Result"))
169 { 169 {
170 m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}", 170 m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}",
171 method, OSDParser.SerializeJsonString(response)); 171 method, uri, OSDParser.SerializeJsonString(response));
172 return false; 172 return false;
173 } 173 }
174 response = (OSDMap)response["_Result"]; 174 response = (OSDMap)response["_Result"];
@@ -176,8 +176,8 @@ namespace OpenSim.Framework.Servers.HttpServer
176 if (response.ContainsKey("error")) 176 if (response.ContainsKey("error"))
177 { 177 {
178 data = response["error"]; 178 data = response["error"];
179 m_log.DebugFormat("JsonRpc request '{0}' returned an error: {1}", 179 m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an error: {2}",
180 method, OSDParser.SerializeJsonString(data)); 180 method, uri, OSDParser.SerializeJsonString(data));
181 return false; 181 return false;
182 } 182 }
183 183
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 @@
1using System;
2using System.Collections.Generic;
3using System.Collections.Specialized;
4using System.Reflection;
5
6using Nini.Config;
7using log4net;
8
9namespace OpenSim.Framework.ServiceAuth
10{
11 public class BasicHttpAuthentication : IServiceAuth
12 {
13 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
14
15 private string m_Username, m_Password;
16 private string m_CredentialsB64;
17
18 private string remove_me;
19
20 public string Credentials
21 {
22 get { return m_CredentialsB64; }
23 }
24
25 public BasicHttpAuthentication(IConfigSource config, string section)
26 {
27 remove_me = section;
28 m_Username = Util.GetConfigVarFromSections<string>(config, "HttpAuthUsername", new string[] { "Network", section }, string.Empty);
29 m_Password = Util.GetConfigVarFromSections<string>(config, "HttpAuthPassword", new string[] { "Network", section }, string.Empty);
30 string str = m_Username + ":" + m_Password;
31 byte[] encData_byte = Util.UTF8.GetBytes(str);
32
33 m_CredentialsB64 = Convert.ToBase64String(encData_byte);
34 m_log.DebugFormat("[HTTP BASIC AUTH]: {0} {1} [{2}]", m_Username, m_Password, section);
35 }
36
37 public void AddAuthorization(NameValueCollection headers)
38 {
39 //m_log.DebugFormat("[HTTP BASIC AUTH]: Adding authorization for {0}", remove_me);
40 headers["Authorization"] = "Basic " + m_CredentialsB64;
41 }
42
43 public bool Authenticate(string data)
44 {
45 string recovered = Util.Base64ToString(data);
46 if (!String.IsNullOrEmpty(recovered))
47 {
48 string[] parts = recovered.Split(new char[] { ':' });
49 if (parts.Length >= 2)
50 {
51 return m_Username.Equals(parts[0]) && m_Password.Equals(parts[1]);
52 }
53 }
54
55 return false;
56 }
57
58 public bool Authenticate(NameValueCollection requestHeaders, AddHeaderDelegate d)
59 {
60 //m_log.DebugFormat("[HTTP BASIC AUTH]: Authenticate in {0}", remove_me);
61 if (requestHeaders != null)
62 {
63 string value = requestHeaders.Get("Authorization");
64 if (value != null)
65 {
66 value = value.Trim();
67 if (value.StartsWith("Basic "))
68 {
69 value = value.Replace("Basic ", string.Empty);
70 if (Authenticate(value))
71 return true;
72 }
73 }
74 }
75 d("WWW-Authenticate", "Basic realm = \"Asset Server\"");
76 return false;
77 }
78 }
79}
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 @@
1using System;
2using System.Collections.Generic;
3using System.Collections.Specialized;
4
5namespace OpenSim.Framework.ServiceAuth
6{
7 public delegate void AddHeaderDelegate(string key, string value);
8
9 public interface IServiceAuth
10 {
11 bool Authenticate(string data);
12 bool Authenticate(NameValueCollection headers, AddHeaderDelegate d);
13 void AddAuthorization(NameValueCollection headers);
14 }
15}
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 @@
1using System;
2using System.Collections.Generic;
3
4using Nini.Config;
5
6namespace OpenSim.Framework.ServiceAuth
7{
8 public class ServiceAuth
9 {
10 public static IServiceAuth Create(IConfigSource config, string section)
11 {
12 string authType = Util.GetConfigVarFromSections<string>(config, "AuthType", new string[] { "Network", section }, "None");
13
14 switch (authType)
15 {
16 case "BasicHttpAuthentication":
17 return new BasicHttpAuthentication(config, section);
18 }
19
20 return null;
21 }
22 }
23}
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index 70fab77..e614fd5 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -45,6 +45,8 @@ using Nwc.XmlRpc;
45using OpenMetaverse.StructuredData; 45using OpenMetaverse.StructuredData;
46using XMLResponseHelper = OpenSim.Framework.SynchronousRestObjectRequester.XMLResponseHelper; 46using XMLResponseHelper = OpenSim.Framework.SynchronousRestObjectRequester.XMLResponseHelper;
47 47
48using OpenSim.Framework.ServiceAuth;
49
48namespace OpenSim.Framework 50namespace OpenSim.Framework
49{ 51{
50 /// <summary> 52 /// <summary>
@@ -773,6 +775,13 @@ namespace OpenSim.Framework
773 string requestUrl, TRequest obj, Action<TResponse> action, 775 string requestUrl, TRequest obj, Action<TResponse> action,
774 int maxConnections) 776 int maxConnections)
775 { 777 {
778 MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, action, maxConnections, null);
779 }
780
781 public static void MakeRequest<TRequest, TResponse>(string verb,
782 string requestUrl, TRequest obj, Action<TResponse> action,
783 int maxConnections, IServiceAuth auth)
784 {
776 int reqnum = WebUtil.RequestNumber++; 785 int reqnum = WebUtil.RequestNumber++;
777 786
778 if (WebUtil.DebugLevel >= 3) 787 if (WebUtil.DebugLevel >= 3)
@@ -786,6 +795,10 @@ namespace OpenSim.Framework
786 795
787 WebRequest request = WebRequest.Create(requestUrl); 796 WebRequest request = WebRequest.Create(requestUrl);
788 HttpWebRequest ht = (HttpWebRequest)request; 797 HttpWebRequest ht = (HttpWebRequest)request;
798
799 if (auth != null)
800 auth.AddAuthorization(ht.Headers);
801
789 if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) 802 if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
790 ht.ServicePoint.ConnectionLimit = maxConnections; 803 ht.ServicePoint.ConnectionLimit = maxConnections;
791 804
@@ -969,7 +982,7 @@ namespace OpenSim.Framework
969 /// 982 ///
970 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting 983 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting
971 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception> 984 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
972 public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs) 985 public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs, IServiceAuth auth)
973 { 986 {
974 int reqnum = WebUtil.RequestNumber++; 987 int reqnum = WebUtil.RequestNumber++;
975 988
@@ -984,6 +997,10 @@ namespace OpenSim.Framework
984 request.Method = verb; 997 request.Method = verb;
985 if (timeoutsecs > 0) 998 if (timeoutsecs > 0)
986 request.Timeout = timeoutsecs * 1000; 999 request.Timeout = timeoutsecs * 1000;
1000
1001 if (auth != null)
1002 auth.AddAuthorization(request.Headers);
1003
987 string respstring = String.Empty; 1004 string respstring = String.Empty;
988 1005
989 using (MemoryStream buffer = new MemoryStream()) 1006 using (MemoryStream buffer = new MemoryStream())
@@ -1068,10 +1085,20 @@ namespace OpenSim.Framework
1068 return respstring; 1085 return respstring;
1069 } 1086 }
1070 1087
1088 public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs)
1089 {
1090 return MakeRequest(verb, requestUrl, obj, timeoutsecs, null);
1091 }
1092
1071 public static string MakeRequest(string verb, string requestUrl, string obj) 1093 public static string MakeRequest(string verb, string requestUrl, string obj)
1072 { 1094 {
1073 return MakeRequest(verb, requestUrl, obj, -1); 1095 return MakeRequest(verb, requestUrl, obj, -1);
1074 } 1096 }
1097
1098 public static string MakeRequest(string verb, string requestUrl, string obj, IServiceAuth auth)
1099 {
1100 return MakeRequest(verb, requestUrl, obj, -1, auth);
1101 }
1075 } 1102 }
1076 1103
1077 public class SynchronousRestObjectRequester 1104 public class SynchronousRestObjectRequester
@@ -1085,23 +1112,76 @@ namespace OpenSim.Framework
1085 /// </summary> 1112 /// </summary>
1086 /// <param name="verb"></param> 1113 /// <param name="verb"></param>
1087 /// <param name="requestUrl"></param> 1114 /// <param name="requestUrl"></param>
1088 /// <param name="obj"> </param> 1115 /// <param name="obj"></param>
1089 /// <returns></returns> 1116 /// <returns>
1090 /// 1117 /// The response. If there was an internal exception, then the default(TResponse) is returned.
1091 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting 1118 /// </returns>
1092 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
1093 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj) 1119 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj)
1094 { 1120 {
1095 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0); 1121 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0);
1096 } 1122 }
1097 1123
1124 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, IServiceAuth auth)
1125 {
1126 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0, auth);
1127 }
1128 /// <summary>
1129 /// Perform a synchronous REST request.
1130 /// </summary>
1131 /// <param name="verb"></param>
1132 /// <param name="requestUrl"></param>
1133 /// <param name="obj"></param>
1134 /// <param name="pTimeout">
1135 /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds)
1136 /// </param>
1137 /// <returns>
1138 /// The response. If there was an internal exception or the request timed out,
1139 /// then the default(TResponse) is returned.
1140 /// </returns>
1098 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout) 1141 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout)
1099 { 1142 {
1100 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0); 1143 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0);
1101 } 1144 }
1102 1145
1146 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, IServiceAuth auth)
1147 {
1148 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0, auth);
1149 }
1150
1151 /// Perform a synchronous REST request.
1152 /// </summary>
1153 /// <param name="verb"></param>
1154 /// <param name="requestUrl"></param>
1155 /// <param name="obj"></param>
1156 /// <param name="pTimeout">
1157 /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds)
1158 /// </param>
1159 /// <param name="maxConnections"></param>
1160 /// <returns>
1161 /// The response. If there was an internal exception or the request timed out,
1162 /// then the default(TResponse) is returned.
1163 /// </returns>
1103 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections) 1164 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections)
1104 { 1165 {
1166 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, maxConnections, null);
1167 }
1168
1169 /// <summary>
1170 /// Perform a synchronous REST request.
1171 /// </summary>
1172 /// <param name="verb"></param>
1173 /// <param name="requestUrl"></param>
1174 /// <param name="obj"></param>
1175 /// <param name="pTimeout">
1176 /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds)
1177 /// </param>
1178 /// <param name="maxConnections"></param>
1179 /// <returns>
1180 /// The response. If there was an internal exception or the request timed out,
1181 /// then the default(TResponse) is returned.
1182 /// </returns>
1183 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections, IServiceAuth auth)
1184 {
1105 int reqnum = WebUtil.RequestNumber++; 1185 int reqnum = WebUtil.RequestNumber++;
1106 1186
1107 if (WebUtil.DebugLevel >= 3) 1187 if (WebUtil.DebugLevel >= 3)
@@ -1116,6 +1196,13 @@ namespace OpenSim.Framework
1116 1196
1117 WebRequest request = WebRequest.Create(requestUrl); 1197 WebRequest request = WebRequest.Create(requestUrl);
1118 HttpWebRequest ht = (HttpWebRequest)request; 1198 HttpWebRequest ht = (HttpWebRequest)request;
1199
1200 if (auth != null)
1201 auth.AddAuthorization(ht.Headers);
1202
1203 if (pTimeout != 0)
1204 ht.Timeout = pTimeout;
1205
1119 if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) 1206 if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
1120 ht.ServicePoint.ConnectionLimit = maxConnections; 1207 ht.ServicePoint.ConnectionLimit = maxConnections;
1121 1208
@@ -1191,8 +1278,18 @@ namespace OpenSim.Framework
1191 { 1278 {
1192 using (HttpWebResponse hwr = (HttpWebResponse)e.Response) 1279 using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
1193 { 1280 {
1194 if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound) 1281 if (hwr != null)
1195 return deserial; 1282 {
1283 if (hwr.StatusCode == HttpStatusCode.NotFound)
1284 return deserial;
1285 if (hwr.StatusCode == HttpStatusCode.Unauthorized)
1286 {
1287 m_log.Error(string.Format(
1288 "[SynchronousRestObjectRequester]: Web request {0} requires authentication ",
1289 requestUrl));
1290 return deserial;
1291 }
1292 }
1196 else 1293 else
1197 m_log.Error(string.Format( 1294 m_log.Error(string.Format(
1198 "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} ", 1295 "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} ",