Fully implement unencrypted auth token operations

remotes/origin/0.6.7-post-fixes
Melanie 2009-09-04 07:48:09 +01:00
parent 548f508044
commit ac40c7a74c
3 changed files with 64 additions and 3 deletions

View File

@ -48,5 +48,9 @@ namespace OpenSim.Data
bool Store(AuthenticationData data);
bool SetDataItem(UUID principalID, string item, string value);
bool SetToken(UUID principalID, string token, int lifetime);
bool CheckToken(UUID principalID, string token, int lifetime);
}
}

View File

@ -39,6 +39,7 @@ namespace OpenSim.Data.MySQL
{
private string m_Realm;
private List<string> m_ColumnNames = null;
private int m_LastExpire = 0;
public MySqlAuthenticationData(string connectionString, string realm)
: base(connectionString)
@ -153,5 +154,56 @@ namespace OpenSim.Data.MySQL
return false;
}
public bool SetToken(UUID principalID, string token, int lifetime)
{
if (System.Environment.TickCount - m_LastExpire > 30000)
DoExpire();
MySqlCommand cmd = new MySqlCommand("insert into tokens (UUID, token, validity) values (?principalID, ?token, date_add(now(), interval ?lifetime minute))");
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
cmd.Parameters.AddWithValue("?token", token);
cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString());
if (ExecuteNonQuery(cmd) > 0)
{
cmd.Dispose();
return true;
}
cmd.Dispose();
return false;
}
public bool CheckToken(UUID principalID, string token, int lifetime)
{
if (System.Environment.TickCount - m_LastExpire > 30000)
DoExpire();
MySqlCommand cmd = new MySqlCommand("update tokens set validity = date_add(now(), interval ?lifetime minute) where UUID = ?principalID and token = ?token and validity > now()");
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
cmd.Parameters.AddWithValue("?token", token);
cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString());
if (ExecuteNonQuery(cmd) > 0)
{
cmd.Dispose();
return true;
}
cmd.Dispose();
return false;
}
private void DoExpire()
{
MySqlCommand cmd = new MySqlCommand("delete from tokens where validity < now()");
ExecuteNonQuery(cmd);
cmd.Dispose();
m_LastExpire = System.Environment.TickCount;
}
}
}

View File

@ -97,7 +97,7 @@ namespace OpenSim.Services.AuthenticationService
public bool Verify(UUID principalID, string token, int lifetime)
{
return false;
return m_Database.CheckToken(principalID, token, lifetime);
}
public bool VerifyEncrypted(byte[] cyphertext, byte[] key)
@ -107,7 +107,7 @@ namespace OpenSim.Services.AuthenticationService
public virtual bool Release(UUID principalID, string token)
{
return false;
return m_Database.CheckToken(principalID, token, 0);
}
public virtual bool ReleaseEncrypted(byte[] cyphertext, byte[] key)
@ -117,7 +117,12 @@ namespace OpenSim.Services.AuthenticationService
protected string GetToken(UUID principalID, int lifetime)
{
return "OK";
UUID token = UUID.Random();
if (m_Database.SetToken(principalID, token.ToString(), lifetime))
return token.ToString();
return String.Empty;
}
}
}