LocalUserAccountServiceConnector.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 OpenSimulator 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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using Mono.Addins;
  32. using Nini.Config;
  33. using OpenSim.Region.Framework.Interfaces;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Server.Base;
  36. using OpenSim.Services.Interfaces;
  37. using OpenMetaverse;
  38. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
  39. {
  40. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalUserAccountServicesConnector")]
  41. public class LocalUserAccountServicesConnector : ISharedRegionModule, IUserAccountService
  42. {
  43. private static readonly ILog m_log =
  44. LogManager.GetLogger(
  45. MethodBase.GetCurrentMethod().DeclaringType);
  46. /// <summary>
  47. /// This is not on the IUserAccountService. It's only being used so that standalone scenes can punch through
  48. /// to a local UserAccountService when setting up an estate manager.
  49. /// </summary>
  50. public IUserAccountService UserAccountService { get; private set; }
  51. private UserAccountCache m_Cache;
  52. private bool m_Enabled = false;
  53. #region ISharedRegionModule
  54. public Type ReplaceableInterface
  55. {
  56. get { return null; }
  57. }
  58. public string Name
  59. {
  60. get { return "LocalUserAccountServicesConnector"; }
  61. }
  62. public void Initialise(IConfigSource source)
  63. {
  64. IConfig moduleConfig = source.Configs["Modules"];
  65. if (moduleConfig != null)
  66. {
  67. string name = moduleConfig.GetString("UserAccountServices", "");
  68. if (name == Name)
  69. {
  70. IConfig userConfig = source.Configs["UserAccountService"];
  71. if (userConfig == null)
  72. {
  73. m_log.Error("[LOCAL USER ACCOUNT SERVICE CONNECTOR]: UserAccountService missing from OpenSim.ini");
  74. return;
  75. }
  76. string serviceDll = userConfig.GetString("LocalServiceModule", String.Empty);
  77. if (serviceDll == String.Empty)
  78. {
  79. m_log.Error("[LOCAL USER ACCOUNT SERVICE CONNECTOR]: No LocalServiceModule named in section UserService");
  80. return;
  81. }
  82. Object[] args = new Object[] { source };
  83. UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(serviceDll, args);
  84. if (UserAccountService == null)
  85. {
  86. m_log.ErrorFormat(
  87. "[LOCAL USER ACCOUNT SERVICE CONNECTOR]: Cannot load user account service specified as {0}", serviceDll);
  88. return;
  89. }
  90. m_Enabled = true;
  91. m_Cache = new UserAccountCache();
  92. m_log.Info("[LOCAL USER ACCOUNT SERVICE CONNECTOR]: Local user connector enabled");
  93. }
  94. }
  95. }
  96. public void PostInitialise()
  97. {
  98. if (!m_Enabled)
  99. return;
  100. }
  101. public void Close()
  102. {
  103. if (!m_Enabled)
  104. return;
  105. }
  106. public void AddRegion(Scene scene)
  107. {
  108. if (!m_Enabled)
  109. return;
  110. // FIXME: Why do we bother setting this module and caching up if we just end up registering the inner
  111. // user account service?!
  112. scene.RegisterModuleInterface<IUserAccountService>(UserAccountService);
  113. scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
  114. }
  115. public void RemoveRegion(Scene scene)
  116. {
  117. if (!m_Enabled)
  118. return;
  119. }
  120. public void RegionLoaded(Scene scene)
  121. {
  122. if (!m_Enabled)
  123. return;
  124. m_log.InfoFormat("[LOCAL USER ACCOUNT SERVICE CONNECTOR]: Enabled local user accounts for region {0}", scene.RegionInfo.RegionName);
  125. }
  126. #endregion
  127. #region IUserAccountService
  128. public UserAccount GetUserAccount(UUID scopeID, UUID userID)
  129. {
  130. bool inCache = false;
  131. UserAccount account;
  132. account = m_Cache.Get(userID, out inCache);
  133. if (inCache)
  134. return account;
  135. account = UserAccountService.GetUserAccount(scopeID, userID);
  136. m_Cache.Cache(userID, account);
  137. return account;
  138. }
  139. public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
  140. {
  141. bool inCache = false;
  142. UserAccount account;
  143. account = m_Cache.Get(firstName + " " + lastName, out inCache);
  144. if (inCache)
  145. return account;
  146. account = UserAccountService.GetUserAccount(scopeID, firstName, lastName);
  147. if (account != null)
  148. m_Cache.Cache(account.PrincipalID, account);
  149. return account;
  150. }
  151. public UserAccount GetUserAccount(UUID scopeID, string Email)
  152. {
  153. return UserAccountService.GetUserAccount(scopeID, Email);
  154. }
  155. public List<UserAccount> GetUserAccounts(UUID scopeID, List<string> IDs)
  156. {
  157. List<UserAccount> ret = new List<UserAccount>();
  158. List<string> missing = new List<string>();
  159. // still another cache..
  160. bool inCache = false;
  161. UUID uuid = UUID.Zero;
  162. UserAccount account;
  163. foreach(string id in IDs)
  164. {
  165. if(UUID.TryParse(id, out uuid))
  166. {
  167. account = m_Cache.Get(uuid, out inCache);
  168. if (inCache)
  169. ret.Add(account);
  170. else
  171. missing.Add(id);
  172. }
  173. }
  174. if(missing.Count == 0)
  175. return ret;
  176. List<UserAccount> ext = UserAccountService.GetUserAccounts(scopeID, missing);
  177. if(ext != null && ext.Count > 0)
  178. {
  179. foreach(UserAccount acc in ext)
  180. {
  181. if(acc != null)
  182. {
  183. ret.Add(acc);
  184. m_Cache.Cache(acc.PrincipalID, acc);
  185. }
  186. }
  187. }
  188. return ret;
  189. }
  190. public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string query)
  191. {
  192. return null;
  193. }
  194. public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
  195. {
  196. return UserAccountService.GetUserAccounts(scopeID, query);
  197. }
  198. // Update all updatable fields
  199. //
  200. public bool StoreUserAccount(UserAccount data)
  201. {
  202. bool ret = UserAccountService.StoreUserAccount(data);
  203. if (ret)
  204. m_Cache.Cache(data.PrincipalID, data);
  205. return ret;
  206. }
  207. public void InvalidateCache(UUID userID)
  208. {
  209. m_Cache.Invalidate(userID);
  210. }
  211. #endregion
  212. }
  213. }