29 using System.Collections.Generic;
31 using OpenSim.Services.Interfaces;
34 using System.Reflection;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Console;
39 namespace OpenSim.Services.AuthenticationService
50 private static readonly ILog m_log =
52 MethodBase.GetCurrentMethod().DeclaringType);
55 base(config, userService)
57 m_log.Debug(
"[AUTH SERVICE]: Started with User Account access");
65 public string Authenticate(UUID principalID,
string password,
int lifetime)
68 return Authenticate(principalID, password, lifetime, out realID);
71 public string Authenticate(UUID principalID,
string password,
int lifetime, out UUID realID)
75 m_log.DebugFormat(
"[AUTH SERVICE]: Authenticating for {0}, user account service present: {1}", principalID, m_UserAccountService != null);
78 if (m_UserAccountService != null)
79 user = m_UserAccountService.GetUserAccount(UUID.Zero, principalID);
81 if (data == null || data.Data == null)
83 m_log.DebugFormat(
"[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID);
87 if (!data.Data.ContainsKey(
"passwordHash") ||
88 !data.Data.ContainsKey(
"passwordSalt"))
93 string hashed = Util.Md5Hash(password +
":" +
94 data.Data[
"passwordSalt"].ToString());
98 if (data.Data[
"passwordHash"].ToString() == hashed)
100 return GetToken(principalID, lifetime);
105 m_log.DebugFormat(
"[PASS AUTH]: No user record for {0}", principalID);
109 int impersonateFlag = 1 << 6;
111 if ((user.UserFlags & impersonateFlag) == 0)
114 m_log.DebugFormat(
"[PASS AUTH]: Attempting impersonation");
116 List<UserAccount> accounts = m_UserAccountService.GetUserAccountsWhere(UUID.Zero,
"UserLevel >= 200");
117 if (accounts == null || accounts.Count == 0)
122 data = m_Database.Get(a.PrincipalID);
123 if (data == null || data.Data == null ||
124 !data.Data.ContainsKey(
"passwordHash") ||
125 !data.Data.ContainsKey(
"passwordSalt"))
132 hashed = Util.Md5Hash(password +
":" +
133 data.Data[
"passwordSalt"].ToString());
135 if (data.Data[
"passwordHash"].ToString() == hashed)
137 m_log.DebugFormat(
"[PASS AUTH]: {0} {1} impersonating {2}, proceeding with login", a.FirstName, a.LastName, principalID);
138 realID = a.PrincipalID;
139 return GetToken(principalID, lifetime);
149 m_log.DebugFormat(
"[PASS AUTH]: Impersonation of {0} failed", principalID);
string Authenticate(UUID principalID, string password, int lifetime)
string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
PasswordAuthenticationService(IConfigSource config, IUserAccountService userService)
PasswordAuthenticationService(IConfigSource config)