30 using System.Collections.Generic;
32 using System.Reflection;
34 using OpenSim.Framework;
36 using OpenSim.Framework.ServiceAuth;
37 using OpenSim.Server.Base;
38 using OpenSim.Services.Interfaces;
41 namespace OpenSim.Services.Connectors
45 private static readonly ILog m_log =
47 MethodBase.GetCurrentMethod().DeclaringType);
49 private string m_ServerURI = String.Empty;
57 m_ServerURI = serverURI.TrimEnd(
'/');
67 IConfig assetConfig = source.Configs[
"UserAccountService"];
68 if (assetConfig == null)
70 m_log.Error(
"[ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini");
71 throw new Exception(
"User account connector init error");
74 string serviceURI = assetConfig.GetString(
"UserAccountServerURI",
77 if (serviceURI == String.Empty)
79 m_log.Error(
"[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService");
80 throw new Exception(
"User account connector init error");
82 m_ServerURI = serviceURI;
84 base.Initialise(source,
"UserAccountService");
89 Dictionary<string, object> sendData =
new Dictionary<string, object>();
91 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
92 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
93 sendData[
"METHOD"] =
"getaccount";
95 sendData[
"ScopeID"] = scopeID;
96 sendData[
"FirstName"] = firstName.ToString();
97 sendData[
"LastName"] = lastName.ToString();
99 return SendAndGetReply(sendData);
104 Dictionary<string, object> sendData =
new Dictionary<string, object>();
106 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
107 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
108 sendData[
"METHOD"] =
"getaccount";
110 sendData[
"ScopeID"] = scopeID;
111 sendData[
"Email"] = email;
113 return SendAndGetReply(sendData);
119 Dictionary<string, object> sendData =
new Dictionary<string, object>();
121 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
122 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
123 sendData[
"METHOD"] =
"getaccount";
125 sendData[
"ScopeID"] = scopeID;
126 sendData[
"UserID"] = userID.ToString();
128 return SendAndGetReply(sendData);
133 Dictionary<string, object> sendData =
new Dictionary<string, object>();
135 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
136 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
137 sendData[
"METHOD"] =
"getaccounts";
139 sendData[
"ScopeID"] = scopeID.ToString();
140 sendData[
"query"] = query;
142 string reply = string.Empty;
143 string reqString = ServerUtils.BuildQueryString(sendData);
144 string uri = m_ServerURI +
"/accounts";
148 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
152 if (reply == null || (reply != null && reply ==
string.Empty))
154 m_log.DebugFormat(
"[ACCOUNT CONNECTOR]: GetUserAccounts received null or empty reply");
160 m_log.DebugFormat(
"[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
163 List<UserAccount> accounts =
new List<UserAccount>();
165 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
167 if (replyData != null)
169 if (replyData.ContainsKey(
"result") && replyData[
"result"].ToString() ==
"null")
174 Dictionary<string, object>.ValueCollection accountList = replyData.Values;
176 foreach (
object acc
in accountList)
178 if (acc is Dictionary<string, object>)
184 m_log.DebugFormat(
"[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}",
189 m_log.DebugFormat(
"[ACCOUNTS CONNECTOR]: GetUserAccounts received null response");
205 Dictionary<string, object> sendData =
new Dictionary<string, object>();
207 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
208 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
209 sendData[
"METHOD"] =
"setaccount";
211 Dictionary<string, object> structData = data.ToKeyValuePairs();
213 foreach (KeyValuePair<string, object> kvp
in structData)
215 if (kvp.Value == null)
217 m_log.DebugFormat(
"[ACCOUNTS CONNECTOR]: Null value for {0}", kvp.Key);
220 sendData[kvp.Key] = kvp.Value.ToString();
223 if (SendAndGetReply(sendData) != null)
240 Dictionary<string, object> sendData =
new Dictionary<string, object>();
242 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
243 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
244 sendData[
"METHOD"] =
"createuser";
246 sendData[
"FirstName"] = first;
247 sendData[
"LastName"] = last;
248 sendData[
"Password"] = password;
249 if (!
string.IsNullOrEmpty(email))
250 sendData[
"Email"] = first;
251 sendData[
"ScopeID"] = scopeID.ToString();
253 return SendAndGetReply(sendData);
256 private UserAccount SendAndGetReply(Dictionary<string, object> sendData)
258 string reply = string.Empty;
259 string reqString = ServerUtils.BuildQueryString(sendData);
260 string uri = m_ServerURI +
"/accounts";
264 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
268 if (reply == null || (reply != null && reply ==
string.Empty))
270 m_log.DebugFormat(
"[ACCOUNT CONNECTOR]: GetUserAccount received null or empty reply");
276 m_log.DebugFormat(
"[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
279 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
282 if ((replyData != null) && replyData.ContainsKey(
"result") && (replyData[
"result"] != null))
284 if (replyData[
"result"] is Dictionary<string, object>)
286 account =
new UserAccount((Dictionary<string, object>)replyData[
"result"]);
294 private bool SendAndGetBoolReply(Dictionary<string, object> sendData)
296 string reqString = ServerUtils.BuildQueryString(sendData);
297 string uri = m_ServerURI +
"/accounts";
301 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
305 if (reply !=
string.Empty)
308 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
310 if (replyData.ContainsKey(
"result"))
312 if (replyData[
"result"].ToString().ToLower() ==
"success")
318 m_log.DebugFormat(
"[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field");
322 m_log.DebugFormat(
"[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply");
326 m_log.DebugFormat(
"[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message);
virtual void Initialise(IConfigSource source)
List< UserAccount > GetUserAccountsWhere(UUID scopeID, string where)
UserAccountServicesConnector(IConfigSource source)
virtual bool StoreUserAccount(UserAccount data)
Store the data given, wich replaces the stored data, therefore must be complete.
List< UserAccount > GetUserAccounts(UUID scopeID, string query)
Returns the list of avatars that matches both the search criterion and the scope ID passed ...
virtual UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
void InvalidateCache(UUID userID)
virtual UserAccount GetUserAccount(UUID scopeID, string email)
UserAccountServicesConnector(string serverURI)
virtual UserAccount GetUserAccount(UUID scopeID, UUID userID)
virtual UserAccount CreateUser(string first, string last, string password, string email, UUID scopeID)
Create user remotely. Note this this is not part of the IUserAccountsService
UserAccountServicesConnector()