diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Services/AuthenticationService | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to '')
5 files changed, 501 insertions, 0 deletions
diff --git a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs new file mode 100644 index 0000000..229f557 --- /dev/null +++ b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs | |||
@@ -0,0 +1,186 @@ | |||
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 System; | ||
29 | using OpenMetaverse; | ||
30 | using log4net; | ||
31 | using Nini.Config; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Data; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Services.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
38 | namespace OpenSim.Services.AuthenticationService | ||
39 | { | ||
40 | // Generic Authentication service used for identifying | ||
41 | // and authenticating principals. | ||
42 | // Principals may be clients acting on users' behalf, | ||
43 | // or any other components that need | ||
44 | // verifiable identification. | ||
45 | // | ||
46 | public class AuthenticationServiceBase : ServiceBase | ||
47 | { | ||
48 | private static readonly ILog m_log = | ||
49 | LogManager.GetLogger( | ||
50 | MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | protected IAuthenticationData m_Database; | ||
53 | |||
54 | public AuthenticationServiceBase(IConfigSource config) : base(config) | ||
55 | { | ||
56 | string dllName = String.Empty; | ||
57 | string connString = String.Empty; | ||
58 | string realm = "auth"; | ||
59 | |||
60 | // | ||
61 | // Try reading the [AuthenticationService] section first, if it exists | ||
62 | // | ||
63 | IConfig authConfig = config.Configs["AuthenticationService"]; | ||
64 | if (authConfig != null) | ||
65 | { | ||
66 | dllName = authConfig.GetString("StorageProvider", dllName); | ||
67 | connString = authConfig.GetString("ConnectionString", connString); | ||
68 | realm = authConfig.GetString("Realm", realm); | ||
69 | } | ||
70 | |||
71 | // | ||
72 | // Try reading the [DatabaseService] section, if it exists | ||
73 | // | ||
74 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
75 | if (dbConfig != null) | ||
76 | { | ||
77 | if (dllName == String.Empty) | ||
78 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
79 | if (connString == String.Empty) | ||
80 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
81 | } | ||
82 | |||
83 | // | ||
84 | // We tried, but this doesn't exist. We can't proceed. | ||
85 | // | ||
86 | if (dllName == String.Empty || realm == String.Empty) | ||
87 | throw new Exception("No StorageProvider configured"); | ||
88 | |||
89 | m_Database = LoadPlugin<IAuthenticationData>(dllName, | ||
90 | new Object[] {connString, realm}); | ||
91 | if (m_Database == null) | ||
92 | throw new Exception(string.Format("Could not find a storage interface in module {0}", dllName)); | ||
93 | } | ||
94 | |||
95 | public bool Verify(UUID principalID, string token, int lifetime) | ||
96 | { | ||
97 | return m_Database.CheckToken(principalID, token, lifetime); | ||
98 | } | ||
99 | |||
100 | public virtual bool Release(UUID principalID, string token) | ||
101 | { | ||
102 | return m_Database.CheckToken(principalID, token, 0); | ||
103 | } | ||
104 | |||
105 | public virtual bool SetPassword(UUID principalID, string password) | ||
106 | { | ||
107 | string passwordSalt = Util.Md5Hash(UUID.Random().ToString()); | ||
108 | string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + passwordSalt); | ||
109 | |||
110 | AuthenticationData auth = m_Database.Get(principalID); | ||
111 | if (auth == null) | ||
112 | { | ||
113 | auth = new AuthenticationData(); | ||
114 | auth.PrincipalID = principalID; | ||
115 | auth.Data = new System.Collections.Generic.Dictionary<string, object>(); | ||
116 | auth.Data["accountType"] = "UserAccount"; | ||
117 | auth.Data["webLoginKey"] = UUID.Zero.ToString(); | ||
118 | } | ||
119 | auth.Data["passwordHash"] = md5PasswdHash; | ||
120 | auth.Data["passwordSalt"] = passwordSalt; | ||
121 | if (!m_Database.Store(auth)) | ||
122 | { | ||
123 | m_log.DebugFormat("[AUTHENTICATION DB]: Failed to store authentication data"); | ||
124 | return false; | ||
125 | } | ||
126 | |||
127 | m_log.InfoFormat("[AUTHENTICATION DB]: Set password for principalID {0}", principalID); | ||
128 | return true; | ||
129 | } | ||
130 | |||
131 | public virtual AuthInfo GetAuthInfo(UUID principalID) | ||
132 | { | ||
133 | AuthenticationData data = m_Database.Get(principalID); | ||
134 | |||
135 | if (data == null) | ||
136 | { | ||
137 | return null; | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | AuthInfo info | ||
142 | = new AuthInfo() | ||
143 | { | ||
144 | PrincipalID = data.PrincipalID, | ||
145 | AccountType = data.Data["accountType"] as string, | ||
146 | PasswordHash = data.Data["passwordHash"] as string, | ||
147 | PasswordSalt = data.Data["passwordSalt"] as string, | ||
148 | WebLoginKey = data.Data["webLoginKey"] as string | ||
149 | }; | ||
150 | |||
151 | return info; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | public virtual bool SetAuthInfo(AuthInfo info) | ||
156 | { | ||
157 | AuthenticationData auth = new AuthenticationData(); | ||
158 | auth.PrincipalID = info.PrincipalID; | ||
159 | auth.Data = new System.Collections.Generic.Dictionary<string, object>(); | ||
160 | auth.Data["accountType"] = info.AccountType; | ||
161 | auth.Data["webLoginKey"] = info.WebLoginKey; | ||
162 | auth.Data["passwordHash"] = info.PasswordHash; | ||
163 | auth.Data["passwordSalt"] = info.PasswordSalt; | ||
164 | |||
165 | if (!m_Database.Store(auth)) | ||
166 | { | ||
167 | m_log.ErrorFormat("[AUTHENTICATION DB]: Failed to store authentication info."); | ||
168 | return false; | ||
169 | } | ||
170 | |||
171 | m_log.DebugFormat("[AUTHENTICATION DB]: Set authentication info for principalID {0}", info.PrincipalID); | ||
172 | return true; | ||
173 | } | ||
174 | |||
175 | protected string GetToken(UUID principalID, int lifetime) | ||
176 | { | ||
177 | UUID token = UUID.Random(); | ||
178 | |||
179 | if (m_Database.SetToken(principalID, token.ToString(), lifetime)) | ||
180 | return token.ToString(); | ||
181 | |||
182 | return String.Empty; | ||
183 | } | ||
184 | |||
185 | } | ||
186 | } | ||
diff --git a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs new file mode 100644 index 0000000..5f1bde1 --- /dev/null +++ b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs | |||
@@ -0,0 +1,99 @@ | |||
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 System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Data; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Console; | ||
38 | |||
39 | namespace OpenSim.Services.AuthenticationService | ||
40 | { | ||
41 | // Generic Authentication service used for identifying | ||
42 | // and authenticating principals. | ||
43 | // Principals may be clients acting on users' behalf, | ||
44 | // or any other components that need | ||
45 | // verifiable identification. | ||
46 | // | ||
47 | public class PasswordAuthenticationService : | ||
48 | AuthenticationServiceBase, IAuthenticationService | ||
49 | { | ||
50 | private static readonly ILog m_log = | ||
51 | LogManager.GetLogger( | ||
52 | MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | public PasswordAuthenticationService(IConfigSource config) : | ||
55 | base(config) | ||
56 | { | ||
57 | } | ||
58 | |||
59 | public string Authenticate(UUID principalID, string password, int lifetime) | ||
60 | { | ||
61 | AuthenticationData data = m_Database.Get(principalID); | ||
62 | |||
63 | if (data == null) | ||
64 | { | ||
65 | m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} not found", principalID); | ||
66 | return String.Empty; | ||
67 | } | ||
68 | else if (data.Data == null) | ||
69 | { | ||
70 | m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} data not found", principalID); | ||
71 | return String.Empty; | ||
72 | } | ||
73 | else if (!data.Data.ContainsKey("passwordHash") || !data.Data.ContainsKey("passwordSalt")) | ||
74 | { | ||
75 | m_log.DebugFormat( | ||
76 | "[AUTH SERVICE]: PrincipalID {0} data didn't contain either passwordHash or passwordSalt", principalID); | ||
77 | return String.Empty; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | string hashed = Util.Md5Hash(password + ":" + data.Data["passwordSalt"].ToString()); | ||
82 | |||
83 | m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); | ||
84 | |||
85 | if (data.Data["passwordHash"].ToString() == hashed) | ||
86 | { | ||
87 | return GetToken(principalID, lifetime); | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | m_log.DebugFormat( | ||
92 | "[AUTH SERVICE]: Salted hash {0} of given password did not match salted hash of {1} for PrincipalID {2}. Authentication failure.", | ||
93 | hashed, data.Data["passwordHash"], principalID); | ||
94 | return String.Empty; | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/AuthenticationService/Properties/AssemblyInfo.cs b/OpenSim/Services/AuthenticationService/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8c63adc --- /dev/null +++ b/OpenSim/Services/AuthenticationService/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Services.AuthenticationService")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("Copyright © 2012")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("74497b6f-8844-4ed4-8f0d-2caf7f42b760")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.8.2.*")] | ||
33 | |||
diff --git a/OpenSim/Services/AuthenticationService/WebkeyAuthenticationService.cs b/OpenSim/Services/AuthenticationService/WebkeyAuthenticationService.cs new file mode 100644 index 0000000..2344c0e --- /dev/null +++ b/OpenSim/Services/AuthenticationService/WebkeyAuthenticationService.cs | |||
@@ -0,0 +1,91 @@ | |||
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 System; | ||
29 | using OpenMetaverse; | ||
30 | using OpenSim.Services.Interfaces; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using System.Reflection; | ||
34 | using OpenSim.Data; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Console; | ||
37 | |||
38 | namespace OpenSim.Services.AuthenticationService | ||
39 | { | ||
40 | // Generic Authentication service used for identifying | ||
41 | // and authenticating principals. | ||
42 | // Principals may be clients acting on users' behalf, | ||
43 | // or any other components that need | ||
44 | // verifiable identification. | ||
45 | // | ||
46 | public class WebkeyAuthenticationService : | ||
47 | AuthenticationServiceBase, IAuthenticationService | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger( | ||
51 | MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | public WebkeyAuthenticationService(IConfigSource config) : | ||
54 | base(config) | ||
55 | { | ||
56 | } | ||
57 | |||
58 | public string Authenticate(UUID principalID, string password, int lifetime) | ||
59 | { | ||
60 | if (new UUID(password) == UUID.Zero) | ||
61 | { | ||
62 | m_log.DebugFormat("[AUTH SERVICE]: UUID.Zero is not a valid web_login_key on PrincipalID {0}", principalID); | ||
63 | } | ||
64 | else | ||
65 | { | ||
66 | AuthenticationData data = m_Database.Get(principalID); | ||
67 | if (data != null && data.Data != null) | ||
68 | { | ||
69 | if (data.Data.ContainsKey("webLoginKey")) | ||
70 | { | ||
71 | string key = data.Data["webLoginKey"].ToString(); | ||
72 | if (key == password) | ||
73 | { | ||
74 | data.Data["webLoginKey"] = UUID.Zero.ToString(); | ||
75 | m_Database.Store(data); | ||
76 | return GetToken(principalID, lifetime); | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | m_log.DebugFormat("[AUTH SERVICE]: web login auth failed, got PrincipalID {0} gave {1} instead of {2}", principalID, password, key); | ||
81 | } | ||
82 | }else{ | ||
83 | m_log.DebugFormat("[AUTH SERVICE]: no col webLoginKey in passwd.db"); | ||
84 | } | ||
85 | } | ||
86 | m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID); | ||
87 | } | ||
88 | return String.Empty; | ||
89 | } | ||
90 | } | ||
91 | } | ||
diff --git a/OpenSim/Services/AuthenticationService/WebkeyOrPasswordAuthenticationService.cs b/OpenSim/Services/AuthenticationService/WebkeyOrPasswordAuthenticationService.cs new file mode 100644 index 0000000..2c6cebd --- /dev/null +++ b/OpenSim/Services/AuthenticationService/WebkeyOrPasswordAuthenticationService.cs | |||
@@ -0,0 +1,92 @@ | |||
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 System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Data; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Console; | ||
38 | using OpenSim.Server.Base; | ||
39 | |||
40 | namespace OpenSim.Services.AuthenticationService | ||
41 | { | ||
42 | public class WebkeyOrPasswordAuthenticationService : AuthenticationServiceBase, IAuthenticationService | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | private Dictionary<string, IAuthenticationService> m_svcChecks | ||
47 | = new Dictionary<string, IAuthenticationService>(); | ||
48 | |||
49 | public WebkeyOrPasswordAuthenticationService(IConfigSource config) | ||
50 | : base(config) | ||
51 | { | ||
52 | m_svcChecks["web_login_key"] = new WebkeyAuthenticationService(config); | ||
53 | m_svcChecks["password"] = new PasswordAuthenticationService(config); | ||
54 | } | ||
55 | |||
56 | public string Authenticate(UUID principalID, string password, int lifetime) | ||
57 | { | ||
58 | AuthenticationData data = m_Database.Get(principalID); | ||
59 | string result = String.Empty; | ||
60 | if (data != null && data.Data != null) | ||
61 | { | ||
62 | if (data.Data.ContainsKey("webLoginKey")) | ||
63 | { | ||
64 | m_log.DebugFormat("[AUTH SERVICE]: Attempting web key authentication for PrincipalID {0}", principalID); | ||
65 | result = m_svcChecks["web_login_key"].Authenticate(principalID, password, lifetime); | ||
66 | if (result == String.Empty) | ||
67 | { | ||
68 | m_log.DebugFormat("[AUTH SERVICE]: Web Login failed for PrincipalID {0}", principalID); | ||
69 | } | ||
70 | } | ||
71 | if (result == string.Empty && data.Data.ContainsKey("passwordHash") && data.Data.ContainsKey("passwordSalt")) | ||
72 | { | ||
73 | m_log.DebugFormat("[AUTH SERVICE]: Attempting password authentication for PrincipalID {0}", principalID); | ||
74 | result = m_svcChecks["password"].Authenticate(principalID, password, lifetime); | ||
75 | if (result == String.Empty) | ||
76 | { | ||
77 | m_log.DebugFormat("[AUTH SERVICE]: Password login failed for PrincipalID {0}", principalID); | ||
78 | } | ||
79 | } | ||
80 | if (result == string.Empty) | ||
81 | { | ||
82 | m_log.DebugFormat("[AUTH SERVICE]: Both password and webLoginKey-based authentication failed for PrincipalID {0}", principalID); | ||
83 | } | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID); | ||
88 | } | ||
89 | return result; | ||
90 | } | ||
91 | } | ||
92 | } \ No newline at end of file | ||