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