Rev 1776 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1312 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
3 | import com.owlike.genson.Genson; |
||
1814 | jmachado | 4 | import com.owlike.genson.GensonBuilder; |
1312 | jmachado | 5 | import org.apache.log4j.Logger; |
6 | import org.json.JSONArray; |
||
7 | import org.json.JSONException; |
||
1814 | jmachado | 8 | import org.json.JSONObject; |
9 | import pt.estgp.estgweb.domain.typesgenservices.repositorydocuments.RepositoryFileProxy; |
||
10 | import pt.estgp.estgweb.services.virtualfilesystem.PageContentAccessPolicyAcl; |
||
1312 | jmachado | 11 | |
12 | import java.io.IOException; |
||
13 | import java.util.ArrayList; |
||
14 | import java.util.HashMap; |
||
1814 | jmachado | 15 | import java.util.List; |
1312 | jmachado | 16 | import java.util.Map; |
17 | |||
18 | |||
19 | /** |
||
20 | * Created by jorgemachado on 03/02/16. |
||
21 | */ |
||
22 | public abstract class PageContentImpl extends PageContent implements ClearanceRuled |
||
23 | { |
||
24 | |||
25 | private static 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(PageContentImpl.class); |
||
26 | |||
27 | private UserSession sess = null; |
||
28 | private Map<Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation,Boolean> userSessionClearences = null; |
||
29 | private boolean childsInitialized = false; |
||
30 | private boolean parentInitialized = false; |
||
31 | |||
1616 | jmachado | 32 | |
1814 | jmachado | 33 | static Genson genson; |
34 | |||
35 | static Genson gensonSerialize; |
||
36 | |||
37 | |||
38 | static { |
||
39 | gensonSerialize = new GensonBuilder() |
||
40 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
41 | .useMethods(true) |
||
42 | .useFields(false) |
||
43 | .useClassMetadata(true) |
||
44 | .useRuntimeType(true) |
||
45 | //.include("visible") |
||
46 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
||
47 | .exclude("clear") |
||
48 | .exclude("clearanceInitialized") |
||
49 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
50 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
51 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
52 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
53 | //.useFields(false) //COM ISTO A SLUG VAI A NULL E SEM ISTO DÁ NULLPOINTER EXCEPTION. ISTO NO SERVIÇO!!! |
||
54 | .include(PageContentImpl.class) |
||
55 | .include(PageSectionImpl.class) |
||
56 | .include(1.5.0/docs/api/java/security/acl/Acl.html">Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation.class) |
||
57 | .include("title", PageContent.class) |
||
58 | //.include("directory",PageContent.class) |
||
59 | //.include("file", PageContent.class) |
||
60 | .include("description",PageContent.class) |
||
61 | .include("path",PageContent.class) |
||
62 | .include("acl",PageContent.class) |
||
63 | .include("slug",PageContent.class) |
||
64 | .include("pathForIdHtml",PageContent.class) |
||
65 | .include("html", PageText.class) |
||
66 | .include("repositoryId",PageRepositoryFile.class) |
||
67 | //.include("url",PageContent.class) PARA DAR URL TRUE TIVE QUE COMENTAR?? ANTES DE COMENTAR DAVA NULL |
||
68 | //.include("textBox", PageContent.class) |
||
69 | //.include("getAclJson", PageContentImpl.class) |
||
70 | .include("clearances", PageContentImpl.class)//como FUNCIONA PARA PÔR AS ACL'S DIREITINHAS?? |
||
71 | .include("clearences", PageContentImpl.class) |
||
72 | .include("userSessionClearences", PageContentImpl.class) |
||
73 | //.include("pageContent", PageContentImpl.class) |
||
74 | //.include("isClear", PageContentImpl.class) |
||
75 | //.include("isDirectory", PageContentImpl.class) |
||
76 | .include("topLayoutSection", PageSection.class) |
||
77 | //.include("UserSessionClearences", PageContentImpl.class) |
||
78 | .exclude("childsInitialized", PageContentImpl.class) |
||
79 | .exclude("parentInitialized", PageContentImpl.class) |
||
80 | |||
81 | .exclude("parent", PageContent.class) |
||
82 | |||
83 | |||
84 | .include("repositoryFileProxy",PageRepositoryFile.class) |
||
85 | .include("repositoryFile",RepositoryFileProxy.class) |
||
86 | .include(RepositoryFileProxy.class) |
||
87 | .include(RepositoryFileImpl.class) |
||
88 | .include(RepositoryFileVersionImpl.class) |
||
89 | |||
90 | .include("name", RepositoryFileVersion.class) |
||
91 | .include("extension", RepositoryFileVersion.class) |
||
92 | .include("contentType", RepositoryFileVersion.class) |
||
93 | .include("lastVersion", RepositoryFile.class) |
||
94 | .include("size", RepositoryFileVersion.class) |
||
95 | .include("repositoryFileProxy", RepositoryDocumentFileImpl.class) |
||
96 | .exclude("repositoryFile", RepositoryFileVersion.class) |
||
97 | .exclude("publishDate", RepositoryDocumentImpl.class) |
||
98 | .exclude("closeDate", RepositoryDocumentImpl.class) |
||
99 | //O sistema nao constroi o RepositoryFile a partir da classe |
||
100 | //mas como guarda o stream quando serializar aparece outra vez o ficheiro |
||
101 | .include("repositoryFile", RepositoryFileProxy.class) //DIFERENCA COM O ANTERIOR |
||
102 | .exclude("repositoryFileVersions",RepositoryFile.class) |
||
103 | .exclude("sourceModule",RepositoryFile.class) |
||
104 | |||
105 | |||
106 | .create(); |
||
107 | |||
108 | } |
||
109 | |||
110 | static { |
||
111 | GensonBuilder gensonBuilder = new GensonBuilder() |
||
112 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
113 | .useMethods(true) |
||
114 | .useFields(false) |
||
115 | .useClassMetadata(true) |
||
116 | .useRuntimeType(true) |
||
117 | |||
118 | .exclude("clear") |
||
119 | .exclude("clearanceInitialized") |
||
120 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
121 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
122 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
123 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
124 | //.useFields(false) //COM ISTO A SLUG VAI A NULL E SEM ISTO DÁ NULLPOINTER EXCEPTION. ISTO NO SERVIÇO!!! |
||
125 | .include(PageContentImpl.class) |
||
126 | .include(PageSectionImpl.class) |
||
127 | .include(1.5.0/docs/api/java/security/acl/Acl.html">Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation.class) |
||
128 | .include("title", PageContent.class) |
||
129 | //.include("directory",PageContent.class) |
||
130 | //.include("file", PageContent.class) |
||
131 | .include("visible", PageContent.class) //TIVE QUE INCLUIR PORQUE PRECISO DO MÉTODO ISVISIBLE |
||
132 | .include("description", PageContent.class) |
||
133 | .include("path", PageContent.class) |
||
134 | .include("acl",PageContent.class) |
||
135 | .include("slug",PageContent.class) |
||
136 | .include("pathForIdHtml", PageContent.class) |
||
137 | .include("html", PageText.class) |
||
138 | .include("repositoryId", PageRepositoryFile.class) |
||
139 | //.include("url",PageContent.class) PARA DAR URL TRUE TIVE QUE COMENTAR?? ANTES DE COMENTAR DAVA NULL |
||
140 | //.include("textBox", PageContent.class) |
||
141 | //.include("getAclJson", PageContentImpl.class) |
||
142 | .include("clearances", PageContentImpl.class)//como FUNCIONA PARA PÔR AS ACL'S DIREITINHAS?? |
||
143 | .include("clearences", PageContentImpl.class) |
||
144 | .include("userSessionClearences", PageContentImpl.class) |
||
145 | //.include("UserSessionClearences", PageContentImpl.class) |
||
146 | //.include("pageContent", PageContentImpl.class) |
||
147 | //.include("isClear", PageContentImpl.class) |
||
148 | //.include("isDirectory", PageContentImpl.class) |
||
149 | .exclude("childsInitialized", PageContentImpl.class) |
||
150 | .exclude("parentInitialized", PageContentImpl.class) |
||
151 | .exclude("parent", PageContent.class); |
||
152 | |||
153 | |||
154 | |||
155 | |||
156 | genson = gensonBuilder.create(); |
||
157 | } |
||
158 | |||
159 | |||
160 | public boolean isDirectory() |
||
161 | { |
||
162 | return this instanceof PageSection; |
||
163 | } |
||
164 | |||
165 | public boolean isFile() |
||
166 | { |
||
167 | return this instanceof PageRepositoryFile; |
||
168 | } |
||
169 | |||
170 | public boolean isUrl() |
||
171 | { |
||
172 | return this instanceof PageExternalUrl; |
||
173 | } |
||
174 | |||
175 | public boolean isTextBox() |
||
176 | { |
||
177 | return this instanceof PageText; |
||
178 | } |
||
179 | |||
180 | public static PageContentImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException{ |
||
181 | return genson.deserialize(json,PageContentImpl.class); |
||
182 | } |
||
183 | |||
184 | public static PageExternalUrlImpl loadFromJsonUrl(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException{ |
||
185 | return genson.deserialize(json,PageExternalUrlImpl.class); |
||
186 | } |
||
187 | |||
188 | public static PageRepositoryFileImpl loadFromJsonFile(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException{ |
||
189 | return genson.deserialize(json,PageRepositoryFileImpl.class); |
||
190 | } |
||
191 | |||
192 | public static PageTextImpl loadFromJsonText(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException{ |
||
193 | return genson.deserialize(json,PageTextImpl.class); |
||
194 | } |
||
195 | |||
196 | public 1.5.0/docs/api/java/lang/String.html">String toJson() |
||
197 | { |
||
198 | return gensonSerialize.serialize(this); |
||
199 | } |
||
200 | |||
201 | public JSONObject toJsonObject() throws JSONException{ |
||
202 | return new JSONObject(toJson()); |
||
203 | } |
||
204 | |||
205 | public static JSONArray toJsonArray(List<PageContentImpl> itemGroup) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
||
206 | return new JSONArray(gensonSerialize.serialize(itemGroup)); |
||
207 | } |
||
208 | |||
1312 | jmachado | 209 | public static class 1.5.0/docs/api/java/security/acl/Acl.html">Acl |
210 | { |
||
1616 | jmachado | 211 | public static 1.5.0/docs/api/java/security/acl/Acl.html">Acl AUTHENTICATED_ACL = new 1.5.0/docs/api/java/security/acl/Acl.html">Acl(1.5.0/docs/api/java/security/acl/Acl.html">Acl.Access.PERMIT.name(), |
212 | 1.5.0/docs/api/java/security/acl/Acl.html">Acl.1.5.0/docs/api/java/lang/reflect/Type.html">Type.AUTHENTICATED.name(),"",1.5.0/docs/api/java/security/acl/Acl.html">Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation.READ_CONTENTS.name()); |
||
213 | public static ArrayList<Acl> AUTHENTICATED_ACL_SIMPLE_LIST = new ArrayList<Acl>(); |
||
214 | static{ |
||
215 | AUTHENTICATED_ACL_SIMPLE_LIST.add(AUTHENTICATED_ACL); |
||
216 | } |
||
217 | |||
218 | public 1.5.0/docs/api/java/security/acl/Acl.html">Acl(1.5.0/docs/api/java/lang/String.html">String access, 1.5.0/docs/api/java/lang/String.html">String type, 1.5.0/docs/api/java/lang/String.html">String id, 1.5.0/docs/api/java/lang/String.html">String operation) { |
||
219 | this.access = access; |
||
220 | this.type = type; |
||
221 | this.id = id; |
||
222 | this.operation = operation; |
||
223 | } |
||
224 | |||
225 | public 1.5.0/docs/api/java/security/acl/Acl.html">Acl() { |
||
226 | } |
||
227 | |||
1312 | jmachado | 228 | public static enum Access |
229 | { |
||
230 | PERMIT, |
||
231 | DENY //default |
||
232 | } |
||
233 | public static enum 1.5.0/docs/api/java/lang/reflect/Type.html">Type |
||
234 | { |
||
235 | ALL, |
||
236 | ANONYMOUS, //ONLY SUPER USER SHOULD ADD ANONYMOUS PERMISSIONS |
||
237 | AUTHENTICATED, |
||
238 | ROLE, |
||
239 | USER, |
||
240 | COURSEUNIT //SPECIFIC PERMISSIONS RELATIVE TO COURSE UNITS |
||
241 | } |
||
242 | public static enum 1.5.0/docs/api/java/rmi/server/Operation.html">Operation |
||
243 | { |
||
244 | ALL, //SPECIAL OPERATION FOR DENY AND PERMIT REPLACE FULL CONTROL |
||
245 | |||
246 | READ_CONTENTS, |
||
247 | |||
248 | READ_VERSIONS, |
||
249 | READ_INVISIBLES, |
||
250 | |||
251 | |||
252 | ORDER_CONTENTS, |
||
253 | |||
1561 | jmachado | 254 | ADD_SECTIONS, //ADD TEXT USA ESTA PERMISSAO |
1312 | jmachado | 255 | ADD_FILES, |
256 | ADD_URLS, |
||
257 | ADD_MODULES, |
||
258 | |||
259 | REMOVE_SECTIONS, |
||
260 | REMOVE_FILES, |
||
261 | REMOVE_URLS, |
||
262 | REMOVE_MODULES, |
||
263 | |||
264 | EDIT_SECTIONS, |
||
265 | EDIT_FILES, |
||
266 | EDIT_URLS, |
||
267 | EDIT_MODULES; |
||
268 | |||
269 | public static 1.5.0/docs/api/java/rmi/server/Operation.html">Operation parse(1.5.0/docs/api/java/lang/String.html">String clearance) |
||
270 | { |
||
271 | if(clearance == null) |
||
272 | return null; |
||
273 | for(1.5.0/docs/api/java/rmi/server/Operation.html">Operation op: 1.5.0/docs/api/java/rmi/server/Operation.html">Operation.values()) |
||
274 | { |
||
275 | if(op.name().equals(clearance)) |
||
276 | return op; |
||
277 | } |
||
278 | return null; |
||
279 | } |
||
1616 | jmachado | 280 | |
281 | |||
1312 | jmachado | 282 | } |
283 | |||
284 | public static enum CourseUnitsId |
||
285 | { |
||
286 | COURSE_UNIT_TEACHER("page.content.course.unit.teacher"), |
||
287 | COURSE_UNIT_STUDENT("page.content.course.unit.student"), |
||
288 | COURSE_UNIT_RESP_TEACHER("page.content.course.unit.resp.teacher"), |
||
289 | COURSE_UNIT_COURSE_COMISSION("page.content.course.unit.course.comission"); |
||
290 | |||
291 | 1.5.0/docs/api/java/lang/String.html">String msgKey; |
||
292 | |||
293 | |||
294 | CourseUnitsId(1.5.0/docs/api/java/lang/String.html">String msgKey) { |
||
295 | this.msgKey = msgKey; |
||
296 | } |
||
297 | } |
||
298 | |||
299 | private 1.5.0/docs/api/java/lang/String.html">String access; |
||
300 | private 1.5.0/docs/api/java/lang/String.html">String type; |
||
301 | private 1.5.0/docs/api/java/lang/String.html">String id; |
||
302 | private 1.5.0/docs/api/java/lang/String.html">String operation; |
||
303 | |||
304 | public 1.5.0/docs/api/java/lang/String.html">String getAccess() { |
||
305 | return access; |
||
306 | } |
||
307 | |||
308 | public void setAccess(1.5.0/docs/api/java/lang/String.html">String access) { |
||
309 | this.access = access; |
||
310 | } |
||
311 | |||
312 | public void setAccessEnum(Access access) { |
||
313 | this.access = access.name(); |
||
314 | } |
||
315 | |||
316 | public 1.5.0/docs/api/java/lang/String.html">String getType() { |
||
317 | return type; |
||
318 | } |
||
319 | |||
320 | public void setType(1.5.0/docs/api/java/lang/String.html">String type) { |
||
321 | this.type = type; |
||
322 | } |
||
323 | public void setTypeEnum(1.5.0/docs/api/java/lang/reflect/Type.html">Type type) { |
||
324 | this.type = type.name(); |
||
325 | } |
||
326 | |||
327 | public 1.5.0/docs/api/java/lang/String.html">String getId() { |
||
328 | return id; |
||
329 | } |
||
330 | |||
331 | public void setId(1.5.0/docs/api/java/lang/String.html">String id) { |
||
332 | this.id = id; |
||
333 | } |
||
334 | |||
335 | public 1.5.0/docs/api/java/lang/String.html">String getOperation() { |
||
336 | return operation; |
||
337 | } |
||
338 | |||
339 | public void setOperation(1.5.0/docs/api/java/lang/String.html">String operation) { |
||
340 | this.operation = operation; |
||
341 | } |
||
342 | |||
343 | public void setOperationEnum(1.5.0/docs/api/java/rmi/server/Operation.html">Operation operation) { |
||
344 | this.operation = operation.name(); |
||
345 | } |
||
346 | |||
347 | public void setCourseUnitIdEnum(CourseUnitsId courseUnitIdEnum) { |
||
348 | this.id = courseUnitIdEnum.name(); |
||
349 | } |
||
350 | |||
351 | public Access getAccessEnum() |
||
352 | { |
||
353 | for(Access a : Access.values()) |
||
354 | { |
||
355 | if(a.name().equals(getAccess())) |
||
356 | return a; |
||
357 | } |
||
358 | return Access.DENY; |
||
359 | } |
||
360 | |||
361 | public 1.5.0/docs/api/java/lang/reflect/Type.html">Type getTypeEnum() |
||
362 | { |
||
363 | for(1.5.0/docs/api/java/lang/reflect/Type.html">Type a : 1.5.0/docs/api/java/lang/reflect/Type.html">Type.values()) |
||
364 | { |
||
365 | if(a.name().equals(getType())) |
||
366 | return a; |
||
367 | } |
||
368 | return 1.5.0/docs/api/java/lang/reflect/Type.html">Type.ROLE; |
||
369 | } |
||
370 | |||
371 | public 1.5.0/docs/api/java/rmi/server/Operation.html">Operation getOperationEnum() |
||
372 | { |
||
373 | for(1.5.0/docs/api/java/rmi/server/Operation.html">Operation a : 1.5.0/docs/api/java/rmi/server/Operation.html">Operation.values()) |
||
374 | { |
||
375 | if(a.name().equals(getOperation())) |
||
376 | return a; |
||
377 | } |
||
378 | return null; |
||
379 | } |
||
380 | |||
381 | public CourseUnitsId getCourseUnitIdEnum() |
||
382 | { |
||
383 | for(CourseUnitsId a : CourseUnitsId.values()) |
||
384 | { |
||
385 | if(a.name().equals(getId())) |
||
386 | return a; |
||
387 | } |
||
388 | return null; |
||
389 | } |
||
390 | } |
||
391 | |||
392 | /** |
||
393 | * Empty Array Means no ACL's defined |
||
394 | * build a json array form ACL's |
||
395 | * @return example [{"access":"PERMIT","operation":"FULL_CONTROL","id":"services","type":"ROLE"}] |
||
396 | * @throws JSONException |
||
397 | */ |
||
398 | public JSONArray getAclJson() throws JSONException |
||
399 | { |
||
400 | if(getAcl() == null || getAcl().trim().length() == 0) |
||
401 | return new JSONArray(); |
||
402 | return new JSONArray(getAcl()); |
||
403 | } |
||
404 | |||
405 | /** |
||
406 | * Sets the string ACL with the proper json |
||
407 | * @param json |
||
408 | * @throws JSONException |
||
409 | */ |
||
410 | public void setAclJson(JSONArray json) throws JSONException |
||
411 | { |
||
412 | if(json == null) |
||
413 | setAcl(null); |
||
414 | else |
||
415 | setAcl(json.toString()); |
||
416 | } |
||
417 | |||
418 | /** |
||
419 | * sets the string Acl with the json built from given List |
||
420 | * @param acls |
||
421 | * @throws JSONException |
||
422 | */ |
||
1776 | jmachado | 423 | public void setAclList(ArrayList<Acl> acls) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
1312 | jmachado | 424 | if(acls == null || acls.size() == 0) |
425 | { |
||
426 | setAcl(null); |
||
427 | return; |
||
428 | } |
||
429 | setAcl(getAclJson(acls).toString()); |
||
430 | } |
||
431 | |||
432 | /** |
||
433 | * Empty Array Means no ACL's defined allays |
||
434 | * @return allays a list if no acls return empty list |
||
435 | * @throws JSONException |
||
436 | */ |
||
1776 | jmachado | 437 | public ArrayList<Acl> getAclList() throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
1312 | jmachado | 438 | ArrayList<Acl> acls = new ArrayList<Acl>(); |
439 | if(getAcl() == null || getAcl().trim().length() == 0) |
||
440 | return acls; |
||
441 | Genson genson = getGenson(); |
||
442 | ArrayList<HashMap<String,String>> aclsDes = genson.deserialize(getAcl(),1.5.0/docs/api/java/util/ArrayList.html">ArrayList.class); |
||
443 | for(HashMap<String,String> acl: aclsDes) |
||
444 | { |
||
445 | 1.5.0/docs/api/java/security/acl/Acl.html">Acl a = new 1.5.0/docs/api/java/security/acl/Acl.html">Acl(); |
||
446 | a.setType(acl.get("type")); |
||
447 | a.setOperation(acl.get("operation")); |
||
448 | a.setAccess(acl.get("access")); |
||
449 | a.setId(acl.get("id")); |
||
450 | acls.add(a); |
||
451 | } |
||
452 | return acls; |
||
453 | } |
||
454 | |||
455 | /** |
||
456 | * Add a acl to String json at the end |
||
457 | * @param acl |
||
458 | * @throws IOException |
||
459 | * @throws JSONException |
||
460 | */ |
||
1776 | jmachado | 461 | public void addAcl(1.5.0/docs/api/java/security/acl/Acl.html">Acl acl) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1312 | jmachado | 462 | if(acl == null) |
463 | return; |
||
464 | ArrayList<Acl> acls = getAclList(); |
||
465 | acls.add(acl); |
||
466 | setAclList(acls); |
||
467 | } |
||
468 | |||
469 | private static Genson getGenson(){ |
||
470 | Genson genson = new Genson.Builder() |
||
471 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
472 | .include("access", 1.5.0/docs/api/java/security/acl/Acl.html">Acl.class) |
||
473 | .include("type", 1.5.0/docs/api/java/security/acl/Acl.html">Acl.class) |
||
474 | .include("id", 1.5.0/docs/api/java/security/acl/Acl.html">Acl.class) |
||
475 | .include("operation", 1.5.0/docs/api/java/security/acl/Acl.html">Acl.class) |
||
476 | .create(); |
||
477 | return genson; |
||
478 | } |
||
479 | |||
480 | /** |
||
481 | * Utilitário |
||
482 | * @param aclList |
||
483 | * @return |
||
484 | * @throws IOException |
||
485 | * @throws JSONException |
||
486 | */ |
||
1776 | jmachado | 487 | public static JSONArray getAclJson(ArrayList<Acl> aclList) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1312 | jmachado | 488 | if(aclList == null) |
489 | return new JSONArray(); |
||
490 | Genson genson = getGenson(); |
||
491 | 1.5.0/docs/api/java/lang/String.html">String json = genson.serialize(aclList); |
||
492 | //System.out.println(json); |
||
493 | return new JSONArray(json); |
||
494 | } |
||
495 | |||
496 | |||
497 | public boolean isChildsInitialized() { |
||
498 | return childsInitialized; |
||
499 | } |
||
500 | |||
501 | public void setChildsInitialized(boolean childsInitialized) { |
||
502 | this.childsInitialized = childsInitialized; |
||
503 | } |
||
504 | |||
505 | public boolean isParentInitialized() { |
||
506 | return parentInitialized; |
||
507 | } |
||
508 | |||
509 | public void setParentInitialized(boolean parentInitialized) { |
||
510 | this.parentInitialized = parentInitialized; |
||
511 | } |
||
512 | |||
513 | /** |
||
514 | * Metodo de testes |
||
515 | * @param args |
||
516 | * @throws IOException |
||
517 | * @throws JSONException |
||
518 | */ |
||
1776 | jmachado | 519 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1312 | jmachado | 520 | |
521 | |||
522 | |||
523 | } |
||
524 | |||
525 | public boolean canAdmin(UserSessionImpl u) |
||
526 | { |
||
527 | if(sess != null && sess.getCookie() != null && !sess.getCookie().equals(u.getCookie())) |
||
528 | { |
||
529 | logger.warn("Clearances checked for Mr:" + sess.getCookie() + " but clearing for Mr:" + u.getCookie()); |
||
530 | return false; |
||
531 | } |
||
532 | else if(userSessionClearences != null) |
||
533 | { |
||
534 | for(1.5.0/docs/api/java/util/Map.html">Map.Entry<Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation,Boolean> entry: userSessionClearences.entrySet()) |
||
535 | { |
||
536 | if(entry.getValue() == true && |
||
537 | !entry.getKey().name().startsWith("READ")) |
||
538 | { |
||
539 | return true; |
||
540 | } |
||
541 | } |
||
542 | return false; |
||
543 | } |
||
544 | else |
||
545 | { |
||
546 | logger.warn("Checking clearance without sessionClearances initialized, not allowed"); |
||
547 | return false; |
||
548 | } |
||
549 | } |
||
550 | |||
551 | |||
552 | |||
553 | |||
554 | public boolean isClear(UserSessionImpl u, 1.5.0/docs/api/java/lang/String.html">String OP) |
||
555 | { |
||
556 | 1.5.0/docs/api/java/security/acl/Acl.html">Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation o = 1.5.0/docs/api/java/security/acl/Acl.html">Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation.parse(OP); |
||
557 | return isClear(u,o); |
||
558 | } |
||
559 | |||
560 | /** |
||
561 | * Same logic in isClearanceInitialized Method |
||
562 | * @param u |
||
563 | * @return |
||
564 | */ |
||
565 | public boolean isClear(UserSessionImpl u, PageContentImpl.1.5.0/docs/api/java/security/acl/Acl.html">Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation op) |
||
566 | { |
||
567 | if(sess != null && sess.getCookie() != null && !sess.getCookie().equals(u.getCookie())) |
||
568 | { |
||
569 | logger.warn("Clearances checked for Mr:" + sess.getCookie() + " but clearing for Mr:" + u.getCookie()); |
||
570 | return false; |
||
571 | } |
||
1616 | jmachado | 572 | else if(sess == null || sess.getCookie() == null || u == null || u.getCookie() == null) |
573 | { |
||
574 | logger.warn("Clearances are being checked to a user or a session with no cookie identifier"); |
||
575 | return false; |
||
576 | } |
||
1312 | jmachado | 577 | else if(userSessionClearences != null) |
578 | { |
||
579 | return userSessionClearences.get(op); |
||
580 | } |
||
581 | else |
||
582 | { |
||
583 | logger.warn("Checking clearance without sessionClearances initialized, not allowed"); |
||
584 | return false; |
||
585 | } |
||
586 | } |
||
587 | |||
588 | /** |
||
589 | * Same logic in isClear Method |
||
590 | * @param u |
||
591 | * @return |
||
592 | */ |
||
593 | public boolean isClearanceInitialized(UserSessionImpl u) |
||
594 | { |
||
595 | if(sess != null && sess.getCookie() != null && !sess.getCookie().equals(u.getCookie())) |
||
596 | { |
||
597 | return false; |
||
598 | } |
||
599 | else if(userSessionClearences == null) |
||
600 | { |
||
601 | return false; |
||
602 | } |
||
603 | return true; |
||
604 | } |
||
605 | |||
1326 | jmachado | 606 | @1.5.0/docs/api/java/lang/Override.html">Override |
607 | public void initClearances(UserSessionImpl u, boolean force) { |
||
1312 | jmachado | 608 | |
609 | |||
1814 | jmachado | 610 | } |
1326 | jmachado | 611 | |
1312 | jmachado | 612 | public void setUserSessionClearences(Map<Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation, Boolean> userSessionClearences) { |
613 | this.userSessionClearences = userSessionClearences; |
||
614 | } |
||
615 | |||
616 | public void setSess(UserSession sess) { |
||
617 | this.sess = sess; |
||
618 | } |
||
619 | |||
620 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
621 | public 1.5.0/docs/api/java/lang/String.html">String getAccessPolicyClass() { |
||
622 | if(super.getAccessPolicyClass() == null) |
||
623 | { |
||
624 | logger.debug("No AccessPolicyClass in PageContent " + getId() + ":" + getTitle() + " using default:" + PageContentAccessPolicyAcl.class.getName()); |
||
625 | return PageContentAccessPolicyAcl.class.getName(); |
||
626 | } |
||
627 | return super.getAccessPolicyClass(); |
||
628 | } |
||
1814 | jmachado | 629 | |
630 | public Map<Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation, Boolean> getClearences() { |
||
631 | return userSessionClearences; |
||
632 | } |
||
633 | |||
634 | public void setClearences(Map<Acl.1.5.0/docs/api/java/rmi/server/Operation.html">Operation, Boolean> x) { |
||
635 | |||
636 | } |
||
1312 | jmachado | 637 | } |