aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
authorDiva Canto2009-09-20 08:32:51 -0700
committerDiva Canto2009-09-20 08:32:51 -0700
commit9027d4b490fcc6e806cb8b49f7d89ed317df0950 (patch)
tree44dff73fa1bb38ea42aa8f79bb9f2792eab23fb4 /OpenSim/Services
parentMerge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff)
parentFinish the (untested) authentication connector (diff)
downloadopensim-SC-9027d4b490fcc6e806cb8b49f7d89ed317df0950.zip
opensim-SC-9027d4b490fcc6e806cb8b49f7d89ed317df0950.tar.gz
opensim-SC-9027d4b490fcc6e806cb8b49f7d89ed317df0950.tar.bz2
opensim-SC-9027d4b490fcc6e806cb8b49f7d89ed317df0950.tar.xz
Merge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Services')
-rw-r--r--OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs150
1 files changed, 150 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs
new file mode 100644
index 0000000..50e817e
--- /dev/null
+++ b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs
@@ -0,0 +1,150 @@
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 log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using OpenSim.Server.Base;
39using OpenMetaverse;
40
41namespace OpenSim.Services.Connectors
42{
43 public class AuthenticationServicesConnector : IAuthenticationService
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType);
48
49 private string m_ServerURI = String.Empty;
50
51 public AuthenticationServicesConnector()
52 {
53 }
54
55 public AuthenticationServicesConnector(string serverURI)
56 {
57 m_ServerURI = serverURI.TrimEnd('/');
58 }
59
60 public AuthenticationServicesConnector(IConfigSource source)
61 {
62 Initialise(source);
63 }
64
65 public virtual void Initialise(IConfigSource source)
66 {
67 IConfig assetConfig = source.Configs["AuthenticationService"];
68 if (assetConfig == null)
69 {
70 m_log.Error("[USER CONNECTOR]: AuthenticationService missing from OpanSim.ini");
71 throw new Exception("Authentication connector init error");
72 }
73
74 string serviceURI = assetConfig.GetString("AuthenticationServerURI",
75 String.Empty);
76
77 if (serviceURI == String.Empty)
78 {
79 m_log.Error("[USER CONNECTOR]: No Server URI named in section AuthenticationService");
80 throw new Exception("Authentication connector init error");
81 }
82 m_ServerURI = serviceURI;
83 }
84
85 public string Authenticate(UUID principalID, string password, int lifetime)
86 {
87 Dictionary<string, string> sendData = new Dictionary<string, string>();
88 sendData["LIFETIME"] = lifetime.ToString();
89 sendData["PRINCIPAL"] = principalID.ToString();
90 sendData["PASSWORD"] = password;
91
92 sendData["METHOD"] = "authenticate";
93
94 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
95 m_ServerURI + "/auth/plain",
96 ServerUtils.BuildQueryString(sendData));
97
98 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
99 reply);
100
101 if (replyData["Result"].ToString() != "Success")
102 return String.Empty;
103
104 return replyData["Token"].ToString();
105 }
106
107 public bool Verify(UUID principalID, string token, int lifetime)
108 {
109 Dictionary<string, string> sendData = new Dictionary<string, string>();
110 sendData["LIFETIME"] = lifetime.ToString();
111 sendData["PRINCIPAL"] = principalID.ToString();
112 sendData["TOKEN"] = token;
113
114 sendData["METHOD"] = "verify";
115
116 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
117 m_ServerURI + "/auth/plain",
118 ServerUtils.BuildQueryString(sendData));
119
120 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
121 reply);
122
123 if (replyData["Result"].ToString() != "Success")
124 return false;
125
126 return true;
127 }
128
129 public bool Release(UUID principalID, string token)
130 {
131 Dictionary<string, string> sendData = new Dictionary<string, string>();
132 sendData["PRINCIPAL"] = principalID.ToString();
133 sendData["TOKEN"] = token;
134
135 sendData["METHOD"] = "release";
136
137 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
138 m_ServerURI + "/auth/plain",
139 ServerUtils.BuildQueryString(sendData));
140
141 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
142 reply);
143
144 if (replyData["Result"].ToString() != "Success")
145 return false;
146
147 return true;
148 }
149 }
150}