aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
diff options
context:
space:
mode:
authorMelanie2010-03-15 17:23:35 +0000
committerMelanie2010-03-15 17:23:35 +0000
commitd3f33acc1a6a385ee19814286fe27cb5e48c1551 (patch)
tree07795e74a637ca63d96b5ee06950b8c1a7a99489 /OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
parentMerge branch 'careminster' into careminster-presence-refactor (diff)
parentflip UVs for profile faces (diff)
downloadopensim-SC_OLD-d3f33acc1a6a385ee19814286fe27cb5e48c1551.zip
opensim-SC_OLD-d3f33acc1a6a385ee19814286fe27cb5e48c1551.tar.gz
opensim-SC_OLD-d3f33acc1a6a385ee19814286fe27cb5e48c1551.tar.bz2
opensim-SC_OLD-d3f33acc1a6a385ee19814286fe27cb5e48c1551.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs201
1 files changed, 201 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..6317b87
--- /dev/null
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianAuthenticationServiceConnector.cs
@@ -0,0 +1,201 @@
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) { if (!String.IsNullOrEmpty(m_serverUrl)) { scene.RegisterModuleInterface<IAuthenticationService>(this); } }
65 public void RemoveRegion(Scene scene) { if (!String.IsNullOrEmpty(m_serverUrl)) { 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 if (Simian.IsSimianEnabled(source, "AuthenticationServices"))
77 {
78 IConfig assetConfig = source.Configs["AuthenticationService"];
79 if (assetConfig == null)
80 {
81 m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini");
82 throw new Exception("Authentication connector init error");
83 }
84
85 string serviceURI = assetConfig.GetString("AuthenticationServerURI");
86 if (String.IsNullOrEmpty(serviceURI))
87 {
88 m_log.Error("[AUTH CONNECTOR]: No Server URI named in section AuthenticationService");
89 throw new Exception("Authentication connector init error");
90 }
91
92 m_serverUrl = serviceURI;
93 }
94 }
95
96 public string Authenticate(UUID principalID, string password, int lifetime)
97 {
98 NameValueCollection requestArgs = new NameValueCollection
99 {
100 { "RequestMethod", "GetIdentities" },
101 { "UserID", principalID.ToString() }
102 };
103
104 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
105 if (response["Success"].AsBoolean() && response["Identities"] is OSDArray)
106 {
107 OSDArray identities = (OSDArray)response["Identities"];
108 for (int i = 0; i < identities.Count; i++)
109 {
110 OSDMap identity = identities[i] as OSDMap;
111 if (identity != null)
112 {
113 if (identity["Type"].AsString() == "md5hash")
114 {
115 string credential = identity["Credential"].AsString();
116
117 if (password == credential || Utils.MD5String(password) == credential)
118 return Authorize(principalID);
119 }
120 }
121 }
122
123 m_log.Warn("[AUTH CONNECTOR]: Authentication failed for " + principalID);
124 }
125 else
126 {
127 m_log.Warn("[AUTH CONNECTOR]: Failed to retrieve identities for " + principalID + ": " +
128 response["Message"].AsString());
129 }
130
131 return String.Empty;
132 }
133
134 public bool Verify(UUID principalID, string token, int lifetime)
135 {
136 NameValueCollection requestArgs = new NameValueCollection
137 {
138 { "RequestMethod", "GetSession" },
139 { "SessionID", token }
140 };
141
142 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
143 if (response["Success"].AsBoolean())
144 {
145 return true;
146 }
147 else
148 {
149 m_log.Warn("[AUTH CONNECTOR]: Could not verify session for " + principalID + ": " +
150 response["Message"].AsString());
151 }
152
153 return false;
154 }
155
156 public bool Release(UUID principalID, string token)
157 {
158 NameValueCollection requestArgs = new NameValueCollection
159 {
160 { "RequestMethod", "RemoveSession" },
161 { "UserID", principalID.ToString() }
162 };
163
164 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
165 if (response["Success"].AsBoolean())
166 {
167 return true;
168 }
169 else
170 {
171 m_log.Warn("[AUTH CONNECTOR]: Failed to remove session for " + principalID + ": " +
172 response["Message"].AsString());
173 }
174
175 return false;
176 }
177
178 public bool SetPassword(UUID principalID, string passwd)
179 {
180 // TODO: Use GetIdentities to find the md5hash identity for principalID
181 // and then update it with AddIdentity
182 m_log.Error("[AUTH CONNECTOR]: Changing passwords is not implemented yet");
183 return false;
184 }
185
186 private string Authorize(UUID userID)
187 {
188 NameValueCollection requestArgs = new NameValueCollection
189 {
190 { "RequestMethod", "AddSession" },
191 { "UserID", userID.ToString() }
192 };
193
194 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
195 if (response["Success"].AsBoolean())
196 return response["SessionID"].AsUUID().ToString();
197 else
198 return String.Empty;
199 }
200 }
201}