From 6b9125b31944c126fa9bf25529a27de5c3972244 Mon Sep 17 00:00:00 2001 From: diva Date: Fri, 27 Mar 2009 16:23:52 +0000 Subject: Added the hg login procedure to the user server. --- OpenSim/Framework/UserConfig.cs | 32 ++- .../UserServer.Modules/UserLoginAuthService.cs | 223 +++++++++++++++++++++ OpenSim/Grid/UserServer/Main.cs | 8 + 3 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 OpenSim/Grid/UserServer.Modules/UserLoginAuthService.cs (limited to 'OpenSim') diff --git a/OpenSim/Framework/UserConfig.cs b/OpenSim/Framework/UserConfig.cs index 901b57a..ea2cba0 100644 --- a/OpenSim/Framework/UserConfig.cs +++ b/OpenSim/Framework/UserConfig.cs @@ -64,6 +64,19 @@ namespace OpenSim.Framework } } + private Uri m_authUrl; + public Uri AuthUrl + { + get + { + return m_authUrl; + } + set + { + m_authUrl = value; + } + } + private Uri m_gridServerURL; public Uri GridServerURL @@ -80,6 +93,8 @@ namespace OpenSim.Framework public bool EnableLLSDLogin = true; + public bool EnableHGLogin = true; + public UserConfig() { // weird, but UserManagerBase needs this. @@ -111,6 +126,11 @@ namespace OpenSim.Framework "Default Inventory Server URI", "http://127.0.0.1:" + InventoryConfig.DefaultHttpPort + "/", false); + configMember.addConfigurationOption("default_authentication_server", + ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, + "User Server (this) External URI for authentication keys", + "http://localhost:" + UserConfig.DefaultHttpPort + "/", + false); configMember.addConfigurationOption("library_location", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Path to library control file", @@ -131,7 +151,10 @@ namespace OpenSim.Framework "Known good region Y", "1000", false); configMember.addConfigurationOption("enable_llsd_login", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN, "Enable LLSD login support [Currently used by libsl based clients/bots]? true/false", true.ToString(), false); - + + configMember.addConfigurationOption("enable_hg_login", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN, + "Enable Hypergrid login support [Currently used by GridSurfer-proxied clients]? true/false", true.ToString(), false); + configMember.addConfigurationOption("default_loginLevel", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, "Minimum Level a user should have to login [0 default]", "0", false); @@ -156,6 +179,9 @@ namespace OpenSim.Framework case "default_inventory_server": InventoryUrl = new Uri((string) configuration_result); break; + case "default_authentication_server": + AuthUrl = new Uri((string)configuration_result); + break; case "database_provider": DatabaseProvider = (string) configuration_result; break; @@ -177,7 +203,9 @@ namespace OpenSim.Framework case "enable_llsd_login": EnableLLSDLogin = (bool)configuration_result; break; - + case "enable_hg_login": + EnableHGLogin = (bool)configuration_result; + break; case "default_loginLevel": DefaultUserLevel = (uint)configuration_result; break; diff --git a/OpenSim/Grid/UserServer.Modules/UserLoginAuthService.cs b/OpenSim/Grid/UserServer.Modules/UserLoginAuthService.cs new file mode 100644 index 0000000..774b4e1 --- /dev/null +++ b/OpenSim/Grid/UserServer.Modules/UserLoginAuthService.cs @@ -0,0 +1,223 @@ +/* + * 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; +using System.Collections.Generic; +using System.Reflection; +using System.Text.RegularExpressions; +using log4net; +using Nwc.XmlRpc; +using OpenMetaverse; +using OpenSim.Data; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Communications.Capabilities; +using OpenSim.Framework.Servers; + +namespace OpenSim.Grid.UserServer.Modules +{ + + /// + /// Hypergrid login service used in grid mode. + /// + public class UserLoginAuthService : HGLoginAuthService + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public UserConfig m_config; + private readonly IRegionProfileRouter m_regionProfileService; + + protected BaseHttpServer m_httpServer; + + public UserLoginAuthService( + UserManagerBase userManager, IInterServiceInventoryServices inventoryService, + LibraryRootFolder libraryRootFolder, + UserConfig config, string welcomeMess, IRegionProfileRouter regionProfileService) + : base(userManager, welcomeMess, inventoryService, null, true, libraryRootFolder, null) + { + m_config = config; + m_defaultHomeX = m_config.DefaultX; + m_defaultHomeY = m_config.DefaultY; + m_inventoryService = inventoryService; + m_regionProfileService = regionProfileService; + + NetworkServersInfo serversinfo = new NetworkServersInfo(1000, 1000); + serversinfo.GridRecvKey = m_config.GridRecvKey; + serversinfo.GridSendKey = m_config.GridSendKey; + serversinfo.GridURL = m_config.GridServerURL.ToString(); + serversinfo.InventoryURL = m_config.InventoryUrl.ToString(); + serversinfo.UserURL = m_config.AuthUrl.ToString(); + SetServersInfo(serversinfo); + } + + public void RegisterHandlers(BaseHttpServer httpServer) + { + m_httpServer = httpServer; + + httpServer.AddXmlRPCHandler("hg_login", XmlRpcLoginMethod); + httpServer.AddXmlRPCHandler("hg_new_auth_key", XmlRpcGenerateKeyMethod); + httpServer.AddXmlRPCHandler("hg_verify_auth_key", XmlRpcVerifyKeyMethod); + } + + + public override void LogOffUser(UserProfileData theUser, string message) + { + RegionProfileData SimInfo; + try + { + SimInfo = m_regionProfileService.RequestSimProfileData( + theUser.CurrentAgent.Handle, m_config.GridServerURL, + m_config.GridSendKey, m_config.GridRecvKey); + + if (SimInfo == null) + { + m_log.Error("[GRID]: Region user was in isn't currently logged in"); + return; + } + } + catch (Exception) + { + m_log.Error("[GRID]: Unable to look up region to log user off"); + return; + } + + // Prepare notification + Hashtable SimParams = new Hashtable(); + SimParams["agent_id"] = theUser.ID.ToString(); + SimParams["region_secret"] = theUser.CurrentAgent.SecureSessionID.ToString(); + SimParams["region_secret2"] = SimInfo.regionSecret; + //m_log.Info(SimInfo.regionSecret); + SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); + SimParams["message"] = message; + ArrayList SendParams = new ArrayList(); + SendParams.Add(SimParams); + + m_log.InfoFormat( + "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", + SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, + theUser.FirstName + " " + theUser.SurName); + + try + { + XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); + XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); + + if (GridResp.IsFault) + { + m_log.ErrorFormat( + "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", + SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); + } + } + catch (Exception) + { + m_log.Error("[LOGIN]: Error telling region to logout user!"); + } + + // Prepare notification + SimParams = new Hashtable(); + SimParams["agent_id"] = theUser.ID.ToString(); + SimParams["region_secret"] = SimInfo.regionSecret; + //m_log.Info(SimInfo.regionSecret); + SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); + SimParams["message"] = message; + SendParams = new ArrayList(); + SendParams.Add(SimParams); + + m_log.InfoFormat( + "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", + SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, + theUser.FirstName + " " + theUser.SurName); + + try + { + XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); + XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); + + if (GridResp.IsFault) + { + m_log.ErrorFormat( + "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", + SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); + } + } + catch (Exception) + { + m_log.Error("[LOGIN]: Error telling region to logout user!"); + } + //base.LogOffUser(theUser); + } + + protected override RegionInfo RequestClosestRegion(string region) + { + RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(region, + m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey); + + if (profileData != null) + { + return profileData.ToRegionInfo(); + } + else + { + return null; + } + } + + protected override RegionInfo GetRegionInfo(ulong homeRegionHandle) + { + RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionHandle, + m_config.GridServerURL, m_config.GridSendKey, + m_config.GridRecvKey); + if (profileData != null) + { + return profileData.ToRegionInfo(); + } + else + { + return null; + } + } + + protected override RegionInfo GetRegionInfo(UUID homeRegionId) + { + RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionId, + m_config.GridServerURL, m_config.GridSendKey, + m_config.GridRecvKey); + if (profileData != null) + { + return profileData.ToRegionInfo(); + } + else + { + return null; + } + } + + } +} diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index 5a1dfd1..c0cba4a 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -62,6 +62,7 @@ namespace OpenSim.Grid.UserServer protected UserServerFriendsModule m_friendsModule; public UserLoginService m_loginService; + public UserLoginAuthService m_loginAuthService; public MessageServersConnector m_messagesService; protected GridInfoServiceModule m_gridInfoService; @@ -191,6 +192,10 @@ namespace OpenSim.Grid.UserServer { m_loginService = new UserLoginService( m_userDataBaseService, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile), Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy()); + + if (Cfg.EnableHGLogin) + m_loginAuthService = new UserLoginAuthService(m_userDataBaseService, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile), + Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy()); } protected virtual void PostInitialiseModules() @@ -209,6 +214,9 @@ namespace OpenSim.Grid.UserServer { m_loginService.RegisterHandlers(m_httpServer, Cfg.EnableLLSDLogin, true); + if (m_loginAuthService != null) + m_loginAuthService.RegisterHandlers(m_httpServer); + m_userManager.RegisterHandlers(m_httpServer); m_friendsModule.RegisterHandlers(m_httpServer); m_avatarAppearanceModule.RegisterHandlers(m_httpServer); -- cgit v1.1