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.lang.StringUtils;
43
44 import java.util.Locale;
45
46
47
48
49
50
51
52
53 public class RBAC implements Localizable
54 {
55 public static final String WILDCARD_RESOURCES_ID = "*";
56 public static final String WILDCARD_PERMISSIONS_KEY = "*";
57 private int _nRBACId;
58 private String _strRoleKey;
59 private String _strResourceTypeKey;
60 private String _strResourceId;
61 private String _strPermissionKey;
62 private Locale _locale;
63
64
65
66
67
68 public void setLocale( Locale locale )
69 {
70 _locale = locale;
71 }
72
73
74
75
76
77 public int getRBACId( )
78 {
79 return _nRBACId;
80 }
81
82
83
84
85
86 public void setRBACId( int nRBACId )
87 {
88 _nRBACId = nRBACId;
89 }
90
91
92
93
94
95 public String getPermissionKey( )
96 {
97 return _strPermissionKey;
98 }
99
100
101
102
103
104 public void setPermissionKey( String strPermissionKey )
105 {
106 _strPermissionKey = strPermissionKey;
107 }
108
109
110
111
112
113 public String getResourceId( )
114 {
115 return _strResourceId;
116 }
117
118
119
120
121
122 public void setResourceId( String strResourceId )
123 {
124 _strResourceId = strResourceId;
125 }
126
127
128
129
130
131 public String getResourceTypeKey( )
132 {
133 return _strResourceTypeKey;
134 }
135
136
137
138
139
140 public void setResourceTypeKey( String strResourceTypeKey )
141 {
142 _strResourceTypeKey = strResourceTypeKey;
143 }
144
145
146
147
148
149 public String getRoleKey( )
150 {
151 return _strRoleKey;
152 }
153
154
155
156
157
158 public void setRoleKey( String strRoleKey )
159 {
160 _strRoleKey = strRoleKey;
161 }
162
163
164
165
166
167 public String getResourceTypeLabel( )
168 {
169 ResourceType resourceType = ResourceTypeManager.getResourceType( getResourceTypeKey( ) );
170
171 if ( resourceType != null )
172 {
173 return resourceType.getResourceTypeLabel( );
174 }
175
176 return StringUtils.EMPTY;
177 }
178
179
180
181
182
183 public String getResourceIdLabel( )
184 {
185 if ( getResourceId( ).equals( WILDCARD_RESOURCES_ID ) )
186 {
187 return WILDCARD_RESOURCES_ID;
188 }
189 else
190 {
191 ResourceType resourceType = ResourceTypeManager.getResourceType( getResourceTypeKey( ) );
192
193 if ( resourceType != null )
194 {
195 ResourceIdService resourceManagerService = resourceType.getResourceIdService( );
196 String strTitle = StringUtils.EMPTY ;
197
198 if ( resourceManagerService!= null )
199 {
200 strTitle = resourceManagerService.getTitle( getResourceId( ), _locale );
201 }
202 if ( strTitle != null && StringUtils.isNotEmpty( strTitle ) )
203 {
204 return strTitle;
205 }
206 else
207 {
208 return getResourceId( );
209 }
210 }
211
212 return StringUtils.EMPTY;
213 }
214 }
215
216
217
218
219
220 public String getPermissionLabel( )
221 {
222 if ( getPermissionKey( ).equals( WILDCARD_PERMISSIONS_KEY ) )
223 {
224 return WILDCARD_PERMISSIONS_KEY;
225 }
226 else
227 {
228 ResourceType resourceType = ResourceTypeManager.getResourceType( getResourceTypeKey( ) );
229 if ( resourceType != null )
230 {
231 Permission permission = resourceType.getPermission( getPermissionKey( ) );
232 if ( permission != null )
233 {
234 permission.setLocale( _locale );
235 return permission.getPermissionTitle( );
236 }
237 }
238 }
239 return StringUtils.EMPTY ;
240 }
241 }