29 using System.Collections.Specialized;
30 using System.Reflection;
35 using OpenMetaverse.StructuredData;
36 using OpenSim.Framework;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
41 namespace OpenSim.Services.Connectors.SimianGrid
46 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"SimianAuthenticationServiceConnector")]
49 private static readonly ILog m_log =
51 MethodBase.GetCurrentMethod().DeclaringType);
53 private string m_serverUrl = String.Empty;
54 private bool m_Enabled =
false;
56 #region ISharedRegionModule
58 public Type ReplaceableInterface {
get {
return null; } }
64 public string Name {
get {
return "SimianAuthenticationServiceConnector"; } }
68 #endregion ISharedRegionModule
77 IConfig moduleConfig = source.Configs[
"Modules"];
78 if (moduleConfig != null)
80 string name = moduleConfig.GetString(
"AuthenticationServices",
"");
86 private void CommonInit(IConfigSource source)
88 IConfig gridConfig = source.Configs[
"AuthenticationService"];
89 if (gridConfig != null)
91 string serviceUrl = gridConfig.GetString(
"AuthenticationServerURI");
92 if (!
String.IsNullOrEmpty(serviceUrl))
94 if (!serviceUrl.EndsWith(
"/") && !serviceUrl.EndsWith(
"="))
95 serviceUrl = serviceUrl +
'/';
96 m_serverUrl = serviceUrl;
101 if (
String.IsNullOrEmpty(m_serverUrl))
102 m_log.Info(
"[SIMIAN AUTH CONNECTOR]: No AuthenticationServerURI specified, disabling connector");
105 public string Authenticate(UUID principalID,
string password,
int lifetime, out UUID realID)
111 public string Authenticate(UUID principalID,
string password,
int lifetime)
113 NameValueCollection requestArgs =
new NameValueCollection
115 {
"RequestMethod",
"GetIdentities" },
116 {
"UserID", principalID.ToString() }
119 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
120 if (response[
"Success"].AsBoolean() && response[
"Identities"] is
OSDArray)
122 bool md5hashFound =
false;
125 for (
int i = 0; i < identities.Count; i++)
128 if (identity != null)
130 if (identity[
"Type"].AsString() ==
"md5hash")
132 string authorizeResult;
133 if (CheckPassword(principalID, password, identity[
"Credential"].AsString(), out authorizeResult))
134 return authorizeResult;
143 m_log.Warn(
"[SIMIAN AUTH CONNECTOR]: Authentication failed for " + principalID +
", no md5hash identity found");
147 m_log.Warn(
"[SIMIAN AUTH CONNECTOR]: Failed to retrieve identities for " + principalID +
": " +
148 response[
"Message"].AsString());
154 public bool Verify(UUID principalID,
string token,
int lifetime)
156 NameValueCollection requestArgs =
new NameValueCollection
158 {
"RequestMethod",
"GetSession" },
159 {
"SessionID", token }
162 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
163 if (response[
"Success"].AsBoolean())
169 m_log.Warn(
"[SIMIAN AUTH CONNECTOR]: Could not verify session for " + principalID +
": " +
170 response[
"Message"].AsString());
176 public bool Release(UUID principalID,
string token)
178 NameValueCollection requestArgs =
new NameValueCollection
180 {
"RequestMethod",
"RemoveSession" },
181 {
"UserID", principalID.ToString() }
184 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
185 if (response[
"Success"].AsBoolean())
191 m_log.Warn(
"[SIMIAN AUTH CONNECTOR]: Failed to remove session for " + principalID +
": " +
192 response[
"Message"].AsString());
201 NameValueCollection requestArgs =
new NameValueCollection
203 {
"RequestMethod",
"GetUser" },
204 {
"UserID", principalID.ToString() }
207 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
208 if (response[
"Success"].AsBoolean() && response[
"User"] is
OSDMap)
211 string identifier = userMap[
"Name"].AsString();
213 if (!
String.IsNullOrEmpty(identifier))
218 requestArgs =
new NameValueCollection
220 {
"RequestMethod",
"AddIdentity" },
221 {
"Identifier", identifier },
222 {
"Credential",
"$1$" + Utils.MD5String(passwd) },
223 {
"Type",
"md5hash" },
224 {
"UserID", principalID.ToString() }
227 response = SimianGrid.PostToService(m_serverUrl, requestArgs);
228 bool success = response[
"Success"].AsBoolean();
231 m_log.WarnFormat(
"[SIMIAN AUTH CONNECTOR]: Failed to set password for {0} ({1})", identifier, principalID);
238 m_log.Warn(
"[SIMIAN AUTH CONNECTOR]: Failed to retrieve identities for " + principalID +
": " +
239 response[
"Message"].AsString());
247 throw new NotImplementedException();
252 throw new NotImplementedException();
255 private bool CheckPassword(UUID userID,
string password,
string simianGridCredential, out
string authorizeResult)
257 if (simianGridCredential.Contains(
":"))
260 int idx = simianGridCredential.IndexOf(
':');
261 string finalhash = simianGridCredential.Substring(0, idx);
262 string salt = simianGridCredential.Substring(idx + 1);
264 if (finalhash ==
Utils.MD5String(password +
":" + salt))
266 authorizeResult = Authorize(userID);
271 m_log.Warn(
"[SIMIAN AUTH CONNECTOR]: Authentication failed for " + userID +
272 " using md5hash " + Utils.MD5String(password) +
":" + salt);
278 if (password == simianGridCredential ||
279 "$1$" + password == simianGridCredential ||
280 "$1$" +
Utils.MD5String(password) == simianGridCredential ||
281 Utils.MD5String(password) == simianGridCredential ||
282 "$1$" +
Utils.MD5String(password +
":") == simianGridCredential)
284 authorizeResult = Authorize(userID);
289 m_log.Warn(
"[SIMIAN AUTH CONNECTOR]: Authentication failed for " + userID +
290 " using md5hash $1$" + Utils.MD5String(password));
294 authorizeResult = null;
298 private string Authorize(UUID userID)
300 NameValueCollection requestArgs =
new NameValueCollection
302 {
"RequestMethod",
"AddSession" },
303 {
"UserID", userID.ToString() }
306 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
307 if (response[
"Success"].AsBoolean())
308 return response[
"SessionID"].AsUUID().ToString();
Connects authentication/authorization to the SimianGrid backend
OpenMetaverse.StructuredData.OSDArray OSDArray
OpenSim.Server.Handlers.Simulation.Utils Utils
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
SimianAuthenticationServiceConnector(IConfigSource source)
OpenMetaverse.StructuredData.OSDMap OSDMap
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
bool Verify(UUID principalID, string token, int lifetime)
SimianAuthenticationServiceConnector()
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
string Authenticate(UUID principalID, string password, int lifetime)
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
bool SetAuthInfo(AuthInfo info)
bool Release(UUID principalID, string token)
AuthInfo GetAuthInfo(UUID principalID)
bool SetPassword(UUID principalID, string passwd)
string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...