From 953ef780c5858b70b3b2da551640c93105feb12c Mon Sep 17 00:00:00 2001 From: Rob Smart Date: Thu, 10 Sep 2009 16:13:18 +0100 Subject: adding in working functionality for the remote connector --- .../RemoteAuthorizationServiceConnector.cs | 2 +- .../Authorization/AuthorizationServerGetHandler.cs | 37 ++++++++++++++++++---- .../Authorization/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 5870111..b0d8baa 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 4e4960c..9e4c00e 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(); + + XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, + "", ""); + + doc.AppendChild(xmlnode); - string[] p = SplitParams(path); + XmlElement rootElement = doc.CreateElement("", "Authorization", + ""); - if (p.Length == 0) - return result; + doc.AppendChild(rootElement); - // Process web request + 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 result; + return ms.GetBuffer(); } } } diff --git a/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs b/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs index a0cdc30..151d96a 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 3b8f3a9..10f7dbd 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 -- cgit v1.1