diff --git a/OpenSim/Data/IUserAccountData.cs b/OpenSim/Data/IUserAccountData.cs new file mode 100644 index 0000000000..6bec18833d --- /dev/null +++ b/OpenSim/Data/IUserAccountData.cs @@ -0,0 +1,55 @@ +/* + * 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 OpenSimulator 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 OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Data +{ + public class UserAccountData + { + public UUID PrincipalID; + public UUID ScopeID; + public Dictionary Data; + } + + /// + /// An interface for connecting to the authentication datastore + /// + public interface IUserAccountData + { + UserAccountData Get(UUID principalID, UUID ScopeID); + + List Query(UUID principalID, UUID ScopeID, string query); + + bool Store(UserAccountData data); + + bool SetDataItem(UUID principalID, string item, string value); + } +} diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs new file mode 100644 index 0000000000..39d60ca6c0 --- /dev/null +++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs @@ -0,0 +1,180 @@ +/* + * 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 OpenSimulator 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.Data; +using OpenMetaverse; +using OpenSim.Framework; +using MySql.Data.MySqlClient; + +namespace OpenSim.Data.MySQL +{ + public class MySqlUserAccountData : MySqlFramework, IUserAccountData + { + private string m_Realm; + private List m_ColumnNames = null; + private int m_LastExpire = 0; + + public MySqlUserAccountData(string connectionString, string realm) + : base(connectionString) + { + m_Realm = realm; + + Migration m = new Migration(m_Connection, GetType().Assembly, "UserStore"); + m.Update(); + } + + public List Query(UUID principalID, UUID scopeID, string query) + { + return null; + } + + public UserAccountData Get(UUID principalID, UUID scopeID) + { + UserAccountData ret = new UserAccountData(); + ret.Data = new Dictionary(); + + string command = "select * from `"+m_Realm+"` where UUID = ?principalID"; + if (scopeID != UUID.Zero) + command += " and ScopeID = ?scopeID"; + + MySqlCommand cmd = new MySqlCommand(command); + + cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); + cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); + + IDataReader result = ExecuteReader(cmd); + + if (result.Read()) + { + ret.PrincipalID = principalID; + UUID scope; + UUID.TryParse(result["ScopeID"].ToString(), out scope); + ret.ScopeID = scope; + + if (m_ColumnNames == null) + { + m_ColumnNames = new List(); + + DataTable schemaTable = result.GetSchemaTable(); + foreach (DataRow row in schemaTable.Rows) + m_ColumnNames.Add(row["ColumnName"].ToString()); + } + + foreach (string s in m_ColumnNames) + { + if (s == "UUID") + continue; + if (s == "ScopeID") + continue; + + ret.Data[s] = result[s].ToString(); + } + + result.Close(); + CloseReaderCommand(cmd); + + return ret; + } + + result.Close(); + CloseReaderCommand(cmd); + + return null; + } + + public bool Store(UserAccountData data) + { + if (data.Data.ContainsKey("UUID")) + data.Data.Remove("UUID"); + if (data.Data.ContainsKey("ScopeID")) + data.Data.Remove("ScopeID"); + + string[] fields = new List(data.Data.Keys).ToArray(); + + MySqlCommand cmd = new MySqlCommand(); + + string update = "update `"+m_Realm+"` set "; + bool first = true; + foreach (string field in fields) + { + if (!first) + update += ", "; + update += "`" + field + "` = ?"+field; + + first = false; + + cmd.Parameters.AddWithValue("?"+field, data.Data[field]); + } + + update += " where UUID = ?principalID"; + + if (data.ScopeID != UUID.Zero) + update += " and ScopeID = ?scopeID"; + + cmd.CommandText = update; + cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString()); + cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString()); + + if (ExecuteNonQuery(cmd) < 1) + { + string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" + + String.Join("`, `", fields) + + "`) values ( ?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")"; + + cmd.CommandText = insert; + + if (ExecuteNonQuery(cmd) < 1) + { + cmd.Dispose(); + return false; + } + } + + cmd.Dispose(); + + return true; + } + + public bool SetDataItem(UUID principalID, string item, string value) + { + MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + + "` set `" + item + "` = ?" + item + " where UUID = ?UUID"); + + + cmd.Parameters.AddWithValue("?"+item, value); + cmd.Parameters.AddWithValue("?UUID", principalID.ToString()); + + if (ExecuteNonQuery(cmd) > 0) + return true; + + return false; + } + } +} diff --git a/OpenSim/Data/MySQL/Resources/008_UserStore.sql b/OpenSim/Data/MySQL/Resources/008_UserStore.sql new file mode 100644 index 0000000000..4500bd5d7b --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/008_UserStore.sql @@ -0,0 +1,5 @@ +BEGIN; + +ALTER TABLE users add scopeID char(36) not null default '00000000-0000-0000-0000-000000000000'; + +COMMIT; diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs index fcd030400e..cca5bb4f6f 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs @@ -42,7 +42,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); - private IUserAccountDataService m_UserService; + private IUserAccountService m_UserService; private bool m_Enabled = false; @@ -82,7 +82,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User Object[] args = new Object[] { source }; m_UserService = - ServerUtils.LoadPlugin(serviceDll, + ServerUtils.LoadPlugin(serviceDll, args); if (m_UserService == null) @@ -113,7 +113,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User if (!m_Enabled) return; - scene.RegisterModuleInterface(m_UserService); + scene.RegisterModuleInterface(m_UserService); } public void RemoveRegion(Scene scene) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs index a2b854b992..cef9129b29 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs @@ -37,7 +37,7 @@ using OpenSim.Services.Connectors; namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User { public class RemoteUserServicesConnector : UserServicesConnector, - ISharedRegionModule, IUserAccountDataService + ISharedRegionModule, IUserAccountService { private static readonly ILog m_log = LogManager.GetLogger( @@ -96,7 +96,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User if (!m_Enabled) return; - scene.RegisterModuleInterface(this); + scene.RegisterModuleInterface(this); } public void RemoveRegion(Scene scene) diff --git a/OpenSim/Services/Connectors/User/UserServiceConnector.cs b/OpenSim/Services/Connectors/User/UserServiceConnector.cs index fb03844dad..d4189380d6 100644 --- a/OpenSim/Services/Connectors/User/UserServiceConnector.cs +++ b/OpenSim/Services/Connectors/User/UserServiceConnector.cs @@ -39,7 +39,7 @@ using OpenMetaverse; namespace OpenSim.Services.Connectors { - public class UserServicesConnector : IUserAccountDataService + public class UserServicesConnector : IUserAccountService { private static readonly ILog m_log = LogManager.GetLogger( @@ -81,153 +81,34 @@ namespace OpenSim.Services.Connectors m_ServerURI = serviceURI; } - public UserAccountData GetUserAccountData(UUID scopeID, string firstName, string lastName) + public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) { - string uri = m_ServerURI + "/users/"; - UserAccountData data = new UserAccountData(); - data.FirstName = firstName; - data.LastName = lastName; - data.ScopeID = scopeID; - data.UserID = UUID.Zero; - - try - { - data = SynchronousRestObjectRequester. - MakeRequest("POST", uri, data); - } - catch (Exception e) - { - m_log.WarnFormat("[USER CONNECTOR]: Unable to send request to user server. Reason: {1}", e.Message); - return null; - } - - if (data.UserID == UUID.Zero) - return null; - - return data; + return null; } - public UserAccountData GetUserAccountData(UUID scopeID, UUID userID) + public UserAccount GetUserAccount(UUID scopeID, UUID userID) { - string uri = m_ServerURI + "/users/"; - UserAccountData data = new UserAccountData(); - data.FirstName = String.Empty; - data.LastName = String.Empty; - data.ScopeID = scopeID; - data.UserID = userID; - - try - { - data = SynchronousRestObjectRequester. - MakeRequest("POST", uri, data); - } - catch (Exception e) - { - m_log.WarnFormat("[USER CONNECTOR]: Unable to send request to user server. Reason: {1}", e.Message); - return null; - } - - if (data.UserID == UUID.Zero) - return null; - - return data; + return null; } - public bool SetHomePosition(UserAccountData data, UUID regionID, UUID regionSecret) + public bool SetHomePosition(UserAccount data, UUID regionID, UUID regionSecret) { - string uri = m_ServerURI + "/user/"; - bool result = false; - - UserAccountDataMessage msg = new UserAccountDataMessage(); - - msg.Data = data; - msg.RegionID = regionID; - msg.RegionSecret = regionSecret; - - try - { - result = SynchronousRestObjectRequester. - MakeRequest("POST", uri, msg); - } - catch (Exception e) - { - m_log.WarnFormat("[USER CONNECTOR]: Unable to send request to user server. Reason: {1}", e.Message); - return false; - } - - return result; + return false; } - public bool SetUserAccountData(UserAccountData data, UUID principalID, UUID sessionID) + public bool SetUserAccount(UserAccount data, UUID principalID, string token) { - string uri = m_ServerURI + "/user/"; - bool result = false; - - UserAccountDataMessage msg = new UserAccountDataMessage(); - - msg.Data = data; - msg.PrincipalID = principalID; - msg.SessionID = sessionID; - - try - { - result = SynchronousRestObjectRequester. - MakeRequest("POST", uri, msg); - } - catch (Exception e) - { - m_log.WarnFormat("[USER CONNECTOR]: Unable to send request to user server. Reason: {1}", e.Message); - return false; - } - - return result; + return false; } - public bool CreateUserAccountData(UserAccountData data, UUID principalID, UUID sessionID) + public bool CreateUserAccount(UserAccount data, UUID principalID, string token) { - string uri = m_ServerURI + "/newuser/"; - bool result = false; - - UserAccountDataMessage msg = new UserAccountDataMessage(); - - msg.Data = data; - msg.PrincipalID = principalID; - msg.SessionID = sessionID; - - try - { - result = SynchronousRestObjectRequester. - MakeRequest("POST", uri, msg); - } - catch (Exception e) - { - m_log.WarnFormat("[USER CONNECTOR]: Unable to send request to user server. Reason: {1}", e.Message); - return false; - } - - return result; + return false; } - public List GetUserAccountData(UUID scopeID, string query) + public List GetUserAccount(UUID scopeID, string query) { - string uri = m_ServerURI + "/userlist/"; - UserAccountData data = new UserAccountData(); - data.FirstName = query; - data.ScopeID = scopeID; - List result; - - try - { - result = SynchronousRestObjectRequester. - MakeRequest>("POST", uri, data); - } - catch (Exception e) - { - m_log.WarnFormat("[USER CONNECTOR]: Unable to send request to user server. Reason: {1}", e.Message); - return null; - } - - return result; + return null; } } } diff --git a/OpenSim/Services/Interfaces/IUserService.cs b/OpenSim/Services/Interfaces/IUserService.cs index 35254a1c54..92bd8ef773 100644 --- a/OpenSim/Services/Interfaces/IUserService.cs +++ b/OpenSim/Services/Interfaces/IUserService.cs @@ -30,13 +30,13 @@ using OpenMetaverse; namespace OpenSim.Services.Interfaces { - public class UserAccountData + public class UserAccount { - public UserAccountData() + public UserAccount() { } - public UserAccountData(UUID userID, UUID homeRegionID, float homePositionX, + public UserAccount(UUID userID, UUID homeRegionID, float homePositionX, float homePositionY, float homePositionZ, float homeLookAtX, float homeLookAtY, float homeLookAtZ) { @@ -78,41 +78,26 @@ namespace OpenSim.Services.Interfaces }; - public class UserAccountDataMessage + public interface IUserAccountService { - public UserAccountData Data; - - // Set to the region's ID and secret when updating home location - // - public UUID RegionID; - public UUID RegionSecret; - - // Set to the auth info of the user requesting creation/update - // - public UUID PrincipalID; - public UUID SessionID; - }; - - public interface IUserAccountDataService - { - UserAccountData GetUserAccountData(UUID scopeID, UUID userID); - UserAccountData GetUserAccountData(UUID scopeID, string FirstName, string LastName); + UserAccount GetUserAccount(UUID scopeID, UUID userID); + UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName); // Returns the list of avatars that matches both the search // criterion and the scope ID passed // - List GetUserAccountData(UUID scopeID, string query); + List GetUserAccount(UUID scopeID, string query); // This will set only the home region portion of the data! // Can't be used to set god level, flags, type or change the name! // - bool SetHomePosition(UserAccountData data, UUID RegionID, UUID RegionSecret); + bool SetHomePosition(UserAccount data, UUID RegionID, UUID RegionSecret); // Update all updatable fields // - bool SetUserAccountData(UserAccountData data, UUID PrincipalID, UUID SessionID); + bool SetUserAccount(UserAccount data, UUID PrincipalID, string token); // Creates a user data record - bool CreateUserAccountData(UserAccountData data, UUID PrincipalID, UUID SessionID); + bool CreateUserAccount(UserAccount data, UUID PrincipalID, string token); } } diff --git a/OpenSim/Services/UserService/UserService.cs b/OpenSim/Services/UserService/UserService.cs index 7879365746..e8b9fc30e7 100644 --- a/OpenSim/Services/UserService/UserService.cs +++ b/OpenSim/Services/UserService/UserService.cs @@ -35,39 +35,39 @@ using OpenMetaverse; namespace OpenSim.Services.UserAccountService { - public class UserAccountService : UserAccountServiceBase, IUserAccountDataService + public class UserAccountService : UserAccountServiceBase, IUserAccountService { public UserAccountService(IConfigSource config) : base(config) { } - public UserAccountData GetUserAccountData(UUID scopeID, string firstName, + public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) { return null; } - public UserAccountData GetUserAccountData(UUID scopeID, UUID userID) + public UserAccount GetUserAccount(UUID scopeID, UUID userID) { return null; } - public bool SetHomePosition(UserAccountData data, UUID regionID, UUID regionSecret) + public bool SetHomePosition(UserAccount data, UUID regionID, UUID regionSecret) { return false; } - public bool SetUserAccountData(UserAccountData data, UUID principalID, UUID sessionID) + public bool SetUserAccount(UserAccount data, UUID principalID, string token) { return false; } - public bool CreateUserAccountData(UserAccountData data, UUID principalID, UUID sessionID) + public bool CreateUserAccount(UserAccount data, UUID principalID, string token) { return false; } - public List GetUserAccountData(UUID scopeID, + public List GetUserAccount(UUID scopeID, string query) { return null;