aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authordiva2009-03-22 04:39:16 +0000
committerdiva2009-03-22 04:39:16 +0000
commit9489ad57f98e13c61725fe157eacf2e56053abe6 (patch)
tree08f22bd1eae20197e0e53a9300904608d45805b4 /OpenSim/Region
parentInitial support for authentication/authorization keys in UserManagerBase, and... (diff)
downloadopensim-SC_OLD-9489ad57f98e13c61725fe157eacf2e56053abe6.zip
opensim-SC_OLD-9489ad57f98e13c61725fe157eacf2e56053abe6.tar.gz
opensim-SC_OLD-9489ad57f98e13c61725fe157eacf2e56053abe6.tar.bz2
opensim-SC_OLD-9489ad57f98e13c61725fe157eacf2e56053abe6.tar.xz
Moving the LoginAuth service up, so that it can be shared among standalones and the User Server.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs (renamed from OpenSim/Region/CoreModules/Hypergrid/Login/HGStandaloneLoginModule.cs)4
-rw-r--r--OpenSim/Region/CoreModules/Hypergrid/Login/HGStandaloneLoginService.cs349
2 files changed, 2 insertions, 351 deletions
diff --git a/OpenSim/Region/CoreModules/Hypergrid/Login/HGStandaloneLoginModule.cs b/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs
index 4b74ed5..3f4d875 100644
--- a/OpenSim/Region/CoreModules/Hypergrid/Login/HGStandaloneLoginModule.cs
+++ b/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs
@@ -69,7 +69,7 @@ namespace OpenSim.Region.CoreModules.Hypergrid
69 } 69 }
70 } 70 }
71 71
72 protected HGStandaloneLoginService m_loginService; 72 protected HGLoginAuthService m_loginService;
73 73
74 #region IRegionModule Members 74 #region IRegionModule Members
75 75
@@ -103,7 +103,7 @@ namespace OpenSim.Region.CoreModules.Hypergrid
103 IHttpServer httpServer = m_firstScene.CommsManager.HttpServer; 103 IHttpServer httpServer = m_firstScene.CommsManager.HttpServer;
104 104
105 //TODO: fix the casting of the user service, maybe by registering the userManagerBase with scenes, or refactoring so we just need a IUserService reference 105 //TODO: fix the casting of the user service, maybe by registering the userManagerBase with scenes, or refactoring so we just need a IUserService reference
106 m_loginService = new HGStandaloneLoginService((UserManagerBase)m_firstScene.CommsManager.UserService, welcomeMessage, m_firstScene.CommsManager.InterServiceInventoryService, m_firstScene.CommsManager.NetworkServersInfo, authenticate, rootFolder, this); 106 m_loginService = new HGLoginAuthService((UserManagerBase)m_firstScene.CommsManager.UserService, welcomeMessage, m_firstScene.CommsManager.InterServiceInventoryService, m_firstScene.CommsManager.NetworkServersInfo, authenticate, rootFolder, this);
107 107
108 httpServer.AddXmlRPCHandler("hg_login", m_loginService.XmlRpcLoginMethod); 108 httpServer.AddXmlRPCHandler("hg_login", m_loginService.XmlRpcLoginMethod);
109 httpServer.AddXmlRPCHandler("hg_new_auth_key", m_loginService.XmlRpcGenerateKeyMethod); 109 httpServer.AddXmlRPCHandler("hg_new_auth_key", m_loginService.XmlRpcGenerateKeyMethod);
diff --git a/OpenSim/Region/CoreModules/Hypergrid/Login/HGStandaloneLoginService.cs b/OpenSim/Region/CoreModules/Hypergrid/Login/HGStandaloneLoginService.cs
deleted file mode 100644
index 5ac50f1..0000000
--- a/OpenSim/Region/CoreModules/Hypergrid/Login/HGStandaloneLoginService.cs
+++ /dev/null
@@ -1,349 +0,0 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33using System.Text.RegularExpressions;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Framework.Communications.Capabilities;
38using OpenSim.Framework.Servers;
39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Region.Framework.Interfaces;
41
42using OpenMetaverse;
43
44using log4net;
45using Nini.Config;
46using Nwc.XmlRpc;
47
48namespace OpenSim.Region.CoreModules.Hypergrid
49{
50 public class HGStandaloneLoginService : LoginService
51 {
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 protected NetworkServersInfo m_serversInfo;
55 protected bool m_authUsers = false;
56
57 /// <summary>
58 /// Used by the login service to make requests to the inventory service.
59 /// </summary>
60 protected IInterServiceInventoryServices m_interServiceInventoryService;
61
62 /// <summary>
63 /// Used to make requests to the local regions.
64 /// </summary>
65 protected ILoginServiceToRegionsConnector m_regionsConnector;
66
67
68 public HGStandaloneLoginService(
69 UserManagerBase userManager, string welcomeMess,
70 IInterServiceInventoryServices interServiceInventoryService,
71 NetworkServersInfo serversInfo,
72 bool authenticate, LibraryRootFolder libraryRootFolder, ILoginServiceToRegionsConnector regionsConnector)
73 : base(userManager, libraryRootFolder, welcomeMess)
74 {
75 this.m_serversInfo = serversInfo;
76 m_defaultHomeX = this.m_serversInfo.DefaultHomeLocX;
77 m_defaultHomeY = this.m_serversInfo.DefaultHomeLocY;
78 m_authUsers = authenticate;
79
80 m_interServiceInventoryService = interServiceInventoryService;
81 m_regionsConnector = regionsConnector;
82 m_inventoryService = interServiceInventoryService;
83 }
84
85 public override XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
86 {
87 m_log.Info("[HGLOGIN] HGLogin called " + request.MethodName);
88 XmlRpcResponse response = base.XmlRpcLoginMethod(request);
89 Hashtable responseData = (Hashtable)response.Value;
90
91 responseData["grid_service"] = m_serversInfo.GridURL;
92 responseData["grid_service_send_key"] = m_serversInfo.GridSendKey;
93 responseData["inventory_service"] = m_serversInfo.InventoryURL;
94 responseData["asset_service"] = m_serversInfo.AssetURL;
95 responseData["asset_service_send_key"] = m_serversInfo.AssetSendKey;
96 int x = (Int32)responseData["region_x"];
97 int y = (Int32)responseData["region_y"];
98 uint ux = (uint)(x / Constants.RegionSize);
99 uint uy = (uint)(y / Constants.RegionSize);
100 ulong regionHandle = Util.UIntsToLong(ux, uy);
101 responseData["region_handle"] = regionHandle.ToString();
102 responseData["http_port"] = (UInt32)m_serversInfo.HttpListenerPort;
103
104 // Let's remove the seed cap from the login
105 //responseData.Remove("seed_capability");
106
107 // Let's add the appearance
108 UUID userID = UUID.Zero;
109 UUID.TryParse((string)responseData["agent_id"], out userID);
110 AvatarAppearance appearance = m_userManager.GetUserAppearance(userID);
111 if (appearance == null)
112 {
113 m_log.WarnFormat("[INTER]: Appearance not found for {0}. Creating default.", userID);
114 appearance = new AvatarAppearance();
115 }
116
117 responseData["appearance"] = appearance.ToHashTable();
118
119 // Let's also send the auth token
120 UUID token = UUID.Random();
121 responseData["auth_token"] = token.ToString();
122 UserProfileData userProfile = m_userManager.GetUserProfile(userID);
123 if (userProfile != null)
124 {
125 userProfile.WebLoginKey = token;
126 m_userManager.CommitAgent(ref userProfile);
127 }
128
129 return response;
130 }
131
132 public XmlRpcResponse XmlRpcGenerateKeyMethod(XmlRpcRequest request)
133 {
134
135 // Verify the key of who's calling
136 UUID userID = UUID.Zero;
137 UUID authKey = UUID.Zero;
138 UUID.TryParse((string)request.Params[0], out userID);
139 UUID.TryParse((string)request.Params[1], out authKey);
140
141 m_log.InfoFormat("[HGLOGIN] HGGenerateKey called with authToken ", authKey);
142 string newKey = string.Empty;
143
144 if (!(m_userManager is IAuthentication))
145 {
146 m_log.Debug("[HGLOGIN]: UserManager is not IAuthentication service. Returning empty key.");
147 }
148 else
149 {
150 newKey = ((IAuthentication)m_userManager).GetNewKey(m_serversInfo.UserURL, userID, authKey);
151 }
152
153 XmlRpcResponse response = new XmlRpcResponse();
154 response.Value = (string) newKey;
155 return response;
156 }
157
158 public XmlRpcResponse XmlRpcVerifyKeyMethod(XmlRpcRequest request)
159 {
160 foreach (object o in request.Params)
161 {
162 if (o != null)
163 m_log.Debug(" >> Param " + o.ToString());
164 else
165 m_log.Debug(" >> Null");
166 }
167
168 // Verify the key of who's calling
169 UUID userID = UUID.Zero;
170 string authKey = string.Empty;
171 UUID.TryParse((string)request.Params[0], out userID);
172 authKey = (string)request.Params[1];
173
174 m_log.InfoFormat("[HGLOGIN] HGVerifyKey called with key ", authKey);
175 bool success = false;
176
177 if (!(m_userManager is IAuthentication))
178 {
179 m_log.Debug("[HGLOGIN]: UserManager is not IAuthentication service. Denying.");
180 }
181 else
182 {
183 success = ((IAuthentication)m_userManager).VerifyKey(userID, authKey);
184 }
185
186 XmlRpcResponse response = new XmlRpcResponse();
187 response.Value = (string)success.ToString();
188 return response;
189 }
190
191 public override UserProfileData GetTheUser(string firstname, string lastname)
192 {
193 UserProfileData profile = m_userManager.GetUserProfile(firstname, lastname);
194 if (profile != null)
195 {
196 return profile;
197 }
198
199 if (!m_authUsers)
200 {
201 //no current user account so make one
202 m_log.Info("[LOGIN]: No user account found so creating a new one.");
203
204 m_userManager.AddUser(firstname, lastname, "test", "", m_defaultHomeX, m_defaultHomeY);
205
206 return m_userManager.GetUserProfile(firstname, lastname);
207 }
208
209 return null;
210 }
211
212 public override bool AuthenticateUser(UserProfileData profile, string password)
213 {
214 if (!m_authUsers)
215 {
216 //for now we will accept any password in sandbox mode
217 m_log.Info("[LOGIN]: Authorising user (no actual password check)");
218
219 return true;
220 }
221 else
222 {
223 m_log.Info(
224 "[LOGIN]: Authenticating " + profile.FirstName + " " + profile.SurName);
225
226 if (!password.StartsWith("$1$"))
227 password = "$1$" + Util.Md5Hash(password);
228
229 password = password.Remove(0, 3); //remove $1$
230
231 string s = Util.Md5Hash(password + ":" + profile.PasswordSalt);
232
233 bool loginresult = (profile.PasswordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase)
234 || profile.PasswordHash.Equals(password, StringComparison.InvariantCultureIgnoreCase));
235 return loginresult;
236 }
237 }
238
239 protected override RegionInfo RequestClosestRegion(string region)
240 {
241 return m_regionsConnector.RequestClosestRegion(region);
242 }
243
244 protected override RegionInfo GetRegionInfo(ulong homeRegionHandle)
245 {
246 return m_regionsConnector.RequestNeighbourInfo(homeRegionHandle);
247 }
248
249 protected override RegionInfo GetRegionInfo(UUID homeRegionId)
250 {
251 return m_regionsConnector.RequestNeighbourInfo(homeRegionId);
252 }
253
254
255 /// <summary>
256 /// Prepare a login to the given region. This involves both telling the region to expect a connection
257 /// and appropriately customising the response to the user.
258 /// </summary>
259 /// <param name="sim"></param>
260 /// <param name="user"></param>
261 /// <param name="response"></param>
262 /// <returns>true if the region was successfully contacted, false otherwise</returns>
263 protected override bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response)
264 {
265 IPEndPoint endPoint = regionInfo.ExternalEndPoint;
266 response.SimAddress = endPoint.Address.ToString();
267 response.SimPort = (uint)endPoint.Port;
268 response.RegionX = regionInfo.RegionLocX;
269 response.RegionY = regionInfo.RegionLocY;
270
271 string capsPath = CapsUtil.GetRandomCapsObjectPath();
272 string capsSeedPath = CapsUtil.GetCapsSeedPath(capsPath);
273
274 // Don't use the following! It Fails for logging into any region not on the same port as the http server!
275 // Kept here so it doesn't happen again!
276 // response.SeedCapability = regionInfo.ServerURI + capsSeedPath;
277
278 string seedcap = "http://";
279
280 if (m_serversInfo.HttpUsesSSL)
281 {
282 seedcap = "https://" + m_serversInfo.HttpSSLCN + ":" + m_serversInfo.httpSSLPort + capsSeedPath;
283 }
284 else
285 {
286 seedcap = "http://" + regionInfo.ExternalHostName + ":" + m_serversInfo.HttpListenerPort + capsSeedPath;
287 }
288
289 response.SeedCapability = seedcap;
290
291 // Notify the target of an incoming user
292 m_log.InfoFormat(
293 "[LOGIN]: Telling {0} @ {1},{2} ({3}) to prepare for client connection",
294 regionInfo.RegionName, response.RegionX, response.RegionY, regionInfo.ServerURI);
295
296 // Update agent with target sim
297 user.CurrentAgent.Region = regionInfo.RegionID;
298 user.CurrentAgent.Handle = regionInfo.RegionHandle;
299
300 AgentCircuitData agent = new AgentCircuitData();
301 agent.AgentID = user.ID;
302 agent.firstname = user.FirstName;
303 agent.lastname = user.SurName;
304 agent.SessionID = user.CurrentAgent.SessionID;
305 agent.SecureSessionID = user.CurrentAgent.SecureSessionID;
306 agent.circuitcode = Convert.ToUInt32(response.CircuitCode);
307 agent.BaseFolder = UUID.Zero;
308 agent.InventoryFolder = UUID.Zero;
309 agent.startpos = user.CurrentAgent.Position;
310 agent.CapsPath = capsPath;
311 agent.Appearance = m_userManager.GetUserAppearance(user.ID);
312 if (agent.Appearance == null)
313 {
314 m_log.WarnFormat("[INTER]: Appearance not found for {0} {1}. Creating default.", agent.firstname, agent.lastname);
315 agent.Appearance = new AvatarAppearance();
316 }
317
318 if (m_regionsConnector.RegionLoginsEnabled)
319 {
320 // m_log.Info("[LLStandaloneLoginModule] Informing region about user");
321 return m_regionsConnector.NewUserConnection(regionInfo.RegionHandle, agent);
322 }
323
324 return false;
325 }
326
327 public override void LogOffUser(UserProfileData theUser, string message)
328 {
329 RegionInfo SimInfo;
330 try
331 {
332 SimInfo = this.m_regionsConnector.RequestNeighbourInfo(theUser.CurrentAgent.Handle);
333
334 if (SimInfo == null)
335 {
336 m_log.Error("[LOCAL LOGIN]: Region user was in isn't currently logged in");
337 return;
338 }
339 }
340 catch (Exception)
341 {
342 m_log.Error("[LOCAL LOGIN]: Unable to look up region to log user off");
343 return;
344 }
345
346 m_regionsConnector.LogOffUserFromGrid(SimInfo.RegionHandle, theUser.ID, theUser.CurrentAgent.SecureSessionID, "Logging you off");
347 }
348 }
349}