Merge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim
commit
9027d4b490
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace OpenSim.Framework.Servers.HttpServer
|
||||
{
|
||||
public class SynchronousRestFormsRequester
|
||||
{
|
||||
/// <summary>
|
||||
/// Perform a synchronous REST request.
|
||||
/// </summary>
|
||||
/// <param name="verb"></param>
|
||||
/// <param name="requestUrl"></param>
|
||||
/// <param name="obj"> </param>
|
||||
/// <returns></returns>
|
||||
///
|
||||
/// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting
|
||||
/// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
|
||||
public static string MakeRequest(string verb, string requestUrl, string obj)
|
||||
{
|
||||
WebRequest request = WebRequest.Create(requestUrl);
|
||||
request.Method = verb;
|
||||
|
||||
if ((verb == "POST") || (verb == "PUT"))
|
||||
{
|
||||
request.ContentType = "text/www-form-urlencoded";
|
||||
|
||||
MemoryStream buffer = new MemoryStream();
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(buffer))
|
||||
{
|
||||
writer.WriteLine(obj);
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
int length = (int) buffer.Length;
|
||||
request.ContentLength = length;
|
||||
|
||||
Stream requestStream = request.GetRequestStream();
|
||||
requestStream.Write(buffer.ToArray(), 0, length);
|
||||
}
|
||||
|
||||
string respstring = String.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
using (WebResponse resp = request.GetResponse())
|
||||
{
|
||||
if (resp.ContentLength > 0)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
|
||||
{
|
||||
respstring = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.InvalidOperationException)
|
||||
{
|
||||
// This is what happens when there is invalid XML
|
||||
}
|
||||
return respstring;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -183,5 +183,119 @@ namespace OpenSim.Server.Base
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string BuildQueryString(Dictionary<string, string> data)
|
||||
{
|
||||
string qstring = String.Empty;
|
||||
|
||||
foreach(KeyValuePair<string, string> kvp in data)
|
||||
{
|
||||
string part;
|
||||
if (kvp.Value != String.Empty)
|
||||
{
|
||||
part = System.Web.HttpUtility.UrlEncode(kvp.Key) +
|
||||
"=" + System.Web.HttpUtility.UrlEncode(kvp.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
part = System.Web.HttpUtility.UrlEncode(kvp.Key);
|
||||
}
|
||||
|
||||
if (qstring != String.Empty)
|
||||
qstring += "&";
|
||||
|
||||
qstring += part;
|
||||
}
|
||||
|
||||
return qstring;
|
||||
}
|
||||
|
||||
public static string BuildXmlResponse(Dictionary<string, object> data)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
|
||||
XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
|
||||
"", "");
|
||||
|
||||
doc.AppendChild(xmlnode);
|
||||
|
||||
XmlElement rootElement = doc.CreateElement("", "ServerResponse",
|
||||
"");
|
||||
|
||||
doc.AppendChild(rootElement);
|
||||
|
||||
BuildXmlData(rootElement, data);
|
||||
|
||||
return doc.InnerXml;
|
||||
}
|
||||
|
||||
private static void BuildXmlData(XmlElement parent, Dictionary<string, object> data)
|
||||
{
|
||||
foreach (KeyValuePair<string, object> kvp in data)
|
||||
{
|
||||
XmlElement elem = parent.OwnerDocument.CreateElement("",
|
||||
kvp.Key, "");
|
||||
|
||||
if (kvp.Value is Dictionary<string, object>)
|
||||
{
|
||||
XmlAttribute type = parent.OwnerDocument.CreateAttribute("",
|
||||
"type", "");
|
||||
type.Value = "List";
|
||||
|
||||
elem.Attributes.Append(type);
|
||||
|
||||
BuildXmlData(elem, (Dictionary<string, object>)kvp.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
elem.AppendChild(parent.OwnerDocument.CreateTextNode(
|
||||
kvp.Value.ToString()));
|
||||
}
|
||||
|
||||
parent.AppendChild(elem);
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, object> ParseXmlResponse(string data)
|
||||
{
|
||||
Dictionary<string, object> ret = new Dictionary<string, object>();
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
|
||||
doc.LoadXml(data);
|
||||
|
||||
XmlNodeList rootL = doc.GetElementsByTagName("ServerResponse");
|
||||
|
||||
if (rootL.Count != 1)
|
||||
return ret;
|
||||
|
||||
XmlNode rootNode = rootL[0];
|
||||
|
||||
ret = ParseElement(rootNode);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> ParseElement(XmlNode element)
|
||||
{
|
||||
Dictionary<string, object> ret = new Dictionary<string, object>();
|
||||
|
||||
XmlNodeList partL = element.ChildNodes;
|
||||
|
||||
foreach (XmlNode part in partL)
|
||||
{
|
||||
XmlNode type = part.Attributes.GetNamedItem("Type");
|
||||
if (type == null || type.Value != "List")
|
||||
{
|
||||
ret[part.Name] = part.InnerText;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret[part.Name] = ParseElement(part);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ namespace OpenSim.Server.Handlers.Authentication
|
|||
|
||||
doc.AppendChild(xmlnode);
|
||||
|
||||
XmlElement rootElement = doc.CreateElement("", "Authentication",
|
||||
XmlElement rootElement = doc.CreateElement("", "ServerResponse",
|
||||
"");
|
||||
|
||||
doc.AppendChild(rootElement);
|
||||
|
@ -179,7 +179,7 @@ namespace OpenSim.Server.Handlers.Authentication
|
|||
|
||||
doc.AppendChild(xmlnode);
|
||||
|
||||
XmlElement rootElement = doc.CreateElement("", "Authentication",
|
||||
XmlElement rootElement = doc.CreateElement("", "ServerResponse",
|
||||
"");
|
||||
|
||||
doc.AppendChild(rootElement);
|
||||
|
@ -201,7 +201,7 @@ namespace OpenSim.Server.Handlers.Authentication
|
|||
|
||||
doc.AppendChild(xmlnode);
|
||||
|
||||
XmlElement rootElement = doc.CreateElement("", "Authentication",
|
||||
XmlElement rootElement = doc.CreateElement("", "ServerResponse",
|
||||
"");
|
||||
|
||||
doc.AppendChild(rootElement);
|
||||
|
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Communications;
|
||||
using OpenSim.Framework.Servers.HttpServer;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using OpenSim.Server.Base;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace OpenSim.Services.Connectors
|
||||
{
|
||||
public class AuthenticationServicesConnector : IAuthenticationService
|
||||
{
|
||||
private static readonly ILog m_log =
|
||||
LogManager.GetLogger(
|
||||
MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private string m_ServerURI = String.Empty;
|
||||
|
||||
public AuthenticationServicesConnector()
|
||||
{
|
||||
}
|
||||
|
||||
public AuthenticationServicesConnector(string serverURI)
|
||||
{
|
||||
m_ServerURI = serverURI.TrimEnd('/');
|
||||
}
|
||||
|
||||
public AuthenticationServicesConnector(IConfigSource source)
|
||||
{
|
||||
Initialise(source);
|
||||
}
|
||||
|
||||
public virtual void Initialise(IConfigSource source)
|
||||
{
|
||||
IConfig assetConfig = source.Configs["AuthenticationService"];
|
||||
if (assetConfig == null)
|
||||
{
|
||||
m_log.Error("[USER CONNECTOR]: AuthenticationService missing from OpanSim.ini");
|
||||
throw new Exception("Authentication connector init error");
|
||||
}
|
||||
|
||||
string serviceURI = assetConfig.GetString("AuthenticationServerURI",
|
||||
String.Empty);
|
||||
|
||||
if (serviceURI == String.Empty)
|
||||
{
|
||||
m_log.Error("[USER CONNECTOR]: No Server URI named in section AuthenticationService");
|
||||
throw new Exception("Authentication connector init error");
|
||||
}
|
||||
m_ServerURI = serviceURI;
|
||||
}
|
||||
|
||||
public string Authenticate(UUID principalID, string password, int lifetime)
|
||||
{
|
||||
Dictionary<string, string> sendData = new Dictionary<string, string>();
|
||||
sendData["LIFETIME"] = lifetime.ToString();
|
||||
sendData["PRINCIPAL"] = principalID.ToString();
|
||||
sendData["PASSWORD"] = password;
|
||||
|
||||
sendData["METHOD"] = "authenticate";
|
||||
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/auth/plain",
|
||||
ServerUtils.BuildQueryString(sendData));
|
||||
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
|
||||
reply);
|
||||
|
||||
if (replyData["Result"].ToString() != "Success")
|
||||
return String.Empty;
|
||||
|
||||
return replyData["Token"].ToString();
|
||||
}
|
||||
|
||||
public bool Verify(UUID principalID, string token, int lifetime)
|
||||
{
|
||||
Dictionary<string, string> sendData = new Dictionary<string, string>();
|
||||
sendData["LIFETIME"] = lifetime.ToString();
|
||||
sendData["PRINCIPAL"] = principalID.ToString();
|
||||
sendData["TOKEN"] = token;
|
||||
|
||||
sendData["METHOD"] = "verify";
|
||||
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/auth/plain",
|
||||
ServerUtils.BuildQueryString(sendData));
|
||||
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
|
||||
reply);
|
||||
|
||||
if (replyData["Result"].ToString() != "Success")
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Release(UUID principalID, string token)
|
||||
{
|
||||
Dictionary<string, string> sendData = new Dictionary<string, string>();
|
||||
sendData["PRINCIPAL"] = principalID.ToString();
|
||||
sendData["TOKEN"] = token;
|
||||
|
||||
sendData["METHOD"] = "release";
|
||||
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/auth/plain",
|
||||
ServerUtils.BuildQueryString(sendData));
|
||||
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
|
||||
reply);
|
||||
|
||||
if (replyData["Result"].ToString() != "Success")
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
59
prebuild.xml
59
prebuild.xml
|
@ -371,7 +371,6 @@
|
|||
<Reference name="System"/>
|
||||
<Reference name="System.Xml"/>
|
||||
<Reference name="OpenSim.Data"/>
|
||||
<Reference name="OpenSim.Server.Base"/>
|
||||
<Reference name="OpenSim.Framework"/>
|
||||
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
||||
<Reference name="OpenSim.Framework.Console"/>
|
||||
|
@ -1105,6 +1104,35 @@
|
|||
</Files>
|
||||
</Project>
|
||||
|
||||
<Project frameworkVersion="v3_5" name="OpenSim.Server.Base" path="OpenSim/Server/Base" type="Library">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Configuration name="Release">
|
||||
<Options>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
||||
<ReferencePath>../../../bin/</ReferencePath>
|
||||
<Reference name="System"/>
|
||||
<Reference name="System.Xml"/>
|
||||
<Reference name="System.Web"/>
|
||||
<Reference name="OpenMetaverseTypes.dll"/>
|
||||
<Reference name="OpenMetaverse.dll"/>
|
||||
<Reference name="OpenSim.Framework"/>
|
||||
<Reference name="OpenSim.Framework.Console"/>
|
||||
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
||||
<Reference name="Nini.dll" />
|
||||
<Reference name="log4net.dll"/>
|
||||
|
||||
<Files>
|
||||
<Match pattern="*.cs" recurse="true"/>
|
||||
</Files>
|
||||
</Project>
|
||||
|
||||
<Project frameworkVersion="v3_5" name="OpenSim.Services.Base" path="OpenSim/Services/Base" type="Library">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
|
@ -1185,6 +1213,7 @@
|
|||
<Reference name="OpenSim.Framework.Communications"/>
|
||||
<Reference name="OpenSim.Framework.Console"/>
|
||||
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
||||
<Reference name="OpenSim.Server.Base"/>
|
||||
<Reference name="Nini.dll" />
|
||||
<Reference name="log4net.dll"/>
|
||||
<Reference name="XMLRPC.dll" />
|
||||
|
@ -1382,34 +1411,6 @@
|
|||
</Files>
|
||||
</Project>
|
||||
|
||||
<Project frameworkVersion="v3_5" name="OpenSim.Server.Base" path="OpenSim/Server/Base" type="Library">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Configuration name="Release">
|
||||
<Options>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
||||
<ReferencePath>../../../bin/</ReferencePath>
|
||||
<Reference name="System"/>
|
||||
<Reference name="System.Xml"/>
|
||||
<Reference name="System.Web"/>
|
||||
<Reference name="OpenMetaverseTypes.dll"/>
|
||||
<Reference name="OpenMetaverse.dll"/>
|
||||
<Reference name="OpenSim.Framework"/>
|
||||
<Reference name="OpenSim.Framework.Console"/>
|
||||
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
||||
<Reference name="Nini.dll" />
|
||||
<Reference name="log4net.dll"/>
|
||||
|
||||
<Files>
|
||||
<Match pattern="*.cs" recurse="true"/>
|
||||
</Files>
|
||||
</Project>
|
||||
|
||||
<Project frameworkVersion="v3_5" name="OpenSim.Server.Handlers" path="OpenSim/Server/Handlers" type="Library">
|
||||
<Configuration name="Debug">
|
||||
|
|
Loading…
Reference in New Issue