From 96ecdcf9c5ba35e589a599ad37cc6ce1a83f46f1 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 9 Jan 2010 18:04:50 -0800 Subject: [PATCH 1/2] * Added SetPassword to IAuthenticationService. * Added create user command to UserAccountService. Works. * Deleted create user command from OpenSim. --- OpenSim/Region/Application/OpenSim.cs | 74 ---------- .../LocalAuthenticationServiceConnector.cs | 5 + .../AuthenticationServiceBase.cs | 29 +++- .../AuthenticationServiceConnector.cs | 6 + .../Interfaces/IAuthenticationService.cs | 11 ++ .../UserAccountService/UserAccountService.cs | 127 ++++++++++++------ bin/config-include/StandaloneHypergrid.ini | 6 +- 7 files changed, 139 insertions(+), 119 deletions(-) diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 82b2fd4e28..787d0257c9 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -349,9 +349,6 @@ namespace OpenSim if (ConfigurationSettings.Standalone) { - m_console.Commands.AddCommand("region", false, "create user", - "create user [ [ [ [ []]]]]", - "Create a new user", HandleCreateUser); m_console.Commands.AddCommand("region", false, "reset user password", "reset user password [ [ []]]", @@ -812,22 +809,6 @@ namespace OpenSim m_console.ConsoleScene = m_sceneManager.CurrentScene; } - /// - /// Execute switch for some of the create commands - /// - /// - private void HandleCreateUser(string module, string[] cmd) - { - if (ConfigurationSettings.Standalone) - { - CreateUser(cmd); - } - else - { - m_log.Info("Create user is not available in grid mode, use the user server."); - } - } - /// /// Execute switch for some of the reset commands /// @@ -1075,61 +1056,6 @@ namespace OpenSim return report; } - /// - /// Create a new user - /// - /// string array with parameters: firstname, lastname, password, locationX, locationY, email - protected void CreateUser(string[] cmdparams) - { - string firstName; - string lastName; - string password; - string email; - uint regX = 1000; - uint regY = 1000; - - IConfig standalone; - if ((standalone = m_config.Source.Configs["StandAlone"]) != null) - { - regX = (uint)standalone.GetInt("default_location_x", (int)regX); - regY = (uint)standalone.GetInt("default_location_y", (int)regY); - } - - - if (cmdparams.Length < 3) - firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); - else firstName = cmdparams[2]; - - if (cmdparams.Length < 4) - lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); - else lastName = cmdparams[3]; - - if (cmdparams.Length < 5) - password = MainConsole.Instance.PasswdPrompt("Password"); - else password = cmdparams[4]; - - if (cmdparams.Length < 6) - regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString())); - else regX = Convert.ToUInt32(cmdparams[5]); - - if (cmdparams.Length < 7) - regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString())); - else regY = Convert.ToUInt32(cmdparams[6]); - - if (cmdparams.Length < 8) - email = MainConsole.Instance.CmdPrompt("Email", ""); - else email = cmdparams[7]; - - if (null == m_commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName)) - { - m_commsManager.UserAdminService.AddUser(firstName, lastName, password, email, regX, regY); - } - else - { - m_log.ErrorFormat("[CONSOLE]: A user with the name {0} {1} already exists!", firstName, lastName); - } - } - /// /// Reset a user password. /// diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs index 4c65722158..acc362b95a 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs @@ -153,6 +153,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication return m_AuthenticationService.Release(principalID, token); } + public bool SetPassword(UUID principalID, string passwd) + { + return m_AuthenticationService.SetPassword(principalID, passwd); + } + #endregion } diff --git a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs index dcf090e0f2..f6dd085f72 100644 --- a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs +++ b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs @@ -32,6 +32,7 @@ using Nini.Config; using System.Reflection; using OpenSim.Services.Base; using OpenSim.Data; +using OpenSim.Framework; namespace OpenSim.Services.AuthenticationService { @@ -43,9 +44,9 @@ namespace OpenSim.Services.AuthenticationService // public class AuthenticationServiceBase : ServiceBase { -// private static readonly ILog m_log = -// LogManager.GetLogger( -// MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); protected IAuthenticationData m_Database; @@ -100,6 +101,27 @@ namespace OpenSim.Services.AuthenticationService return m_Database.CheckToken(principalID, token, 0); } + public virtual bool SetPassword(UUID principalID, string password) + { + string passwordSalt = Util.Md5Hash(UUID.Random().ToString()); + string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + passwordSalt); + + AuthenticationData auth = new AuthenticationData(); + auth.PrincipalID = principalID; + auth.Data = new System.Collections.Generic.Dictionary(); + auth.Data["passwordHash"] = md5PasswdHash; + auth.Data["passwordSalt"] = passwordSalt; + auth.Data["webLoginKey"] = UUID.Zero.ToString(); + if (!m_Database.Store(auth)) + { + m_log.DebugFormat("[AUTHENTICATION DB]: Failed to store authentication data"); + return false; + } + + m_log.InfoFormat("[AUTHENTICATION DB]: Set password for principalID {0}", principalID); + return true; + } + protected string GetToken(UUID principalID, int lifetime) { UUID token = UUID.Random(); @@ -109,5 +131,6 @@ namespace OpenSim.Services.AuthenticationService return String.Empty; } + } } diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs index 125065874a..f36fe5bed7 100644 --- a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs @@ -146,5 +146,11 @@ namespace OpenSim.Services.Connectors return true; } + + public bool SetPassword(UUID principalID, string passwd) + { + // nope, we don't do this + return false; + } } } diff --git a/OpenSim/Services/Interfaces/IAuthenticationService.cs b/OpenSim/Services/Interfaces/IAuthenticationService.cs index 9225773a30..9de261ba8e 100644 --- a/OpenSim/Services/Interfaces/IAuthenticationService.cs +++ b/OpenSim/Services/Interfaces/IAuthenticationService.cs @@ -65,6 +65,17 @@ namespace OpenSim.Services.Interfaces // bool Release(UUID principalID, string token); + ////////////////////////////////////////////////////// + // SetPassword for a principal + // + // This method exists for the service, but may or may not + // be served remotely. That is, the authentication + // handlers may not include one handler for this, + // because it's a bit risky. Such handlers require + // authentication/authorization. + // + bool SetPassword(UUID principalID, string passwd); + ////////////////////////////////////////////////////// // Grid // diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index dacfa51bee..8f78813bb9 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs @@ -26,25 +26,58 @@ */ using System; +using System.Collections.Generic; using System.Reflection; using Nini.Config; using OpenSim.Data; -using OpenSim.Framework.Console; using OpenSim.Services.Interfaces; -using System.Collections.Generic; +using OpenSim.Framework.Console; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; + using OpenMetaverse; +using log4net; namespace OpenSim.Services.UserAccountService { public class UserAccountService : UserAccountServiceBase, IUserAccountService { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static UserAccountService m_RootInstance; + + protected IGridService m_GridService; + protected IAuthenticationService m_AuthenticationService; + protected IPresenceService m_PresenceService; + public UserAccountService(IConfigSource config) : base(config) { - MainConsole.Instance.Commands.AddCommand("UserService", false, - "create user", - "create user [ [ [ [ []]]]]", - "Create a new user", HandleCreateUser); + IConfig userConfig = config.Configs["UserAccountService"]; + if (userConfig == null) + throw new Exception("No UserAccountService configuration"); + + // In case there are several instances of this class in the same process, + // the console commands are only registered for the root instance + if (m_RootInstance == null) + { + m_RootInstance = this; + string gridServiceDll = userConfig.GetString("GridService", string.Empty); + if (gridServiceDll != string.Empty) + m_GridService = LoadPlugin(gridServiceDll, new Object[] { config }); + + string authServiceDll = userConfig.GetString("AuthenticationService", string.Empty); + if (authServiceDll != string.Empty) + m_AuthenticationService = LoadPlugin(authServiceDll, new Object[] { config }); + + string presenceServiceDll = userConfig.GetString("PresenceService", string.Empty); + if (presenceServiceDll != string.Empty) + m_PresenceService = LoadPlugin(presenceServiceDll, new Object[] { config }); + + MainConsole.Instance.Commands.AddCommand("UserService", false, + "create user", + "create user [ [ [ []]]]", + "Create a new user", HandleCreateUser); + } + } #region IUserAccountService @@ -202,52 +235,64 @@ namespace OpenSim.Services.UserAccountService string lastName; string password; string email; - uint regX = 1000; - uint regY = 1000; - // IConfig standalone; - // if ((standalone = m_config.Source.Configs["StandAlone"]) != null) - // { - // regX = (uint)standalone.GetInt("default_location_x", (int)regX); - // regY = (uint)standalone.GetInt("default_location_y", (int)regY); - // } + if (cmdparams.Length < 3) + firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); + else firstName = cmdparams[2]; + if (cmdparams.Length < 4) + lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); + else lastName = cmdparams[3]; - // if (cmdparams.Length < 3) - // firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); - // else firstName = cmdparams[2]; + if (cmdparams.Length < 5) + password = MainConsole.Instance.PasswdPrompt("Password"); + else password = cmdparams[4]; - // if (cmdparams.Length < 4) - // lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); - // else lastName = cmdparams[3]; + if (cmdparams.Length < 6) + email = MainConsole.Instance.CmdPrompt("Email", ""); + else email = cmdparams[5]; - // if (cmdparams.Length < 5) - // password = MainConsole.Instance.PasswdPrompt("Password"); - // else password = cmdparams[4]; + UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); + if (null == account) + { + account = new UserAccount(UUID.Zero, firstName, lastName, email); + if (StoreUserAccount(account)) + { + bool success = false; + if (m_AuthenticationService != null) + success = m_AuthenticationService.SetPassword(account.PrincipalID, password); + if (!success) + m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.", + firstName, lastName); - // if (cmdparams.Length < 6) - // regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString())); - // else regX = Convert.ToUInt32(cmdparams[5]); + GridRegion home = null; + if (m_GridService != null) + { + List defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero); + if (defaultRegions != null && defaultRegions.Count >= 1) + home = defaultRegions[0]; - // if (cmdparams.Length < 7) - // regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString())); - // else regY = Convert.ToUInt32(cmdparams[6]); + if (m_PresenceService != null && home != null) + m_PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); + else + m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.", + firstName, lastName); - // if (cmdparams.Length < 8) - // email = MainConsole.Instance.CmdPrompt("Email", ""); - // else email = cmdparams[7]; + } + else + m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.", + firstName, lastName); - // if (null == m_commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName)) - // { - // m_commsManager.UserAdminService.AddUser(firstName, lastName, password, email, regX, regY); - // } - // else - // { - // m_log.ErrorFormat("[CONSOLE]: A user with the name {0} {1} already exists!", firstName, lastName); - // } - //} + m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", firstName, lastName); + } + } + else + { + m_log.ErrorFormat("[USER ACCOUNT SERVICE]: A user with the name {0} {1} already exists!", firstName, lastName); + } } #endregion + } } diff --git a/bin/config-include/StandaloneHypergrid.ini b/bin/config-include/StandaloneHypergrid.ini index 5e54cde154..feca1159a9 100644 --- a/bin/config-include/StandaloneHypergrid.ini +++ b/bin/config-include/StandaloneHypergrid.ini @@ -67,7 +67,11 @@ [UserAccountService] LocalServiceModule = "OpenSim.Services.UserAccountService.dll:UserAccountService" - + ;; These are for creating new accounts + AuthenticationService = "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService" + PresenceService = "OpenSim.Services.PresenceService.dll:PresenceService" + GridService = "OpenSim.Services.GridService.dll:GridService" + [LoginService] LocalServiceModule = "OpenSim.Services.LLLoginService.dll:LLLoginService" UserAccountService = "OpenSim.Services.UserAccountService.dll:UserAccountService" From 7cb66de2e022d1013eacb43dc0186a575a19a5c6 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 9 Jan 2010 18:16:14 -0800 Subject: [PATCH 2/2] * Moved command reset password from OpenSim to UserAccountService. --- OpenSim/Region/Application/OpenSim.cs | 47 ------------------- .../UserAccountService/UserAccountService.cs | 37 +++++++++++++++ 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 787d0257c9..31cc6104c8 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -347,13 +347,6 @@ namespace OpenSim "kill uuid ", "Kill an object by UUID", KillUUID); - if (ConfigurationSettings.Standalone) - { - - m_console.Commands.AddCommand("region", false, "reset user password", - "reset user password [ [ []]]", - "Reset a user password", HandleResetUserPassword); - } m_console.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [ ] ", "Set local coordinate to map HG regions to", RunCommand); @@ -809,21 +802,6 @@ namespace OpenSim m_console.ConsoleScene = m_sceneManager.CurrentScene; } - /// - /// Execute switch for some of the reset commands - /// - /// - protected void HandleResetUserPassword(string module, string[] cmd) - { - if (ConfigurationSettings.Standalone) - { - ResetUserPassword(cmd); - } - else - { - m_log.Info("Reset user password is not available in grid mode, use the user-server."); - } - } /// /// Turn on some debugging values for OpenSim. @@ -1056,31 +1034,6 @@ namespace OpenSim return report; } - /// - /// Reset a user password. - /// - /// - private void ResetUserPassword(string[] cmdparams) - { - string firstName; - string lastName; - string newPassword; - - if (cmdparams.Length < 4) - firstName = MainConsole.Instance.CmdPrompt("First name"); - else firstName = cmdparams[3]; - - if (cmdparams.Length < 5) - lastName = MainConsole.Instance.CmdPrompt("Last name"); - else lastName = cmdparams[4]; - - if (cmdparams.Length < 6) - newPassword = MainConsole.Instance.PasswdPrompt("New password"); - else newPassword = cmdparams[5]; - - m_commsManager.UserAdminService.ResetUserPassword(firstName, lastName, newPassword); - } - /// /// Use XML2 format to serialize data to a file /// diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index 8f78813bb9..90077d8eb6 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs @@ -76,6 +76,10 @@ namespace OpenSim.Services.UserAccountService "create user", "create user [ [ [ []]]]", "Create a new user", HandleCreateUser); + MainConsole.Instance.Commands.AddCommand("UserService", false, "reset user password", + "reset user password [ [ []]]", + "Reset a user password", HandleResetUserPassword); + } } @@ -292,6 +296,39 @@ namespace OpenSim.Services.UserAccountService } } + + protected void HandleResetUserPassword(string module, string[] cmdparams) + { + string firstName; + string lastName; + string newPassword; + + if (cmdparams.Length < 4) + firstName = MainConsole.Instance.CmdPrompt("First name"); + else firstName = cmdparams[3]; + + if (cmdparams.Length < 5) + lastName = MainConsole.Instance.CmdPrompt("Last name"); + else lastName = cmdparams[4]; + + if (cmdparams.Length < 6) + newPassword = MainConsole.Instance.PasswdPrompt("New password"); + else newPassword = cmdparams[5]; + + UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); + if (account == null) + m_log.ErrorFormat("[USER ACCOUNT SERVICE]: No such user"); + + bool success = false; + if (m_AuthenticationService != null) + success = m_AuthenticationService.SetPassword(account.PrincipalID, newPassword); + if (!success) + m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Unable to reset password for account {0} {1}.", + firstName, lastName); + else + m_log.InfoFormat("[USER ACCOUNT SERVICE]: Password reset for user {0} {1}", firstName, lastName); + } + #endregion }