From 4c9400e6460a73baa2d687afe73a62c6efca9f37 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 24 Oct 2011 21:34:44 +0100 Subject: Add optional getauthinfo and setauthinfo authentication service calls. These are disabled by default, as before. Please only turn these on in secure grids, since they allow the same facilities as the existing SetPassword call (also disabled by default) These facilities can be helpful when integrating external systems, in addition to the existing option of adapting an IAuthenticationService or using WebLoginKey --- .../AuthenticationServiceBase.cs | 47 +++++++++++++++++++++- .../AuthenticationServiceConnector.cs | 12 ++++++ .../SimianAuthenticationServiceConnector.cs | 10 +++++ .../Services/Interfaces/IAuthenticationService.cs | 26 ++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) (limited to 'OpenSim/Services') diff --git a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs index edc1097..229f557 100644 --- a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs +++ b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs @@ -30,9 +30,10 @@ using OpenMetaverse; using log4net; using Nini.Config; using System.Reflection; -using OpenSim.Services.Base; using OpenSim.Data; using OpenSim.Framework; +using OpenSim.Services.Base; +using OpenSim.Services.Interfaces; namespace OpenSim.Services.AuthenticationService { @@ -126,6 +127,50 @@ namespace OpenSim.Services.AuthenticationService m_log.InfoFormat("[AUTHENTICATION DB]: Set password for principalID {0}", principalID); return true; } + + public virtual AuthInfo GetAuthInfo(UUID principalID) + { + AuthenticationData data = m_Database.Get(principalID); + + if (data == null) + { + return null; + } + else + { + AuthInfo info + = new AuthInfo() + { + PrincipalID = data.PrincipalID, + AccountType = data.Data["accountType"] as string, + PasswordHash = data.Data["passwordHash"] as string, + PasswordSalt = data.Data["passwordSalt"] as string, + WebLoginKey = data.Data["webLoginKey"] as string + }; + + return info; + } + } + + public virtual bool SetAuthInfo(AuthInfo info) + { + AuthenticationData auth = new AuthenticationData(); + auth.PrincipalID = info.PrincipalID; + auth.Data = new System.Collections.Generic.Dictionary(); + auth.Data["accountType"] = info.AccountType; + auth.Data["webLoginKey"] = info.WebLoginKey; + auth.Data["passwordHash"] = info.PasswordHash; + auth.Data["passwordSalt"] = info.PasswordSalt; + + if (!m_Database.Store(auth)) + { + m_log.ErrorFormat("[AUTHENTICATION DB]: Failed to store authentication info."); + return false; + } + + m_log.DebugFormat("[AUTHENTICATION DB]: Set authentication info for principalID {0}", info.PrincipalID); + return true; + } protected string GetToken(UUID principalID, int lifetime) { diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs index c04e7a4..2b77154 100644 --- a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs @@ -151,5 +151,17 @@ namespace OpenSim.Services.Connectors // nope, we don't do this return false; } + + public AuthInfo GetAuthInfo(UUID principalID) + { + // not done from remote simulators + return null; + } + + public bool SetAuthInfo(AuthInfo info) + { + // not done from remote simulators + return false; + } } } diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs index 51a09f8..69f6ed2 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs @@ -236,6 +236,16 @@ namespace OpenSim.Services.Connectors.SimianGrid return false; } + public AuthInfo GetAuthInfo(UUID principalID) + { + throw new NotImplementedException(); + } + + public bool SetAuthInfo(AuthInfo info) + { + throw new NotImplementedException(); + } + private bool CheckPassword(UUID userID, string password, string simianGridCredential, out string authorizeResult) { if (simianGridCredential.Contains(":")) diff --git a/OpenSim/Services/Interfaces/IAuthenticationService.cs b/OpenSim/Services/Interfaces/IAuthenticationService.cs index 9de261b..cee8bc0 100644 --- a/OpenSim/Services/Interfaces/IAuthenticationService.cs +++ b/OpenSim/Services/Interfaces/IAuthenticationService.cs @@ -26,10 +26,32 @@ */ using System; +using System.Collections.Generic; using OpenMetaverse; namespace OpenSim.Services.Interfaces { + public class AuthInfo + { + public UUID PrincipalID { get; set; } + public string AccountType { get; set; } + public string PasswordHash { get; set; } + public string PasswordSalt { get; set; } + public string WebLoginKey { get; set; } + + public Dictionary ToKeyValuePairs() + { + Dictionary result = new Dictionary(); + result["PrincipalID"] = PrincipalID; + result["AccountType"] = AccountType; + result["PasswordHash"] = PasswordHash; + result["PasswordSalt"] = PasswordSalt; + result["WebLoginKey"] = WebLoginKey; + + return result; + } + } + // Generic Authentication service used for identifying // and authenticating principals. // Principals may be clients acting on users' behalf, @@ -76,6 +98,10 @@ namespace OpenSim.Services.Interfaces // bool SetPassword(UUID principalID, string passwd); + AuthInfo GetAuthInfo(UUID principalID); + + bool SetAuthInfo(AuthInfo info); + ////////////////////////////////////////////////////// // Grid // -- cgit v1.1