Making combined auth service re-use the existing auth services instead of duplicating code

Signed-off-by: SignpostMarv Martin <me@signpostmarv.name>
0.7.1-dev
SignpostMarv Martin 2011-03-21 15:42:57 +00:00 committed by Justin Clark-Casey (justincc)
parent 0e808950fb
commit 3bc859a834
1 changed files with 19 additions and 21 deletions

View File

@ -8,58 +8,56 @@ using System.Reflection;
using OpenSim.Data; using OpenSim.Data;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Server.Base;
namespace OpenSim.Services.AuthenticationService namespace OpenSim.Services.AuthenticationService
{ {
public class WebkeyOrPasswordAuthenticationService : AuthenticationServiceBase, IAuthenticationService public class WebkeyOrPasswordAuthenticationService : AuthenticationServiceBase, IAuthenticationService
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IConfigSource config;
public WebkeyOrPasswordAuthenticationService(IConfigSource config) public WebkeyOrPasswordAuthenticationService(IConfigSource config)
: base(config) : base(config)
{ {
this.config = config;
} }
public string Authenticate(UUID principalID, string password, int lifetime) public string Authenticate(UUID principalID, string password, int lifetime)
{ {
AuthenticationData data = m_Database.Get(principalID); AuthenticationData data = m_Database.Get(principalID);
IAuthenticationService svc;
Object[] args = new Object[] { config };
string result = String.Empty;
if (data != null && data.Data != null) if (data != null && data.Data != null)
{ {
if (data.Data.ContainsKey("webLoginKey")) if (data.Data.ContainsKey("webLoginKey"))
{ {
m_log.InfoFormat("[Authenticate]: Trying a web key authentication"); svc = ServerUtils.LoadPlugin<IAuthenticationService>("OpenSim.Services.AuthenticationService.dll", "WebkeyAuthenticationService", args);
if (new UUID(password) == UUID.Zero) result = svc.Authenticate(principalID, password, lifetime);
if (result == String.Empty)
{ {
m_log.InfoFormat("[Authenticate]: NULL_KEY is not a valid web_login_key"); m_log.DebugFormat("[Authenticate]: Web Login failed for PrincipalID {0}", principalID);
}
else
{
string key = data.Data["webLoginKey"].ToString();
m_log.DebugFormat("[WEB LOGIN AUTH]: got {0} for key in db vs {1}", key, password);
if (key == password)
{
data.Data["webLoginKey"] = UUID.Zero.ToString();
m_Database.Store(data);
return GetToken(principalID, lifetime);
}
} }
} }
if (data.Data.ContainsKey("passwordHash") && data.Data.ContainsKey("passwordSalt")) if (data.Data.ContainsKey("passwordHash") && data.Data.ContainsKey("passwordSalt"))
{ {
m_log.InfoFormat("[Authenticate]: Trying a password authentication"); svc = ServerUtils.LoadPlugin<IAuthenticationService>("OpenSim.Services.AuthenticationService.dll", "PasswordAuthenticationService", args);
string hashed = Util.Md5Hash(password + ":" + data.Data["passwordSalt"].ToString()); result = svc.Authenticate(principalID, password, lifetime);
m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); if (result == String.Empty)
if (data.Data["passwordHash"].ToString() == hashed)
{ {
return GetToken(principalID, lifetime); m_log.DebugFormat("[Authenticate]: Password login failed for PrincipalID {0}", principalID);
} }
} }
m_log.DebugFormat("[AUTH SERVICE]: Both password and webLoginKey-based login failed for PrincipalID {0}", principalID); if (result == string.Empty)
{
m_log.DebugFormat("[AUTH SERVICE]: Both password and webLoginKey-based login failed for PrincipalID {0}", principalID);
}
} }
else else
{ {
m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID); m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID);
} }
return string.Empty; return result;
} }
} }
} }