LocalAuthenticationServiceConnector.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.Authentication
  39. {
  40. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalAuthenticationServicesConnector")]
  41. public class LocalAuthenticationServicesConnector : ISharedRegionModule, IAuthenticationService
  42. {
  43. private static readonly ILog m_log =
  44. LogManager.GetLogger(
  45. MethodBase.GetCurrentMethod().DeclaringType);
  46. private IAuthenticationService m_AuthenticationService;
  47. private bool m_Enabled = false;
  48. #region ISharedRegionModule
  49. public Type ReplaceableInterface
  50. {
  51. get { return null; }
  52. }
  53. public string Name
  54. {
  55. get { return "LocalAuthenticationServicesConnector"; }
  56. }
  57. public void Initialise(IConfigSource source)
  58. {
  59. IConfig moduleConfig = source.Configs["Modules"];
  60. if (moduleConfig != null)
  61. {
  62. string name = moduleConfig.GetString("AuthenticationServices", "");
  63. if (name == Name)
  64. {
  65. IConfig userConfig = source.Configs["AuthenticationService"];
  66. if (userConfig == null)
  67. {
  68. m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini");
  69. return;
  70. }
  71. string serviceDll = userConfig.GetString("LocalServiceModule",
  72. String.Empty);
  73. if (serviceDll == String.Empty)
  74. {
  75. m_log.Error("[AUTH CONNECTOR]: No LocalServiceModule named in section AuthenticationService");
  76. return;
  77. }
  78. Object[] args = new Object[] { source };
  79. m_AuthenticationService =
  80. ServerUtils.LoadPlugin<IAuthenticationService>(serviceDll,
  81. args);
  82. if (m_AuthenticationService == null)
  83. {
  84. m_log.Error("[AUTH CONNECTOR]: Can't load Authentication service");
  85. return;
  86. }
  87. m_Enabled = true;
  88. m_log.Info("[AUTH CONNECTOR]: Local Authentication connector enabled");
  89. }
  90. }
  91. }
  92. public void PostInitialise()
  93. {
  94. if (!m_Enabled)
  95. return;
  96. }
  97. public void Close()
  98. {
  99. if (!m_Enabled)
  100. return;
  101. }
  102. public void AddRegion(Scene scene)
  103. {
  104. if (!m_Enabled)
  105. return;
  106. scene.RegisterModuleInterface<IAuthenticationService>(m_AuthenticationService);
  107. }
  108. public void RemoveRegion(Scene scene)
  109. {
  110. if (!m_Enabled)
  111. return;
  112. }
  113. public void RegionLoaded(Scene scene)
  114. {
  115. if (!m_Enabled)
  116. return;
  117. }
  118. #endregion
  119. #region IAuthenticationService
  120. public string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
  121. {
  122. // Not implemented at the regions
  123. realID = UUID.Zero;
  124. return string.Empty;
  125. }
  126. public string Authenticate(UUID principalID, string password, int lifetime)
  127. {
  128. // Not implemented at the regions
  129. return string.Empty;
  130. }
  131. public bool Verify(UUID principalID, string token, int lifetime)
  132. {
  133. return m_AuthenticationService.Verify(principalID, token, lifetime);
  134. }
  135. public bool Release(UUID principalID, string token)
  136. {
  137. return m_AuthenticationService.Release(principalID, token);
  138. }
  139. public bool SetPassword(UUID principalID, string passwd)
  140. {
  141. return m_AuthenticationService.SetPassword(principalID, passwd);
  142. }
  143. public AuthInfo GetAuthInfo(UUID principalID)
  144. {
  145. return m_AuthenticationService.GetAuthInfo(principalID);
  146. }
  147. public bool SetAuthInfo(AuthInfo info)
  148. {
  149. return m_AuthenticationService.SetAuthInfo(info);
  150. }
  151. #endregion
  152. }
  153. }