aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs198
1 files changed, 198 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
new file mode 100644
index 0000000..ec66341
--- /dev/null
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
@@ -0,0 +1,198 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Specialized;
30using System.Reflection;
31using log4net;
32using Mono.Addins;
33using Nini.Config;
34using OpenMetaverse;
35using OpenMetaverse.StructuredData;
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Services.Interfaces;
40
41namespace OpenSim.Services.Connectors.SimianGrid
42{
43 /// <summary>
44 /// Connects authentication/authorization to the SimianGrid backend
45 /// </summary>
46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
47 public class SimianAuthenticationServiceConnector : IAuthenticationService, ISharedRegionModule
48 {
49 private static readonly ILog m_log =
50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType);
52
53 private string m_serverUrl = String.Empty;
54
55 #region ISharedRegionModule
56
57 public Type ReplaceableInterface { get { return null; } }
58 public void RegionLoaded(Scene scene) { }
59 public void PostInitialise() { }
60 public void Close() { }
61
62 public SimianAuthenticationServiceConnector() { }
63 public string Name { get { return "SimianAuthenticationServiceConnector"; } }
64 public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IAuthenticationService>(this); }
65 public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IAuthenticationService>(this); }
66
67 #endregion ISharedRegionModule
68
69 public SimianAuthenticationServiceConnector(IConfigSource source)
70 {
71 Initialise(source);
72 }
73
74 public void Initialise(IConfigSource source)
75 {
76 IConfig assetConfig = source.Configs["AuthenticationService"];
77 if (assetConfig == null)
78 {
79 m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini");
80 throw new Exception("Authentication connector init error");
81 }
82
83 string serviceURI = assetConfig.GetString("AuthenticationServerURI");
84 if (String.IsNullOrEmpty(serviceURI))
85 {
86 m_log.Error("[AUTH CONNECTOR]: No Server URI named in section AuthenticationService");
87 throw new Exception("Authentication connector init error");
88 }
89
90 m_serverUrl = serviceURI;
91 }
92
93 public string Authenticate(UUID principalID, string password, int lifetime)
94 {
95 NameValueCollection requestArgs = new NameValueCollection
96 {
97 { "RequestMethod", "GetIdentities" },
98 { "UserID", principalID.ToString() }
99 };
100
101 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
102 if (response["Success"].AsBoolean() && response["Identities"] is OSDArray)
103 {
104 OSDArray identities = (OSDArray)response["Identities"];
105 for (int i = 0; i < identities.Count; i++)
106 {
107 OSDMap identity = identities[i] as OSDMap;
108 if (identity != null)
109 {
110 if (identity["Type"].AsString() == "md5hash")
111 {
112 string credential = identity["Credential"].AsString();
113
114 if (password == credential || Utils.MD5String(password) == credential)
115 return Authorize(principalID);
116 }
117 }
118 }
119
120 m_log.Warn("[AUTH CONNECTOR]: Authentication failed for " + principalID);
121 }
122 else
123 {
124 m_log.Warn("[AUTH CONNECTOR]: Failed to retrieve identities for " + principalID + ": " +
125 response["Message"].AsString());
126 }
127
128 return String.Empty;
129 }
130
131 public bool Verify(UUID principalID, string token, int lifetime)
132 {
133 NameValueCollection requestArgs = new NameValueCollection
134 {
135 { "RequestMethod", "GetSession" },
136 { "SessionID", token }
137 };
138
139 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
140 if (response["Success"].AsBoolean())
141 {
142 return true;
143 }
144 else
145 {
146 m_log.Warn("[AUTH CONNECTOR]: Could not verify session for " + principalID + ": " +
147 response["Message"].AsString());
148 }
149
150 return false;
151 }
152
153 public bool Release(UUID principalID, string token)
154 {
155 NameValueCollection requestArgs = new NameValueCollection
156 {
157 { "RequestMethod", "RemoveSession" },
158 { "UserID", principalID.ToString() }
159 };
160
161 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
162 if (response["Success"].AsBoolean())
163 {
164 return true;
165 }
166 else
167 {
168 m_log.Warn("[AUTH CONNECTOR]: Failed to remove session for " + principalID + ": " +
169 response["Message"].AsString());
170 }
171
172 return false;
173 }
174
175 public bool SetPassword(UUID principalID, string passwd)
176 {
177 // TODO: Use GetIdentities to find the md5hash identity for principalID
178 // and then update it with AddIdentity
179 m_log.Error("[AUTH CONNECTOR]: Changing passwords is not implemented yet");
180 return false;
181 }
182
183 private string Authorize(UUID userID)
184 {
185 NameValueCollection requestArgs = new NameValueCollection
186 {
187 { "RequestMethod", "AddSession" },
188 { "UserID", userID.ToString() }
189 };
190
191 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
192 if (response["Success"].AsBoolean())
193 return response["SessionID"].AsUUID().ToString();
194 else
195 return String.Empty;
196 }
197 }
198}