1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.business.rbac;
35
36 import fr.paris.lutece.portal.service.i18n.Localizable;
37 import fr.paris.lutece.portal.service.rbac.Permission;
38 import fr.paris.lutece.portal.service.rbac.ResourceIdService;
39 import fr.paris.lutece.portal.service.rbac.ResourceType;
40 import fr.paris.lutece.portal.service.rbac.ResourceTypeManager;
41
42 import org.apache.commons.lang3.StringUtils;
43
44 import java.util.Locale;
45
46
47
48
49
50 public class RBAC implements Localizable
51 {
52 public static final String WILDCARD_RESOURCES_ID = "*";
53 public static final String WILDCARD_PERMISSIONS_KEY = "*";
54 private int _nRBACId;
55 private String _strRoleKey;
56 private String _strResourceTypeKey;
57 private String _strResourceId;
58 private String _strPermissionKey;
59 private Locale _locale;
60
61
62
63
64
65
66
67 public void setLocale( Locale locale )
68 {
69 _locale = locale;
70 }
71
72
73
74
75
76
77 public int getRBACId( )
78 {
79 return _nRBACId;
80 }
81
82
83
84
85
86
87
88 public void setRBACId( int nRBACId )
89 {
90 _nRBACId = nRBACId;
91 }
92
93
94
95
96
97
98 public String getPermissionKey( )
99 {
100 return _strPermissionKey;
101 }
102
103
104
105
106
107
108
109 public void setPermissionKey( String strPermissionKey )
110 {
111 _strPermissionKey = strPermissionKey;
112 }
113
114
115
116
117
118
119 public String getResourceId( )
120 {
121 return _strResourceId;
122 }
123
124
125
126
127
128
129
130 public void setResourceId( String strResourceId )
131 {
132 _strResourceId = strResourceId;
133 }
134
135
136
137
138
139
140 public String getResourceTypeKey( )
141 {
142 return _strResourceTypeKey;
143 }
144
145
146
147
148
149
150
151 public void setResourceTypeKey( String strResourceTypeKey )
152 {
153 _strResourceTypeKey = strResourceTypeKey;
154 }
155
156
157
158
159
160
161 public String getRoleKey( )
162 {
163 return _strRoleKey;
164 }
165
166
167
168
169
170
171
172 public void setRoleKey( String strRoleKey )
173 {
174 _strRoleKey = strRoleKey;
175 }
176
177
178
179
180
181
182 public String getResourceTypeLabel( )
183 {
184 ResourceType resourceType = ResourceTypeManager.getResourceType( getResourceTypeKey( ) );
185
186 if ( resourceType != null )
187 {
188 return resourceType.getResourceTypeLabel( );
189 }
190
191 return StringUtils.EMPTY;
192 }
193
194
195
196
197
198
199 public String getResourceIdLabel( )
200 {
201 if ( getResourceId( ).equals( WILDCARD_RESOURCES_ID ) )
202 {
203 return WILDCARD_RESOURCES_ID;
204 }
205 else
206 {
207 ResourceType resourceType = ResourceTypeManager.getResourceType( getResourceTypeKey( ) );
208
209 if ( resourceType != null )
210 {
211 ResourceIdService resourceManagerService = resourceType.getResourceIdService( );
212 String strTitle = StringUtils.EMPTY;
213
214 if ( resourceManagerService != null )
215 {
216 strTitle = resourceManagerService.getTitle( getResourceId( ), _locale );
217 }
218 if ( strTitle != null && StringUtils.isNotEmpty( strTitle ) )
219 {
220 return strTitle;
221 }
222 else
223 {
224 return getResourceId( );
225 }
226 }
227
228 return StringUtils.EMPTY;
229 }
230 }
231
232
233
234
235
236
237 public String getPermissionLabel( )
238 {
239 if ( getPermissionKey( ).equals( WILDCARD_PERMISSIONS_KEY ) )
240 {
241 return WILDCARD_PERMISSIONS_KEY;
242 }
243 else
244 {
245 ResourceType resourceType = ResourceTypeManager.getResourceType( getResourceTypeKey( ) );
246 if ( resourceType != null )
247 {
248 Permission permission = resourceType.getPermission( getPermissionKey( ) );
249 if ( permission != null )
250 {
251 permission.setLocale( _locale );
252 return permission.getPermissionTitle( );
253 }
254 }
255 }
256 return StringUtils.EMPTY;
257 }
258 }