OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AuthorizationService.cs
Go to the documentation of this file.
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 System.Linq;
31 using System.Reflection;
32 using Nini.Config;
33 using log4net;
34 using OpenSim.Framework;
35 using OpenSim.Services.Interfaces;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenMetaverse;
39 
41 
42 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
43 {
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  // This should not happen
93  if (m_Scene.RegionInfo.RegionID.ToString() != regionID)
94  {
95  m_log.WarnFormat("[AuthorizationService]: Service for region {0} received request to authorize for region {1}",
96  m_Scene.RegionInfo.RegionID, regionID);
97  message = string.Format("Region {0} received request to authorize for region {1}", m_Scene.RegionInfo.RegionID, regionID);
98  return false;
99  }
100 
101  if (m_accessValue == AccessFlags.None)
102  {
103  message = "Authorized";
104  return true;
105  }
106 
107  UUID userID = new UUID(user);
108 
109  if ((m_accessValue & AccessFlags.DisallowForeigners) != 0)
110  {
111  if (!m_UserManagement.IsLocalGridUser(userID))
112  {
113  message = "No foreign users allowed in this region";
114  return false;
115  }
116  }
117 
118  if ((m_accessValue & AccessFlags.DisallowResidents) != 0)
119  {
120  if (!(m_Scene.Permissions.IsGod(userID) || m_Scene.Permissions.IsAdministrator(userID)))
121  {
122  message = "Only Admins and Managers allowed in this region";
123  return false;
124  }
125  }
126 
127  message = "Authorized";
128  return true;
129  }
130 
131  }
132 }
bool IsAuthorizedForRegion(string user, string firstName, string lastName, string regionID, out string message)
Check whether the user should be given access to the region.
Interactive OpenSim region server
Definition: OpenSim.cs:55
OpenSim.Services.Interfaces.GridRegion GridRegion
This maintains the relationship between a UUID and a user name.