diff options
Diffstat (limited to 'OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs')
-rw-r--r-- | OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs | 90 |
1 files changed, 85 insertions, 5 deletions
diff --git a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs index dcf090e..e42f9a0 100644 --- a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs +++ b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs | |||
@@ -30,8 +30,11 @@ using OpenMetaverse; | |||
30 | using log4net; | 30 | using log4net; |
31 | using Nini.Config; | 31 | using Nini.Config; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Services.Base; | 33 | using OpenSim.Server.Base; |
34 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Data; | 35 | using OpenSim.Data; |
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Services.Base; | ||
35 | 38 | ||
36 | namespace OpenSim.Services.AuthenticationService | 39 | namespace OpenSim.Services.AuthenticationService |
37 | { | 40 | { |
@@ -43,11 +46,17 @@ namespace OpenSim.Services.AuthenticationService | |||
43 | // | 46 | // |
44 | public class AuthenticationServiceBase : ServiceBase | 47 | public class AuthenticationServiceBase : ServiceBase |
45 | { | 48 | { |
46 | // private static readonly ILog m_log = | 49 | private static readonly ILog m_log = |
47 | // LogManager.GetLogger( | 50 | LogManager.GetLogger( |
48 | // MethodBase.GetCurrentMethod().DeclaringType); | 51 | MethodBase.GetCurrentMethod().DeclaringType); |
49 | 52 | ||
50 | protected IAuthenticationData m_Database; | 53 | protected IAuthenticationData m_Database; |
54 | protected IUserAccountService m_UserAccountService = null; | ||
55 | |||
56 | public AuthenticationServiceBase(IConfigSource config, IUserAccountService acct) : this(config) | ||
57 | { | ||
58 | m_UserAccountService = acct; | ||
59 | } | ||
51 | 60 | ||
52 | public AuthenticationServiceBase(IConfigSource config) : base(config) | 61 | public AuthenticationServiceBase(IConfigSource config) : base(config) |
53 | { | 62 | { |
@@ -87,7 +96,7 @@ namespace OpenSim.Services.AuthenticationService | |||
87 | m_Database = LoadPlugin<IAuthenticationData>(dllName, | 96 | m_Database = LoadPlugin<IAuthenticationData>(dllName, |
88 | new Object[] {connString, realm}); | 97 | new Object[] {connString, realm}); |
89 | if (m_Database == null) | 98 | if (m_Database == null) |
90 | throw new Exception("Could not find a storage interface in the given module"); | 99 | throw new Exception(string.Format("Could not find a storage interface in module {0}", dllName)); |
91 | } | 100 | } |
92 | 101 | ||
93 | public bool Verify(UUID principalID, string token, int lifetime) | 102 | public bool Verify(UUID principalID, string token, int lifetime) |
@@ -100,6 +109,76 @@ namespace OpenSim.Services.AuthenticationService | |||
100 | return m_Database.CheckToken(principalID, token, 0); | 109 | return m_Database.CheckToken(principalID, token, 0); |
101 | } | 110 | } |
102 | 111 | ||
112 | public virtual bool SetPassword(UUID principalID, string password) | ||
113 | { | ||
114 | string passwordSalt = Util.Md5Hash(UUID.Random().ToString()); | ||
115 | string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + passwordSalt); | ||
116 | |||
117 | AuthenticationData auth = m_Database.Get(principalID); | ||
118 | if (auth == null) | ||
119 | { | ||
120 | auth = new AuthenticationData(); | ||
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(); | ||
125 | } | ||
126 | auth.Data["passwordHash"] = md5PasswdHash; | ||
127 | auth.Data["passwordSalt"] = passwordSalt; | ||
128 | if (!m_Database.Store(auth)) | ||
129 | { | ||
130 | m_log.DebugFormat("[AUTHENTICATION DB]: Failed to store authentication data"); | ||
131 | return false; | ||
132 | } | ||
133 | |||
134 | m_log.InfoFormat("[AUTHENTICATION DB]: Set password for principalID {0}", principalID); | ||
135 | return true; | ||
136 | } | ||
137 | |||
138 | public virtual AuthInfo GetAuthInfo(UUID principalID) | ||
139 | { | ||
140 | AuthenticationData data = m_Database.Get(principalID); | ||
141 | |||
142 | if (data == null) | ||
143 | { | ||
144 | return null; | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | AuthInfo info | ||
149 | = new AuthInfo() | ||
150 | { | ||
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 | ||
156 | }; | ||
157 | |||
158 | return info; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | public virtual bool SetAuthInfo(AuthInfo info) | ||
163 | { | ||
164 | AuthenticationData auth = new AuthenticationData(); | ||
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; | ||
171 | |||
172 | if (!m_Database.Store(auth)) | ||
173 | { | ||
174 | m_log.ErrorFormat("[AUTHENTICATION DB]: Failed to store authentication info."); | ||
175 | return false; | ||
176 | } | ||
177 | |||
178 | m_log.DebugFormat("[AUTHENTICATION DB]: Set authentication info for principalID {0}", info.PrincipalID); | ||
179 | return true; | ||
180 | } | ||
181 | |||
103 | protected string GetToken(UUID principalID, int lifetime) | 182 | protected string GetToken(UUID principalID, int lifetime) |
104 | { | 183 | { |
105 | UUID token = UUID.Random(); | 184 | UUID token = UUID.Random(); |
@@ -109,5 +188,6 @@ namespace OpenSim.Services.AuthenticationService | |||
109 | 188 | ||
110 | return String.Empty; | 189 | return String.Empty; |
111 | } | 190 | } |
191 | |||
112 | } | 192 | } |
113 | } | 193 | } |