32 using System.Reflection;
33 using OpenSim.Server.Base;
34 using OpenSim.Services.Interfaces;
36 using OpenSim.Framework;
37 using OpenSim.Services.Base;
39 namespace OpenSim.Services.AuthenticationService
49 private static readonly ILog m_log =
51 MethodBase.GetCurrentMethod().DeclaringType);
58 m_UserAccountService = acct;
63 string dllName = String.Empty;
64 string connString = String.Empty;
65 string realm =
"auth";
70 IConfig authConfig = config.Configs[
"AuthenticationService"];
71 if (authConfig != null)
73 dllName = authConfig.GetString(
"StorageProvider", dllName);
74 connString = authConfig.GetString(
"ConnectionString", connString);
75 realm = authConfig.GetString(
"Realm", realm);
81 IConfig dbConfig = config.Configs[
"DatabaseService"];
84 if (dllName == String.Empty)
85 dllName = dbConfig.GetString(
"StorageProvider", String.Empty);
86 if (connString == String.Empty)
87 connString = dbConfig.GetString(
"ConnectionString", String.Empty);
93 if (dllName == String.Empty || realm == String.Empty)
94 throw new Exception(
"No StorageProvider configured");
96 m_Database = LoadPlugin<IAuthenticationData>(dllName,
97 new Object[] {connString, realm});
98 if (m_Database == null)
99 throw new Exception(
string.Format(
"Could not find a storage interface in module {0}", dllName));
102 public bool Verify(UUID principalID,
string token,
int lifetime)
104 return m_Database.CheckToken(principalID, token, lifetime);
107 public virtual bool Release(UUID principalID,
string token)
109 return m_Database.CheckToken(principalID, token, 0);
112 public virtual bool SetPassword(UUID principalID,
string password)
114 string passwordSalt = Util.Md5Hash(UUID.Random().ToString());
115 string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) +
":" + passwordSalt);
121 auth.PrincipalID = principalID;
122 auth.Data =
new System.Collections.Generic.Dictionary<string,
object>();
123 auth.Data[
"accountType"] =
"UserAccount";
124 auth.Data[
"webLoginKey"] = UUID.Zero.ToString();
126 auth.Data[
"passwordHash"] = md5PasswdHash;
127 auth.Data[
"passwordSalt"] = passwordSalt;
128 if (!m_Database.Store(auth))
130 m_log.DebugFormat(
"[AUTHENTICATION DB]: Failed to store authentication data");
134 m_log.InfoFormat(
"[AUTHENTICATION DB]: Set password for principalID {0}", principalID);
151 PrincipalID = data.PrincipalID,
152 AccountType = data.Data[
"accountType"] as string,
153 PasswordHash = data.Data[
"passwordHash"] as string,
154 PasswordSalt = data.Data[
"passwordSalt"] as string,
155 WebLoginKey = data.Data[
"webLoginKey"] as
string
165 auth.PrincipalID = info.PrincipalID;
166 auth.Data =
new System.Collections.Generic.Dictionary<string,
object>();
167 auth.Data[
"accountType"] = info.AccountType;
168 auth.Data[
"webLoginKey"] = info.WebLoginKey;
169 auth.Data[
"passwordHash"] = info.PasswordHash;
170 auth.Data[
"passwordSalt"] = info.PasswordSalt;
172 if (!m_Database.Store(auth))
174 m_log.ErrorFormat(
"[AUTHENTICATION DB]: Failed to store authentication info.");
178 m_log.DebugFormat(
"[AUTHENTICATION DB]: Set authentication info for principalID {0}", info.PrincipalID);
182 protected string GetToken(UUID principalID,
int lifetime)
184 UUID token = UUID.Random();
186 if (m_Database.SetToken(principalID, token.ToString(), lifetime))
187 return token.ToString();
AuthenticationServiceBase(IConfigSource config)
virtual AuthInfo GetAuthInfo(UUID principalID)
AuthenticationServiceBase(IConfigSource config, IUserAccountService acct)
virtual bool SetAuthInfo(AuthInfo info)
string GetToken(UUID principalID, int lifetime)
IAuthenticationData m_Database
virtual bool SetPassword(UUID principalID, string password)
Interactive OpenSim region server
bool Verify(UUID principalID, string token, int lifetime)
virtual bool Release(UUID principalID, string token)
An interface for connecting to the authentication datastore