mirror of
https://github.com/opensim/opensim.git
synced 2026-08-09 02:36:00 +08:00
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
This commit is contained in:
@@ -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<string, object> result = new Dictionary<string, object>();
|
||||
result["result"] = info.ToKeyValuePairs();
|
||||
|
||||
return ResultToBytes(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FailureResult();
|
||||
}
|
||||
}
|
||||
|
||||
byte[] SetAuthInfo(UUID principalID, Dictionary<string, object> 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<string, object> result)
|
||||
{
|
||||
string xmlString = ServerUtils.BuildXmlResponse(result);
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
return encoding.GetBytes(xmlString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,7 +356,5 @@ namespace OpenSim.Server.Handlers.UserAccounts
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
return encoding.GetBytes(xmlString);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user