clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
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 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 | |||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
41 | |||
42 | namespace 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 | } |