aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
diff options
context:
space:
mode:
authorDiva Canto2012-03-17 10:00:11 -0700
committerDiva Canto2012-03-17 10:00:11 -0700
commit33c14cb107ecb67a3e971d6adaab17d173d52747 (patch)
tree401301804f123e686b23c3ff925a7a393eaf4c2c /OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
parentClean up "save iar" help (diff)
downloadopensim-SC_OLD-33c14cb107ecb67a3e971d6adaab17d173d52747.zip
opensim-SC_OLD-33c14cb107ecb67a3e971d6adaab17d173d52747.tar.gz
opensim-SC_OLD-33c14cb107ecb67a3e971d6adaab17d173d52747.tar.bz2
opensim-SC_OLD-33c14cb107ecb67a3e971d6adaab17d173d52747.tar.xz
Region access control! Region operators can now specify things like DisallowForeigners (means what it says) and DisallowResidents (means that only admins and managers can get into the region). This puts the never-completed AuthorizationService to good use. Note that I didn't implement a grid-wide Authorization service; this service implementation is done entirely locally on the simulator. This can be changed as usual by pluging in a different AuthorizationServicesConnector.
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs124
1 files changed, 124 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
new file mode 100644
index 0000000..f0d21e6
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
@@ -0,0 +1,124 @@
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.Generic;
30using System.Linq;
31using System.Reflection;
32using Nini.Config;
33using log4net;
34using OpenSim.Framework;
35using OpenSim.Services.Interfaces;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenMetaverse;
39
40using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41
42namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
43{
44 public class AuthorizationService : IAuthorizationService
45 {
46 private enum AccessFlags
47 {
48 None = 0, /* No restrictions */
49 DisallowResidents = 1, /* Only gods and managers*/
50 DisallowForeigners = 2, /* Only local people */
51 }
52
53 private static readonly ILog m_log =
54 LogManager.GetLogger(
55 MethodBase.GetCurrentMethod().DeclaringType);
56
57 private IUserManagement m_UserManagement;
58 private IGridService m_GridService;
59
60 private Scene m_Scene;
61 AccessFlags m_accessValue = AccessFlags.None;
62
63
64 public AuthorizationService(IConfig config, Scene scene)
65 {
66 m_Scene = scene;
67 m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
68 m_GridService = scene.GridService;
69
70 if (config != null)
71 {
72 string accessStr = config.GetString("Region_" + scene.RegionInfo.RegionName.Replace(' ', '_'), String.Empty);
73 if (accessStr != string.Empty)
74 {
75 try
76 {
77 m_accessValue = (AccessFlags)Enum.Parse(typeof(AccessFlags), accessStr);
78 }
79 catch (ArgumentException)
80 {
81 m_log.WarnFormat("[AuthorizationService]: {0} is not a valid access flag", accessStr);
82 }
83 }
84 m_log.DebugFormat("[AuthorizationService]: Region {0} access restrictions: {1}", m_Scene.RegionInfo.RegionName, m_accessValue);
85 }
86
87 }
88
89 public bool IsAuthorizedForRegion(
90 string user, string firstName, string lastName, string regionID, out string message)
91 {
92 message = "authorized";
93
94 // This should not happen
95 if (m_Scene.RegionInfo.RegionID.ToString() != regionID)
96 {
97 m_log.WarnFormat("[AuthorizationService]: Service for region {0} received request to authorize for region {1}",
98 m_Scene.RegionInfo.RegionID, regionID);
99 return true;
100 }
101
102 if (m_accessValue == AccessFlags.None)
103 return true;
104
105 UUID userID = new UUID(user);
106 bool authorized = true;
107 if ((m_accessValue & AccessFlags.DisallowForeigners) == AccessFlags.DisallowForeigners)
108 {
109 authorized = m_UserManagement.IsLocalGridUser(userID);
110 if (!authorized)
111 message = "no foreigner users allowed in this region";
112 }
113 if (authorized && (m_accessValue & AccessFlags.DisallowResidents) == AccessFlags.DisallowResidents)
114 {
115 authorized = m_Scene.Permissions.IsGod(userID) | m_Scene.Permissions.IsAdministrator(userID);
116 if (!authorized)
117 message = "only Admins and Managers allowed in this region";
118 }
119
120 return authorized;
121 }
122
123 }
124} \ No newline at end of file