aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authordiva2009-03-29 23:39:00 +0000
committerdiva2009-03-29 23:39:00 +0000
commitc3e604c46c04673a9493251ef63daf9437e37a10 (patch)
tree29bbac800c55ad3a6690046ee95ad23b2f795cd7 /OpenSim
parentAnother bit of refactoring to try to make sense of OpenSim.Framework.Communic... (diff)
downloadopensim-SC-c3e604c46c04673a9493251ef63daf9437e37a10.zip
opensim-SC-c3e604c46c04673a9493251ef63daf9437e37a10.tar.gz
opensim-SC-c3e604c46c04673a9493251ef63daf9437e37a10.tar.bz2
opensim-SC-c3e604c46c04673a9493251ef63daf9437e37a10.tar.xz
Added Authorization client code that interfaces with HGLoginAuthService. Improved error handling in HGLoginAuthService. Instrumented HGInventoryService so that it can interface both with local and remote user and asset services.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Communications/Clients/AuthClient.cs108
-rw-r--r--OpenSim/Framework/Communications/Services/HGInventoryService.cs73
-rw-r--r--OpenSim/Framework/Communications/Services/HGLoginAuthService.cs32
3 files changed, 192 insertions, 21 deletions
diff --git a/OpenSim/Framework/Communications/Clients/AuthClient.cs b/OpenSim/Framework/Communications/Clients/AuthClient.cs
new file mode 100644
index 0000000..95af7e1
--- /dev/null
+++ b/OpenSim/Framework/Communications/Clients/AuthClient.cs
@@ -0,0 +1,108 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using Nwc.XmlRpc;
31using OpenMetaverse;
32
33namespace OpenSim.Framework.Communications.Clients
34{
35 public class AuthClient
36 {
37 public static string GetNewKey(string authurl, UUID userID, UUID authToken)
38 {
39 //Hashtable keyParams = new Hashtable();
40 //keyParams["user_id"] = userID;
41 //keyParams["auth_token"] = authKey;
42
43 List<string> SendParams = new List<string>();
44 SendParams.Add(userID.ToString());
45 SendParams.Add(authToken.ToString());
46
47 XmlRpcRequest request = new XmlRpcRequest("hg_new_auth_key", SendParams);
48 XmlRpcResponse reply;
49 try
50 {
51 reply = request.Send(authurl, 6000);
52 }
53 catch (Exception e)
54 {
55 System.Console.WriteLine("[HGrid]: Failed to get new key. Reason: " + e.Message);
56 return string.Empty;
57 }
58
59 if (!reply.IsFault)
60 {
61 string newKey = string.Empty;
62 if (reply.Value != null)
63 newKey = (string)reply.Value;
64
65 return newKey;
66 }
67 else
68 {
69 System.Console.WriteLine("[HGrid]: XmlRpc request to get auth key failed with message {0}" + reply.FaultString + ", code " + reply.FaultCode);
70 return string.Empty;
71 }
72
73 }
74
75 public static bool VerifyKey(string authurl, UUID userID, string authKey)
76 {
77 List<string> SendParams = new List<string>();
78 SendParams.Add(userID.ToString());
79 SendParams.Add(authKey);
80
81 XmlRpcRequest request = new XmlRpcRequest("hg_verify_auth_key", SendParams);
82 XmlRpcResponse reply;
83 try
84 {
85 reply = request.Send(authurl, 6000);
86 }
87 catch (Exception e)
88 {
89 System.Console.WriteLine("[HGrid]: Failed to verify key. Reason: " + e.Message);
90 return false;
91 }
92
93 if (!reply.IsFault)
94 {
95 bool success = false;
96 if (reply.Value != null)
97 success = (bool)reply.Value;
98
99 return success;
100 }
101 else
102 {
103 System.Console.WriteLine("[HGrid]: XmlRpc request to verify key failed with message {0}" + reply.FaultString + ", code " + reply.FaultCode);
104 return false;
105 }
106 }
107 }
108}
diff --git a/OpenSim/Framework/Communications/Services/HGInventoryService.cs b/OpenSim/Framework/Communications/Services/HGInventoryService.cs
index 33d7722..eef9e80 100644
--- a/OpenSim/Framework/Communications/Services/HGInventoryService.cs
+++ b/OpenSim/Framework/Communications/Services/HGInventoryService.cs
@@ -35,7 +35,7 @@ using Nini.Config;
35using OpenMetaverse; 35using OpenMetaverse;
36using OpenSim.Data; 36using OpenSim.Data;
37using OpenSim.Framework; 37using OpenSim.Framework;
38//using OpenSim.Framework.Communications; 38using OpenSim.Framework.Communications.Clients;
39using OpenSim.Framework.Communications.Cache; 39using OpenSim.Framework.Communications.Cache;
40using Caps = OpenSim.Framework.Communications.Capabilities.Caps; 40using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
41using LLSDHelpers = OpenSim.Framework.Communications.Capabilities.LLSDHelpers; 41using LLSDHelpers = OpenSim.Framework.Communications.Capabilities.LLSDHelpers;
@@ -64,6 +64,7 @@ namespace OpenSim.Framework.Communications.Services
64 // These two used for remote access 64 // These two used for remote access
65 string m_UserServerURL = string.Empty; 65 string m_UserServerURL = string.Empty;
66 string m_AssetServerURL = string.Empty; 66 string m_AssetServerURL = string.Empty;
67 SynchronousGridAssetClient m_AssetClient = null;
67 68
68 // Constructor for grid inventory server 69 // Constructor for grid inventory server
69 public HGInventoryService(InventoryServiceBase invService, string assetServiceURL, string userServiceURL, IHttpServer httpserver, string thisurl) 70 public HGInventoryService(InventoryServiceBase invService, string assetServiceURL, string userServiceURL, IHttpServer httpserver, string thisurl)
@@ -71,6 +72,8 @@ namespace OpenSim.Framework.Communications.Services
71 m_UserServerURL = userServiceURL; 72 m_UserServerURL = userServiceURL;
72 m_AssetServerURL = assetServiceURL; 73 m_AssetServerURL = assetServiceURL;
73 74
75 m_AssetClient = new SynchronousGridAssetClient(m_AssetServerURL);
76
74 Init(invService, thisurl, httpserver); 77 Init(invService, thisurl, httpserver);
75 } 78 }
76 79
@@ -298,7 +301,7 @@ namespace OpenSim.Framework.Communications.Services
298 Item.Owner = olditem.Owner; 301 Item.Owner = olditem.Owner;
299 // There should be some tests here about the owner, etc but I'm going to ignore that 302 // There should be some tests here about the owner, etc but I'm going to ignore that
300 // because I'm not sure it makes any sense 303 // because I'm not sure it makes any sense
301 // Also I should probably close the asset... 304 // Also I should probably clone the asset...
302 m_inventoryService.AddItem(Item); 305 m_inventoryService.AddItem(Item);
303 return Item; 306 return Item;
304 } 307 }
@@ -319,7 +322,7 @@ namespace OpenSim.Framework.Communications.Services
319 public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID) 322 public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID)
320 { 323 {
321 UUID userID = new UUID(rawUserID); 324 UUID userID = new UUID(rawUserID);
322 return ((InventoryServiceBase)m_inventoryService).GetInventorySkeleton(userID); 325 return m_inventoryService.GetInventorySkeleton(userID);
323 } 326 }
324 327
325 public List<InventoryItemBase> GetActiveGestures(Guid rawUserID) 328 public List<InventoryItemBase> GetActiveGestures(Guid rawUserID)
@@ -328,7 +331,7 @@ namespace OpenSim.Framework.Communications.Services
328 331
329 m_log.InfoFormat("[HGStandaloneInvService]: fetching active gestures for user {0}", userID); 332 m_log.InfoFormat("[HGStandaloneInvService]: fetching active gestures for user {0}", userID);
330 333
331 return ((InventoryServiceBase)m_inventoryService).GetActiveGestures(userID); 334 return m_inventoryService.GetActiveGestures(userID);
332 } 335 }
333 336
334 public AssetBase GetAsset(InventoryItemBase item) 337 public AssetBase GetAsset(InventoryItemBase item)
@@ -348,8 +351,10 @@ namespace OpenSim.Framework.Communications.Services
348 } 351 }
349 352
350 // All good, get the asset 353 // All good, get the asset
351 AssetBase theasset = m_assetProvider.FetchAsset(item.AssetID); 354 //AssetBase theasset = m_assetProvider.FetchAsset(item.AssetID);
352 m_log.Debug("[HGStandaloneInvService] Found asset " + ((theasset == null)? "NULL" : "Not Null")); 355 AssetBase theasset = FetchAsset(item.AssetID, (item.InvType == (int)InventoryType.Texture));
356
357 m_log.Debug("[HGStandaloneInvService] Found asset " + ((theasset == null) ? "NULL" : "Not Null"));
353 if (theasset != null) 358 if (theasset != null)
354 { 359 {
355 asset = theasset; 360 asset = theasset;
@@ -361,7 +366,8 @@ namespace OpenSim.Framework.Communications.Services
361 public bool PostAsset(AssetBase asset) 366 public bool PostAsset(AssetBase asset)
362 { 367 {
363 m_log.Info("[HGStandaloneInvService]: Post asset " + asset.FullID); 368 m_log.Info("[HGStandaloneInvService]: Post asset " + asset.FullID);
364 m_assetProvider.CreateAsset(asset); 369 //m_assetProvider.CreateAsset(asset);
370 StoreAsset(asset);
365 371
366 return true; 372 return true;
367 } 373 }
@@ -492,7 +498,7 @@ namespace OpenSim.Framework.Communications.Services
492 return; 498 return;
493 } 499 }
494 500
495 bool success = ((IAuthentication)m_userService).VerifyKey(userID, authToken); 501 bool success = VerifyKey(userID, authToken);
496 502
497 if (success) 503 if (success)
498 { 504 {
@@ -653,5 +659,56 @@ namespace OpenSim.Framework.Communications.Services
653 } 659 }
654 660
655 #endregion Caps 661 #endregion Caps
662
663 #region Local vs Remote
664
665 bool VerifyKey(UUID userID, string key)
666 {
667 // Remote call to the Authorization server
668 if (m_userService == null)
669 return AuthClient.VerifyKey(m_UserServerURL, userID, key);
670 // local call
671 else
672 return ((IAuthentication)m_userService).VerifyKey(userID, key);
673 }
674
675 AssetBase FetchAsset(UUID assetID, bool isTexture)
676 {
677 // Remote call to the Asset server
678 if (m_assetProvider == null)
679 return m_AssetClient.SyncGetAsset(assetID, isTexture);
680 // local call
681 else
682 return m_assetProvider.FetchAsset(assetID);
683 }
684
685 void StoreAsset(AssetBase asset)
686 {
687 // Remote call to the Asset server
688 if (m_assetProvider == null)
689 m_AssetClient.StoreAsset(asset);
690 // local call
691 else
692 m_assetProvider.CreateAsset(asset);
693 }
694
695 #endregion Local vs Remote
696 }
697
698 class SynchronousGridAssetClient : GridAssetClient
699 {
700 public SynchronousGridAssetClient(string url)
701 : base(url)
702 {
703 }
704
705 public AssetBase SyncGetAsset(UUID assetID, bool isTexture)
706 {
707 AssetRequest assReq = new AssetRequest();
708 assReq.AssetID = assetID;
709 assReq.IsTexture = isTexture;
710 return base.GetAsset(assReq);
711 }
712
656 } 713 }
657} 714}
diff --git a/OpenSim/Framework/Communications/Services/HGLoginAuthService.cs b/OpenSim/Framework/Communications/Services/HGLoginAuthService.cs
index 37c8846..cd4ca5c 100644
--- a/OpenSim/Framework/Communications/Services/HGLoginAuthService.cs
+++ b/OpenSim/Framework/Communications/Services/HGLoginAuthService.cs
@@ -169,22 +169,28 @@ namespace OpenSim.Framework.Communications.Services
169 m_log.Debug(" >> Null"); 169 m_log.Debug(" >> Null");
170 } 170 }
171 171
172 // Verify the key of who's calling
173 UUID userID = UUID.Zero;
174 string authKey = string.Empty;
175 UUID.TryParse((string)request.Params[0], out userID);
176 authKey = (string)request.Params[1];
177
178 m_log.InfoFormat("[HGLOGIN] HGVerifyKey called with key ", authKey);
179 bool success = false; 172 bool success = false;
180 173
181 if (!(m_userManager is IAuthentication)) 174 if (request.Params.Count >= 2)
182 { 175 {
183 m_log.Debug("[HGLOGIN]: UserManager is not IAuthentication service. Denying."); 176 // Verify the key of who's calling
184 } 177 UUID userID = UUID.Zero;
185 else 178 string authKey = string.Empty;
186 { 179 if (UUID.TryParse((string)request.Params[0], out userID))
187 success = ((IAuthentication)m_userManager).VerifyKey(userID, authKey); 180 {
181 authKey = (string)request.Params[1];
182
183 m_log.InfoFormat("[HGLOGIN] HGVerifyKey called with key ", authKey);
184
185 if (!(m_userManager is IAuthentication))
186 {
187 m_log.Debug("[HGLOGIN]: UserManager is not IAuthentication service. Denying.");
188 }
189 else
190 {
191 success = ((IAuthentication)m_userManager).VerifyKey(userID, authKey);
192 }
193 }
188 } 194 }
189 195
190 XmlRpcResponse response = new XmlRpcResponse(); 196 XmlRpcResponse response = new XmlRpcResponse();