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.
parent
f7eac63e01
commit
c3e604c46c
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Nwc.XmlRpc;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace OpenSim.Framework.Communications.Clients
|
||||
{
|
||||
public class AuthClient
|
||||
{
|
||||
public static string GetNewKey(string authurl, UUID userID, UUID authToken)
|
||||
{
|
||||
//Hashtable keyParams = new Hashtable();
|
||||
//keyParams["user_id"] = userID;
|
||||
//keyParams["auth_token"] = authKey;
|
||||
|
||||
List<string> SendParams = new List<string>();
|
||||
SendParams.Add(userID.ToString());
|
||||
SendParams.Add(authToken.ToString());
|
||||
|
||||
XmlRpcRequest request = new XmlRpcRequest("hg_new_auth_key", SendParams);
|
||||
XmlRpcResponse reply;
|
||||
try
|
||||
{
|
||||
reply = request.Send(authurl, 6000);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Console.WriteLine("[HGrid]: Failed to get new key. Reason: " + e.Message);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (!reply.IsFault)
|
||||
{
|
||||
string newKey = string.Empty;
|
||||
if (reply.Value != null)
|
||||
newKey = (string)reply.Value;
|
||||
|
||||
return newKey;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Console.WriteLine("[HGrid]: XmlRpc request to get auth key failed with message {0}" + reply.FaultString + ", code " + reply.FaultCode);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static bool VerifyKey(string authurl, UUID userID, string authKey)
|
||||
{
|
||||
List<string> SendParams = new List<string>();
|
||||
SendParams.Add(userID.ToString());
|
||||
SendParams.Add(authKey);
|
||||
|
||||
XmlRpcRequest request = new XmlRpcRequest("hg_verify_auth_key", SendParams);
|
||||
XmlRpcResponse reply;
|
||||
try
|
||||
{
|
||||
reply = request.Send(authurl, 6000);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Console.WriteLine("[HGrid]: Failed to verify key. Reason: " + e.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!reply.IsFault)
|
||||
{
|
||||
bool success = false;
|
||||
if (reply.Value != null)
|
||||
success = (bool)reply.Value;
|
||||
|
||||
return success;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Console.WriteLine("[HGrid]: XmlRpc request to verify key failed with message {0}" + reply.FaultString + ", code " + reply.FaultCode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ using Nini.Config;
|
|||
using OpenMetaverse;
|
||||
using OpenSim.Data;
|
||||
using OpenSim.Framework;
|
||||
//using OpenSim.Framework.Communications;
|
||||
using OpenSim.Framework.Communications.Clients;
|
||||
using OpenSim.Framework.Communications.Cache;
|
||||
using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
|
||||
using LLSDHelpers = OpenSim.Framework.Communications.Capabilities.LLSDHelpers;
|
||||
|
@ -64,6 +64,7 @@ namespace OpenSim.Framework.Communications.Services
|
|||
// These two used for remote access
|
||||
string m_UserServerURL = string.Empty;
|
||||
string m_AssetServerURL = string.Empty;
|
||||
SynchronousGridAssetClient m_AssetClient = null;
|
||||
|
||||
// Constructor for grid inventory server
|
||||
public HGInventoryService(InventoryServiceBase invService, string assetServiceURL, string userServiceURL, IHttpServer httpserver, string thisurl)
|
||||
|
@ -71,6 +72,8 @@ namespace OpenSim.Framework.Communications.Services
|
|||
m_UserServerURL = userServiceURL;
|
||||
m_AssetServerURL = assetServiceURL;
|
||||
|
||||
m_AssetClient = new SynchronousGridAssetClient(m_AssetServerURL);
|
||||
|
||||
Init(invService, thisurl, httpserver);
|
||||
}
|
||||
|
||||
|
@ -298,7 +301,7 @@ namespace OpenSim.Framework.Communications.Services
|
|||
Item.Owner = olditem.Owner;
|
||||
// There should be some tests here about the owner, etc but I'm going to ignore that
|
||||
// because I'm not sure it makes any sense
|
||||
// Also I should probably close the asset...
|
||||
// Also I should probably clone the asset...
|
||||
m_inventoryService.AddItem(Item);
|
||||
return Item;
|
||||
}
|
||||
|
@ -319,7 +322,7 @@ namespace OpenSim.Framework.Communications.Services
|
|||
public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID)
|
||||
{
|
||||
UUID userID = new UUID(rawUserID);
|
||||
return ((InventoryServiceBase)m_inventoryService).GetInventorySkeleton(userID);
|
||||
return m_inventoryService.GetInventorySkeleton(userID);
|
||||
}
|
||||
|
||||
public List<InventoryItemBase> GetActiveGestures(Guid rawUserID)
|
||||
|
@ -328,7 +331,7 @@ namespace OpenSim.Framework.Communications.Services
|
|||
|
||||
m_log.InfoFormat("[HGStandaloneInvService]: fetching active gestures for user {0}", userID);
|
||||
|
||||
return ((InventoryServiceBase)m_inventoryService).GetActiveGestures(userID);
|
||||
return m_inventoryService.GetActiveGestures(userID);
|
||||
}
|
||||
|
||||
public AssetBase GetAsset(InventoryItemBase item)
|
||||
|
@ -348,8 +351,10 @@ namespace OpenSim.Framework.Communications.Services
|
|||
}
|
||||
|
||||
// All good, get the asset
|
||||
AssetBase theasset = m_assetProvider.FetchAsset(item.AssetID);
|
||||
m_log.Debug("[HGStandaloneInvService] Found asset " + ((theasset == null)? "NULL" : "Not Null"));
|
||||
//AssetBase theasset = m_assetProvider.FetchAsset(item.AssetID);
|
||||
AssetBase theasset = FetchAsset(item.AssetID, (item.InvType == (int)InventoryType.Texture));
|
||||
|
||||
m_log.Debug("[HGStandaloneInvService] Found asset " + ((theasset == null) ? "NULL" : "Not Null"));
|
||||
if (theasset != null)
|
||||
{
|
||||
asset = theasset;
|
||||
|
@ -361,7 +366,8 @@ namespace OpenSim.Framework.Communications.Services
|
|||
public bool PostAsset(AssetBase asset)
|
||||
{
|
||||
m_log.Info("[HGStandaloneInvService]: Post asset " + asset.FullID);
|
||||
m_assetProvider.CreateAsset(asset);
|
||||
//m_assetProvider.CreateAsset(asset);
|
||||
StoreAsset(asset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -492,7 +498,7 @@ namespace OpenSim.Framework.Communications.Services
|
|||
return;
|
||||
}
|
||||
|
||||
bool success = ((IAuthentication)m_userService).VerifyKey(userID, authToken);
|
||||
bool success = VerifyKey(userID, authToken);
|
||||
|
||||
if (success)
|
||||
{
|
||||
|
@ -653,5 +659,56 @@ namespace OpenSim.Framework.Communications.Services
|
|||
}
|
||||
|
||||
#endregion Caps
|
||||
|
||||
#region Local vs Remote
|
||||
|
||||
bool VerifyKey(UUID userID, string key)
|
||||
{
|
||||
// Remote call to the Authorization server
|
||||
if (m_userService == null)
|
||||
return AuthClient.VerifyKey(m_UserServerURL, userID, key);
|
||||
// local call
|
||||
else
|
||||
return ((IAuthentication)m_userService).VerifyKey(userID, key);
|
||||
}
|
||||
|
||||
AssetBase FetchAsset(UUID assetID, bool isTexture)
|
||||
{
|
||||
// Remote call to the Asset server
|
||||
if (m_assetProvider == null)
|
||||
return m_AssetClient.SyncGetAsset(assetID, isTexture);
|
||||
// local call
|
||||
else
|
||||
return m_assetProvider.FetchAsset(assetID);
|
||||
}
|
||||
|
||||
void StoreAsset(AssetBase asset)
|
||||
{
|
||||
// Remote call to the Asset server
|
||||
if (m_assetProvider == null)
|
||||
m_AssetClient.StoreAsset(asset);
|
||||
// local call
|
||||
else
|
||||
m_assetProvider.CreateAsset(asset);
|
||||
}
|
||||
|
||||
#endregion Local vs Remote
|
||||
}
|
||||
|
||||
class SynchronousGridAssetClient : GridAssetClient
|
||||
{
|
||||
public SynchronousGridAssetClient(string url)
|
||||
: base(url)
|
||||
{
|
||||
}
|
||||
|
||||
public AssetBase SyncGetAsset(UUID assetID, bool isTexture)
|
||||
{
|
||||
AssetRequest assReq = new AssetRequest();
|
||||
assReq.AssetID = assetID;
|
||||
assReq.IsTexture = isTexture;
|
||||
return base.GetAsset(assReq);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,22 +169,28 @@ namespace OpenSim.Framework.Communications.Services
|
|||
m_log.Debug(" >> Null");
|
||||
}
|
||||
|
||||
// Verify the key of who's calling
|
||||
UUID userID = UUID.Zero;
|
||||
string authKey = string.Empty;
|
||||
UUID.TryParse((string)request.Params[0], out userID);
|
||||
authKey = (string)request.Params[1];
|
||||
|
||||
m_log.InfoFormat("[HGLOGIN] HGVerifyKey called with key ", authKey);
|
||||
bool success = false;
|
||||
|
||||
if (!(m_userManager is IAuthentication))
|
||||
if (request.Params.Count >= 2)
|
||||
{
|
||||
m_log.Debug("[HGLOGIN]: UserManager is not IAuthentication service. Denying.");
|
||||
}
|
||||
else
|
||||
{
|
||||
success = ((IAuthentication)m_userManager).VerifyKey(userID, authKey);
|
||||
// Verify the key of who's calling
|
||||
UUID userID = UUID.Zero;
|
||||
string authKey = string.Empty;
|
||||
if (UUID.TryParse((string)request.Params[0], out userID))
|
||||
{
|
||||
authKey = (string)request.Params[1];
|
||||
|
||||
m_log.InfoFormat("[HGLOGIN] HGVerifyKey called with key ", authKey);
|
||||
|
||||
if (!(m_userManager is IAuthentication))
|
||||
{
|
||||
m_log.Debug("[HGLOGIN]: UserManager is not IAuthentication service. Denying.");
|
||||
}
|
||||
else
|
||||
{
|
||||
success = ((IAuthentication)m_userManager).VerifyKey(userID, authKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XmlRpcResponse response = new XmlRpcResponse();
|
||||
|
|
Loading…
Reference in New Issue