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 --- .../AuthenticationServerPostHandler.cs | 74 +++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Authentication') diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs index ae71945..4d1b0ff 100644 --- a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs @@ -46,9 +46,12 @@ namespace OpenSim.Server.Handlers.Authentication { public class AuthenticationServerPostHandler : BaseStreamHandler { - // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAuthenticationService m_AuthenticationService; + + private bool m_AllowGetAuthInfo = false; + private bool m_AllowSetAuthInfo = false; private bool m_AllowSetPassword = false; public AuthenticationServerPostHandler(IAuthenticationService service) : @@ -61,6 +64,8 @@ namespace OpenSim.Server.Handlers.Authentication if (config != null) { + m_AllowGetAuthInfo = config.GetBoolean("AllowGetAuthInfo", m_AllowGetAuthInfo); + m_AllowSetAuthInfo = config.GetBoolean("AllowSetAuthInfo", m_AllowSetAuthInfo); m_AllowSetPassword = config.GetBoolean("AllowSetPassword", m_AllowSetPassword); } } @@ -161,6 +166,18 @@ namespace OpenSim.Server.Handlers.Authentication return SuccessResult(); return FailureResult(); + + case "getauthinfo": + if (m_AllowGetAuthInfo) + return GetAuthInfo(principalID); + + break; + + case "setauthinfo": + if (m_AllowSetAuthInfo) + return SetAuthInfo(principalID, request); + + break; } return FailureResult(); @@ -193,6 +210,54 @@ namespace OpenSim.Server.Handlers.Authentication return DocToBytes(doc); } + byte[] GetAuthInfo(UUID principalID) + { + AuthInfo info = m_AuthenticationService.GetAuthInfo(principalID); + + if (info != null) + { + Dictionary result = new Dictionary(); + result["result"] = info.ToKeyValuePairs(); + + return ResultToBytes(result); + } + else + { + return FailureResult(); + } + } + + byte[] SetAuthInfo(UUID principalID, Dictionary request) + { + AuthInfo existingInfo = m_AuthenticationService.GetAuthInfo(principalID); + + if (existingInfo == null) + return FailureResult(); + + if (request.ContainsKey("AccountType")) + existingInfo.AccountType = request["AccountType"].ToString(); + + if (request.ContainsKey("PasswordHash")) + existingInfo.PasswordHash = request["PasswordHash"].ToString(); + + if (request.ContainsKey("PasswordSalt")) + existingInfo.PasswordSalt = request["PasswordSalt"].ToString(); + + if (request.ContainsKey("WebLoginKey")) + existingInfo.WebLoginKey = request["WebLoginKey"].ToString(); + + if (!m_AuthenticationService.SetAuthInfo(existingInfo)) + { + m_log.ErrorFormat( + "[AUTHENTICATION SERVER POST HANDLER]: Authentication info store failed for account {0} {1} {2}", + existingInfo.PrincipalID); + + return FailureResult(); + } + + return SuccessResult(); + } + private byte[] FailureResult() { XmlDocument doc = new XmlDocument(); @@ -252,5 +317,12 @@ namespace OpenSim.Server.Handlers.Authentication return ms.GetBuffer(); } + + private byte[] ResultToBytes(Dictionary result) + { + string xmlString = ServerUtils.BuildXmlResponse(result); + UTF8Encoding encoding = new UTF8Encoding(); + return encoding.GetBytes(xmlString); + } } } -- cgit v1.1