From 953ef780c5858b70b3b2da551640c93105feb12c Mon Sep 17 00:00:00 2001 From: Rob Smart Date: Thu, 10 Sep 2009 16:13:18 +0100 Subject: [PATCH] adding in working functionality for the remote connector --- .../RemoteAuthorizationServiceConnector.cs | 2 +- .../AuthorizationServerGetHandler.cs | 37 ++++++++++++++++--- .../AuthorizationServiceConnector.cs | 36 ++++++++++++++++-- bin/config-include/Grid.ini | 1 + 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs index 587011108b..b0d8baaaa7 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs @@ -76,7 +76,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization base.Initialise(source); - m_log.Info("[AUTHORIZATION CONNECTOR]: Remote assets enabled"); + m_log.Info("[AUTHORIZATION CONNECTOR]: Remote authorization enabled"); } } } diff --git a/OpenSim/Server/Handlers/Authorization/AuthorizationServerGetHandler.cs b/OpenSim/Server/Handlers/Authorization/AuthorizationServerGetHandler.cs index 4e4960cd32..9e4c00e572 100644 --- a/OpenSim/Server/Handlers/Authorization/AuthorizationServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Authorization/AuthorizationServerGetHandler.cs @@ -55,16 +55,41 @@ namespace OpenSim.Server.Handlers.Authorization public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { - byte[] result = new byte[0]; + // always return success for now, this is just stub functionality + return SuccessResult(); + } + + private byte[] SuccessResult() + { + XmlDocument doc = new XmlDocument(); - string[] p = SplitParams(path); + XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, + "", ""); - if (p.Length == 0) - return result; + doc.AppendChild(xmlnode); - // Process web request + XmlElement rootElement = doc.CreateElement("", "Authorization", + ""); - return result; + doc.AppendChild(rootElement); + + XmlElement result = doc.CreateElement("", "Result", ""); + result.AppendChild(doc.CreateTextNode("success")); + + rootElement.AppendChild(result); + + return DocToBytes(doc); + } + + private byte[] DocToBytes(XmlDocument doc) + { + MemoryStream ms = new MemoryStream(); + XmlTextWriter xw = new XmlTextWriter(ms, null); + xw.Formatting = Formatting.Indented; + doc.WriteTo(xw); + xw.Flush(); + + return ms.GetBuffer(); } } } diff --git a/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs b/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs index a0cdc30983..151d96a2e2 100644 --- a/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs @@ -46,6 +46,7 @@ namespace OpenSim.Services.Connectors MethodBase.GetCurrentMethod().DeclaringType); private string m_ServerURI = String.Empty; + private bool m_ResponseOnFailure = true; public AuthorizationServicesConnector() { @@ -66,7 +67,7 @@ namespace OpenSim.Services.Connectors IConfig authorizationConfig = source.Configs["AuthorizationService"]; if (authorizationConfig == null) { - m_log.Error("[AUTHORIZATION CONNECTOR]: AuthorizationService missing from OpanSim.ini"); + m_log.Error("[AUTHORIZATION CONNECTOR]: AuthorizationService missing from OpenSim.ini"); throw new Exception("Authorization connector init error"); } @@ -75,16 +76,43 @@ namespace OpenSim.Services.Connectors if (serviceURI == String.Empty) { - m_log.Error("[AUTHORIZATION CONNECTOR]: No Server URI named in section AssetService"); + m_log.Error("[AUTHORIZATION CONNECTOR]: No Server URI named in section AuthorizationService"); throw new Exception("Authorization connector init error"); } m_ServerURI = serviceURI; + + // this dictates what happens if the remote service fails, if the service fails and the value is true + // the user is authorized for the region. + bool responseOnFailure = authorizationConfig.GetBoolean("ResponseOnFailure",true); + + m_ResponseOnFailure = responseOnFailure; } public bool isAuthorizedForRegion(UserProfileData user, RegionInfo region) { - // call remote service - return true; + // this should be a remote call to the authorization server specified in the AuthorizationServerURI + m_log.Info("[AUTHORIZATION CONNECTOR]: isAuthorizedForRegion is not yet implemented. Returning true, the user is authorized "); + + string uri = m_ServerURI + "?uuid="+user.ID + "&firstname="+user.FirstName+"&lastname="+user.SurName+"®ion="+region.RegionName+"®ionid="+region.RegionID+"&email="+user.Email; + + string result = string.Empty; + + try + { + result = SynchronousRestObjectRequester. + MakeRequest("POST", uri, user); + } + catch (Exception e) + { + m_log.WarnFormat("[AUTHORIZATION CONNECTOR]: Unable to send authorize {0} {1} for region {2} error thrown during comms with remote server. Reason: {3}", user.FirstName,user.SurName,region.RegionName, e.Message); + return m_ResponseOnFailure; + } + + m_log.DebugFormat("[AUTHORIZATION CONNECTOR] response from remote service was {0}",result); + if(result.Contains("success")) + return true; + else + return false; } } diff --git a/bin/config-include/Grid.ini b/bin/config-include/Grid.ini index 3b8f3a9737..10f7dbdb28 100644 --- a/bin/config-include/Grid.ini +++ b/bin/config-include/Grid.ini @@ -10,6 +10,7 @@ [Modules] AssetServices = "RemoteAssetServicesConnector" InventoryServices = "RemoteInventoryServicesConnector" + AuthorizationServices = "RemoteAuthorizationServicesConnector" NeighbourServices = "RemoteNeighbourServicesConnector" NeighbourServiceInConnector = true LandServiceInConnector = true