annotate src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java @ 1028:1c41c7b8f7c2 schema-update

Updated server application to new database model. THIS IS STILL WIP!!!
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 08 Jul 2016 15:32:36 +0200
parents f5b4784d9173
children
rev   line source
849
d0a591b3eade Added missing file header.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 840
diff changeset
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
d0a591b3eade Added missing file header.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 840
diff changeset
2 * Software engineering by Intevation GmbH
d0a591b3eade Added missing file header.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 840
diff changeset
3 *
d0a591b3eade Added missing file header.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 840
diff changeset
4 * This file is Free Software under the GNU GPL (v>=3)
d0a591b3eade Added missing file header.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 840
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
d0a591b3eade Added missing file header.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 840
diff changeset
6 * the documentation coming with IMIS-Labordaten-Application for details.
d0a591b3eade Added missing file header.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 840
diff changeset
7 */
833
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 package de.intevation.lada.util.auth;
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 import java.util.ArrayList;
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import java.util.List;
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12
1028
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
13 import de.intevation.lada.model.land.Probe;
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
14 import de.intevation.lada.model.stammdaten.MessStelle;
833
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import de.intevation.lada.util.rest.RequestMethod;
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import de.intevation.lada.util.rest.Response;
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 public class ProbeAuthorizer extends BaseAuthorizer {
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 @Override
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 public <T> boolean isAuthorized(
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 Object data,
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 RequestMethod method,
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 UserInfo userInfo,
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 Class<T> clazz
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 ) {
1028
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
27 Probe probe = (Probe)data;
840
2fe625c91ab3 Merged branches.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 833
diff changeset
28 if (method == RequestMethod.PUT ||
2fe625c91ab3 Merged branches.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 833
diff changeset
29 method == RequestMethod.DELETE) {
833
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 return !isProbeReadOnly(probe.getId());
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 }
840
2fe625c91ab3 Merged branches.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 833
diff changeset
32 return getAuthorization(userInfo, probe);
833
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 }
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 @SuppressWarnings("unchecked")
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 @Override
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 public <T> Response filter(
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 Response data,
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 UserInfo userInfo,
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 Class<T> clazz
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 ) {
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 if (data.getData() instanceof List<?>) {
1028
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
43 List<Probe> proben = new ArrayList<Probe>();
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
44 for (Probe probe :(List<Probe>)data.getData()) {
833
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 proben.add(setAuthData(userInfo, probe));
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 }
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 data.setData(proben);
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 }
1028
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
49 else if (data.getData() instanceof Probe) {
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
50 Probe probe = (Probe)data.getData();
833
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 data.setData(setAuthData(userInfo, probe));
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 }
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 return data;
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 }
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 /**
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 * Set authorization data for the current probe object.
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 *
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 * @param userInfo The user information.
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 * @param probe The probe object.
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 * @return The probe.
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 */
1028
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
63 private Probe setAuthData(UserInfo userInfo, Probe probe) {
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
64 MessStelle mst = repository.getByIdPlain(MessStelle.class, probe.getMstId(), "stamm");
1c41c7b8f7c2 Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents: 894
diff changeset
65 if (!userInfo.getNetzbetreiber().contains(mst.getNetzbetreiberId())) {
833
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 probe.setOwner(false);
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 probe.setReadonly(true);
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 return probe;
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 }
894
f5b4784d9173 Load probe attribute 'laborMstId' from db and use this field to authorize
Raimund Renkert <raimund.renkert@intevation.de>
parents: 849
diff changeset
70 if (userInfo.belongsTo(probe.getMstId(), probe.getLaborMstId())) {
833
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 probe.setOwner(true);
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 }
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 else {
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 probe.setOwner(false);
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 }
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 probe.setReadonly(this.isProbeReadOnly(probe.getId()));
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 return probe;
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 }
fa922101a462 Refactored Authorization.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)