clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using log4net;
29 using System;
30 using System.Collections.Generic;
31 using System.IO;
32 using System.Reflection;
33 using Nini.Config;
34 using OpenSim.Framework;
35 using OpenSim.Framework.ServiceAuth;
36 using OpenSim.Services.Interfaces;
37 using OpenSim.Server.Base;
38 using OpenMetaverse;
39  
40 namespace OpenSim.Services.Connectors
41 {
42 public class AuthenticationServicesConnector : BaseServiceConnector, IAuthenticationService
43 {
44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
47  
48 private string m_ServerURI = String.Empty;
49  
50 public AuthenticationServicesConnector()
51 {
52 }
53  
54 public AuthenticationServicesConnector(string serverURI)
55 {
56 m_ServerURI = serverURI.TrimEnd('/');
57 }
58  
59 public AuthenticationServicesConnector(IConfigSource source)
60 : base(source, "AuthenticationService")
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("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.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("[AUTH CONNECTOR]: No Server URI named in section AuthenticationService");
80 throw new Exception("Authentication connector init error");
81 }
82 m_ServerURI = serviceURI;
83  
84 base.Initialise(source, "AuthenticationService");
85 }
86  
87 public string Authenticate(UUID principalID, string password, int lifetime)
88 {
89 Dictionary<string, object> sendData = new Dictionary<string, object>();
90 sendData["LIFETIME"] = lifetime.ToString();
91 sendData["PRINCIPAL"] = principalID.ToString();
92 sendData["PASSWORD"] = password;
93  
94 sendData["METHOD"] = "authenticate";
95  
96 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
97 m_ServerURI + "/auth/plain",
98 ServerUtils.BuildQueryString(sendData), m_Auth);
99  
100 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
101 reply);
102  
103 if (replyData["Result"].ToString() != "Success")
104 return String.Empty;
105  
106 return replyData["Token"].ToString();
107 }
108  
109 public bool Verify(UUID principalID, string token, int lifetime)
110 {
111 // m_log.Error("[XXX]: Verify");
112 Dictionary<string, object> sendData = new Dictionary<string, object>();
113 sendData["LIFETIME"] = lifetime.ToString();
114 sendData["PRINCIPAL"] = principalID.ToString();
115 sendData["TOKEN"] = token;
116  
117 sendData["METHOD"] = "verify";
118  
119 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
120 m_ServerURI + "/auth/plain",
121 ServerUtils.BuildQueryString(sendData), m_Auth);
122  
123 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
124 reply);
125  
126 if (replyData["Result"].ToString() != "Success")
127 return false;
128  
129 return true;
130 }
131  
132 public bool Release(UUID principalID, string token)
133 {
134 Dictionary<string, object> sendData = new Dictionary<string, object>();
135 sendData["PRINCIPAL"] = principalID.ToString();
136 sendData["TOKEN"] = token;
137  
138 sendData["METHOD"] = "release";
139  
140 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
141 m_ServerURI + "/auth/plain",
142 ServerUtils.BuildQueryString(sendData), m_Auth);
143  
144 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
145 reply);
146  
147 if (replyData["Result"].ToString() != "Success")
148 return false;
149  
150 return true;
151 }
152  
153 public bool SetPassword(UUID principalID, string passwd)
154 {
155 // nope, we don't do this
156 return false;
157 }
158  
159 public AuthInfo GetAuthInfo(UUID principalID)
160 {
161 // not done from remote simulators
162 return null;
163 }
164  
165 public bool SetAuthInfo(AuthInfo info)
166 {
167 // not done from remote simulators
168 return false;
169 }
170 }
171 }