Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java @ 833:fa922101a462
Refactored Authorization.
* Introduced "authorizer"
* Attribute and datatype depended authorization
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 08 Jan 2016 12:05:26 +0100 |
parents | |
children | 2fe625c91ab3 |
comparison
equal
deleted
inserted
replaced
832:59c51da59b30 | 833:fa922101a462 |
---|---|
1 package de.intevation.lada.util.auth; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import de.intevation.lada.model.land.LProbe; | |
7 import de.intevation.lada.util.rest.RequestMethod; | |
8 import de.intevation.lada.util.rest.Response; | |
9 | |
10 public class ProbeAuthorizer extends BaseAuthorizer { | |
11 | |
12 @Override | |
13 public <T> boolean isAuthorized( | |
14 Object data, | |
15 RequestMethod method, | |
16 UserInfo userInfo, | |
17 Class<T> clazz | |
18 ) { | |
19 LProbe probe = (LProbe)data; | |
20 if (method == RequestMethod.POST) { | |
21 return getAuthorization(userInfo, probe); | |
22 } | |
23 else if (method == RequestMethod.PUT || | |
24 method == RequestMethod.DELETE) { | |
25 return !isProbeReadOnly(probe.getId()); | |
26 } | |
27 return false; | |
28 } | |
29 | |
30 @SuppressWarnings("unchecked") | |
31 @Override | |
32 public <T> Response filter( | |
33 Response data, | |
34 UserInfo userInfo, | |
35 Class<T> clazz | |
36 ) { | |
37 if (data.getData() instanceof List<?>) { | |
38 List<LProbe> proben = new ArrayList<LProbe>(); | |
39 for (LProbe probe :(List<LProbe>)data.getData()) { | |
40 proben.add(setAuthData(userInfo, probe)); | |
41 } | |
42 data.setData(proben); | |
43 } | |
44 else if (data.getData() instanceof LProbe) { | |
45 LProbe probe = (LProbe)data.getData(); | |
46 data.setData(setAuthData(userInfo, probe)); | |
47 } | |
48 return data; | |
49 } | |
50 | |
51 /** | |
52 * Set authorization data for the current probe object. | |
53 * | |
54 * @param userInfo The user information. | |
55 * @param probe The probe object. | |
56 * @return The probe. | |
57 */ | |
58 private LProbe setAuthData(UserInfo userInfo, LProbe probe) { | |
59 if (!userInfo.getNetzbetreiber().contains(probe.getNetzbetreiberId())) { | |
60 probe.setOwner(false); | |
61 probe.setReadonly(true); | |
62 return probe; | |
63 } | |
64 if (userInfo.getMessstellen().contains(probe.getMstId())) { | |
65 probe.setOwner(true); | |
66 } | |
67 else { | |
68 probe.setOwner(false); | |
69 } | |
70 probe.setReadonly(this.isProbeReadOnly(probe.getId())); | |
71 return probe; | |
72 } | |
73 } |