diff options
Diffstat (limited to 'OpenSim/Data')
-rw-r--r-- | OpenSim/Data/IAuthenticationData.cs | 4 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/MySQLAuthenticationData.cs | 55 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/Resources/001_AuthStore.sql | 21 |
3 files changed, 80 insertions, 0 deletions
diff --git a/OpenSim/Data/IAuthenticationData.cs b/OpenSim/Data/IAuthenticationData.cs index f848716..7753e04 100644 --- a/OpenSim/Data/IAuthenticationData.cs +++ b/OpenSim/Data/IAuthenticationData.cs | |||
@@ -48,5 +48,9 @@ namespace OpenSim.Data | |||
48 | bool Store(AuthenticationData data); | 48 | bool Store(AuthenticationData data); |
49 | 49 | ||
50 | bool SetDataItem(UUID principalID, string item, string value); | 50 | bool SetDataItem(UUID principalID, string item, string value); |
51 | |||
52 | bool SetToken(UUID principalID, string token, int lifetime); | ||
53 | |||
54 | bool CheckToken(UUID principalID, string token, int lifetime); | ||
51 | } | 55 | } |
52 | } | 56 | } |
diff --git a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs index 19575ec..afd59bd 100644 --- a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs +++ b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs | |||
@@ -39,11 +39,15 @@ namespace OpenSim.Data.MySQL | |||
39 | { | 39 | { |
40 | private string m_Realm; | 40 | private string m_Realm; |
41 | private List<string> m_ColumnNames = null; | 41 | private List<string> m_ColumnNames = null; |
42 | private int m_LastExpire = 0; | ||
42 | 43 | ||
43 | public MySqlAuthenticationData(string connectionString, string realm) | 44 | public MySqlAuthenticationData(string connectionString, string realm) |
44 | : base(connectionString) | 45 | : base(connectionString) |
45 | { | 46 | { |
46 | m_Realm = realm; | 47 | m_Realm = realm; |
48 | |||
49 | Migration m = new Migration(m_Connection, GetType().Assembly, "AuthStore"); | ||
50 | m.Update(); | ||
47 | } | 51 | } |
48 | 52 | ||
49 | public AuthenticationData Get(UUID principalID) | 53 | public AuthenticationData Get(UUID principalID) |
@@ -153,5 +157,56 @@ namespace OpenSim.Data.MySQL | |||
153 | 157 | ||
154 | return false; | 158 | return false; |
155 | } | 159 | } |
160 | |||
161 | public bool SetToken(UUID principalID, string token, int lifetime) | ||
162 | { | ||
163 | if (System.Environment.TickCount - m_LastExpire > 30000) | ||
164 | DoExpire(); | ||
165 | |||
166 | MySqlCommand cmd = new MySqlCommand("insert into tokens (UUID, token, validity) values (?principalID, ?token, date_add(now(), interval ?lifetime minute))"); | ||
167 | cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); | ||
168 | cmd.Parameters.AddWithValue("?token", token); | ||
169 | cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString()); | ||
170 | |||
171 | if (ExecuteNonQuery(cmd) > 0) | ||
172 | { | ||
173 | cmd.Dispose(); | ||
174 | return true; | ||
175 | } | ||
176 | |||
177 | cmd.Dispose(); | ||
178 | return false; | ||
179 | } | ||
180 | |||
181 | public bool CheckToken(UUID principalID, string token, int lifetime) | ||
182 | { | ||
183 | if (System.Environment.TickCount - m_LastExpire > 30000) | ||
184 | DoExpire(); | ||
185 | |||
186 | MySqlCommand cmd = new MySqlCommand("update tokens set validity = date_add(now(), interval ?lifetime minute) where UUID = ?principalID and token = ?token and validity > now()"); | ||
187 | cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); | ||
188 | cmd.Parameters.AddWithValue("?token", token); | ||
189 | cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString()); | ||
190 | |||
191 | if (ExecuteNonQuery(cmd) > 0) | ||
192 | { | ||
193 | cmd.Dispose(); | ||
194 | return true; | ||
195 | } | ||
196 | |||
197 | cmd.Dispose(); | ||
198 | |||
199 | return false; | ||
200 | } | ||
201 | |||
202 | private void DoExpire() | ||
203 | { | ||
204 | MySqlCommand cmd = new MySqlCommand("delete from tokens where validity < now()"); | ||
205 | ExecuteNonQuery(cmd); | ||
206 | |||
207 | cmd.Dispose(); | ||
208 | |||
209 | m_LastExpire = System.Environment.TickCount; | ||
210 | } | ||
156 | } | 211 | } |
157 | } | 212 | } |
diff --git a/OpenSim/Data/MySQL/Resources/001_AuthStore.sql b/OpenSim/Data/MySQL/Resources/001_AuthStore.sql new file mode 100644 index 0000000..c7e16fb --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/001_AuthStore.sql | |||
@@ -0,0 +1,21 @@ | |||
1 | begin; | ||
2 | |||
3 | CREATE TABLE `auth` ( | ||
4 | `UUID` char(36) NOT NULL, | ||
5 | `passwordHash` char(32) NOT NULL default '', | ||
6 | `passwordSalt` char(32) NOT NULL default '', | ||
7 | `webLoginKey` varchar(255) NOT NULL default '', | ||
8 | PRIMARY KEY (`UUID`) | ||
9 | ) ENGINE=InnoDB; | ||
10 | |||
11 | CREATE TABLE `tokens` ( | ||
12 | `UUID` char(36) NOT NULL, | ||
13 | `token` varchar(255) NOT NULL, | ||
14 | `validity` datetime NOT NULL, | ||
15 | UNIQUE KEY `uuid_token` (`UUID`,`token`), | ||
16 | KEY `UUID` (`UUID`), | ||
17 | KEY `token` (`token`), | ||
18 | KEY `validity` (`validity`) | ||
19 | ) ENGINE=InnoDB; | ||
20 | |||
21 | commit; | ||