aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/WebUtil.cs
diff options
context:
space:
mode:
authorDiva Canto2014-05-23 16:19:43 -0700
committerDiva Canto2014-05-23 16:19:43 -0700
commit20f20895cf1444071d5edc42e11a1fb94b1b1079 (patch)
tree0c7547590a89eec47886e0a8646f86ebbf449e63 /OpenSim/Framework/WebUtil.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-20f20895cf1444071d5edc42e11a1fb94b1b1079.zip
opensim-SC_OLD-20f20895cf1444071d5edc42e11a1fb94b1b1079.tar.gz
opensim-SC_OLD-20f20895cf1444071d5edc42e11a1fb94b1b1079.tar.bz2
opensim-SC_OLD-20f20895cf1444071d5edc42e11a1fb94b1b1079.tar.xz
Adds optional HTTP Basic Authentication to Robust service connectors.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/WebUtil.cs75
1 files changed, 71 insertions, 4 deletions
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;
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
@@ -1094,6 +1121,10 @@ namespace OpenSim.Framework
1094 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0); 1121 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0);
1095 } 1122 }
1096 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 }
1097 /// <summary> 1128 /// <summary>
1098 /// Perform a synchronous REST request. 1129 /// Perform a synchronous REST request.
1099 /// </summary> 1130 /// </summary>
@@ -1112,7 +1143,11 @@ namespace OpenSim.Framework
1112 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0); 1143 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0);
1113 } 1144 }
1114 1145
1115 /// <summary> 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
1116 /// Perform a synchronous REST request. 1151 /// Perform a synchronous REST request.
1117 /// </summary> 1152 /// </summary>
1118 /// <param name="verb"></param> 1153 /// <param name="verb"></param>
@@ -1128,6 +1163,25 @@ namespace OpenSim.Framework
1128 /// </returns> 1163 /// </returns>
1129 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)
1130 { 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 {
1131 int reqnum = WebUtil.RequestNumber++; 1185 int reqnum = WebUtil.RequestNumber++;
1132 1186
1133 if (WebUtil.DebugLevel >= 3) 1187 if (WebUtil.DebugLevel >= 3)
@@ -1143,6 +1197,9 @@ namespace OpenSim.Framework
1143 WebRequest request = WebRequest.Create(requestUrl); 1197 WebRequest request = WebRequest.Create(requestUrl);
1144 HttpWebRequest ht = (HttpWebRequest)request; 1198 HttpWebRequest ht = (HttpWebRequest)request;
1145 1199
1200 if (auth != null)
1201 auth.AddAuthorization(ht.Headers);
1202
1146 if (pTimeout != 0) 1203 if (pTimeout != 0)
1147 ht.Timeout = pTimeout; 1204 ht.Timeout = pTimeout;
1148 1205
@@ -1221,8 +1278,18 @@ namespace OpenSim.Framework
1221 { 1278 {
1222 using (HttpWebResponse hwr = (HttpWebResponse)e.Response) 1279 using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
1223 { 1280 {
1224 if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound) 1281 if (hwr != null)
1225 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 }
1226 else 1293 else
1227 m_log.Error(string.Format( 1294 m_log.Error(string.Format(
1228 "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} ", 1295 "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} ",