More work on new authentication service

remotes/origin/0.6.7-post-fixes
Melanie 2009-09-04 03:13:32 +01:00
parent e39d0ef627
commit c9a24ece54
5 changed files with 43 additions and 18 deletions

View File

@ -38,7 +38,7 @@ namespace OpenSim.Data.MySQL
public class MySqlAuthenticationData : MySqlFramework, IAuthenticationData public class MySqlAuthenticationData : MySqlFramework, IAuthenticationData
{ {
private string m_Realm; private string m_Realm;
private DataTable m_SchemaTable = null; private List<string> m_ColumnNames = null;
public MySqlAuthenticationData(string connectionString, string realm) public MySqlAuthenticationData(string connectionString, string realm)
: base(connectionString) : base(connectionString)
@ -63,15 +63,21 @@ namespace OpenSim.Data.MySQL
{ {
ret.PrincipalID = principalID; ret.PrincipalID = principalID;
if (m_SchemaTable == null) if (m_ColumnNames == null)
m_SchemaTable = result.GetSchemaTable();
foreach (DataColumn c in m_SchemaTable.Columns)
{ {
if (c.ColumnName == "UUID") m_ColumnNames = new List<string>();
DataTable schemaTable = result.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
m_ColumnNames.Add(row["ColumnName"].ToString());
}
foreach (string s in m_ColumnNames)
{
if (s == "UUID")
continue; continue;
ret.Data[c.ColumnName] = result[c.ColumnName].ToString(); ret.Data[s] = result[s].ToString();
} }
result.Close(); result.Close();
@ -105,21 +111,23 @@ namespace OpenSim.Data.MySQL
first = false; first = false;
cmd.Parameters.AddWithValue(field, data.Data[field]); cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
} }
update += " where UUID = ?principalID"; update += " where UUID = ?principalID";
cmd.CommandText = update; cmd.CommandText = update;
cmd.Parameters.AddWithValue("UUID", data.PrincipalID.ToString()); cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString());
if (ExecuteNonQuery(cmd) < 1) if (ExecuteNonQuery(cmd) < 1)
{ {
string insert = "insert into `" + m_Realm + "` (`UUID`, `" + string insert = "insert into `" + m_Realm + "` (`UUID`, `" +
String.Join("`, `", fields) + String.Join("`, `", fields) +
"`) values ( ?UUID, ?" + String.Join(", ?", fields) + ")"; "`) values ( ?principalID, ?" + String.Join(", ?", fields) + ")";
if (ExecuteNonQuery(cmd) < 0) cmd.CommandText = insert;
if (ExecuteNonQuery(cmd) < 1)
{ {
cmd.Dispose(); cmd.Dispose();
return false; return false;
@ -137,8 +145,11 @@ namespace OpenSim.Data.MySQL
"` set `" + item + "` = ?" + item + " where UUID = ?UUID"); "` set `" + item + "` = ?" + item + " where UUID = ?UUID");
cmd.Parameters.AddWithValue(item, value); cmd.Parameters.AddWithValue("?"+item, value);
cmd.Parameters.AddWithValue("UUID", principalID.ToString()); cmd.Parameters.AddWithValue("?UUID", principalID.ToString());
if (ExecuteNonQuery(cmd) > 0)
return true;
return false; return false;
} }

View File

@ -70,6 +70,7 @@ namespace OpenSim.Data.MySQL
} }
catch (MySqlException e) catch (MySqlException e)
{ {
Console.WriteLine(e.ToString());
if (errorSeen) if (errorSeen)
throw; throw;
@ -88,6 +89,13 @@ namespace OpenSim.Data.MySQL
cmd.Connection = m_Connection; cmd.Connection = m_Connection;
} }
else
throw;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return 0;
} }
} }
} }

View File

@ -36,7 +36,7 @@ namespace OpenSim.Server.Handlers.Authentication
{ {
public class AuthenticationServiceConnector : ServiceConnector public class AuthenticationServiceConnector : ServiceConnector
{ {
//private IAuthenticationService m_AuthenticationService; private IAuthenticationService m_AuthenticationService;
public AuthenticationServiceConnector(IConfigSource config, IHttpServer server) : public AuthenticationServiceConnector(IConfigSource config, IHttpServer server) :
base(config, server) base(config, server)
@ -51,8 +51,8 @@ namespace OpenSim.Server.Handlers.Authentication
if (authenticationService == String.Empty) if (authenticationService == String.Empty)
throw new Exception("No AuthenticationService in config file"); throw new Exception("No AuthenticationService in config file");
//Object[] args = new Object[] { config }; Object[] args = new Object[] { config };
//m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authenticationService, args); m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authenticationService, args);
//server.AddStreamHandler(new AuthenticationServerGetHandler(m_AuthenticationService)); //server.AddStreamHandler(new AuthenticationServerGetHandler(m_AuthenticationService));
} }

View File

@ -53,6 +53,7 @@ namespace OpenSim.Services.AuthenticationService
{ {
string dllName = String.Empty; string dllName = String.Empty;
string connString = String.Empty; string connString = String.Empty;
string realm = String.Empty;
// //
// Try reading the [AuthenticationService] section first, if it exists // Try reading the [AuthenticationService] section first, if it exists
@ -62,6 +63,7 @@ namespace OpenSim.Services.AuthenticationService
{ {
dllName = authConfig.GetString("StorageProvider", dllName); dllName = authConfig.GetString("StorageProvider", dllName);
connString = authConfig.GetString("ConnectionString", connString); connString = authConfig.GetString("ConnectionString", connString);
realm = authConfig.GetString("Realm", realm);
} }
// //
@ -79,11 +81,11 @@ namespace OpenSim.Services.AuthenticationService
// //
// We tried, but this doesn't exist. We can't proceed. // We tried, but this doesn't exist. We can't proceed.
// //
if (dllName.Equals(String.Empty)) if (dllName == String.Empty || realm == String.Empty)
throw new Exception("No StorageProvider configured"); throw new Exception("No StorageProvider configured");
m_Database = LoadPlugin<IAuthenticationData>(dllName, m_Database = LoadPlugin<IAuthenticationData>(dllName,
new Object[] {connString}); new Object[] {connString, realm});
if (m_Database == null) if (m_Database == null)
throw new Exception("Could not find a storage interface in the given module"); throw new Exception("Could not find a storage interface in the given module");
} }

View File

@ -26,11 +26,15 @@
*/ */
using System; using System;
using System.Collections.Generic;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
using log4net; using log4net;
using Nini.Config; using Nini.Config;
using System.Reflection; using System.Reflection;
using OpenSim.Data;
using OpenSim.Framework;
using OpenSim.Framework.Console;
namespace OpenSim.Services.AuthenticationService namespace OpenSim.Services.AuthenticationService
{ {