Mercurial > lada > lada-server
changeset 894:f5b4784d9173
Load probe attribute 'laborMstId' from db and use this field to authorize
objects.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 11 Mar 2016 13:59:16 +0100 |
parents | 9258cce7bcbd |
children | 0a69252ed7a0 |
files | src/main/java/de/intevation/lada/model/Probe.java src/main/java/de/intevation/lada/rest/UserService.java src/main/java/de/intevation/lada/util/auth/MessungAuthorizer.java src/main/java/de/intevation/lada/util/auth/MessungIdAuthorizer.java src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java src/main/java/de/intevation/lada/util/auth/ProbeIdAuthorizer.java src/main/java/de/intevation/lada/util/auth/UserInfo.java |
diffstat | 7 files changed, 94 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/model/Probe.java Wed Mar 09 17:00:55 2016 +0100 +++ b/src/main/java/de/intevation/lada/model/Probe.java Fri Mar 11 13:59:16 2016 +0100 @@ -50,6 +50,9 @@ @Column(name="mst_id") private String mstId; + @Column(name="labor_mst_id") + private String laborMstId; + @Column(name="netzbetreiber_id") private String netzbetreiberId; @@ -134,6 +137,20 @@ this.mstId = mstId; } + /** + * @return the laborMstId + */ + public String getLaborMstId() { + return laborMstId; + } + + /** + * @param laborMstId the laborMstId to set + */ + public void setLaborMstId(String laborMstId) { + this.laborMstId = laborMstId; + } + public String getNetzbetreiberId() { return this.netzbetreiberId; }
--- a/src/main/java/de/intevation/lada/rest/UserService.java Wed Mar 09 17:00:55 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/UserService.java Fri Mar 11 13:59:16 2016 +0100 @@ -95,7 +95,7 @@ response.put("roles", request.getAttribute("lada.user.roles")); response.put("servertime", new Date().getTime()); UserInfo userInfo = authorization.getInfo(request); - response.put("mst", userInfo.getMessstellen()); + response.put("messstelleLabor", userInfo.getMessLaborId()); response.put("netzbetreiber", userInfo.getNetzbetreiber()); response.put("funktionen", userInfo.getFunktionen()); return new Response(true, 200, response);
--- a/src/main/java/de/intevation/lada/util/auth/MessungAuthorizer.java Wed Mar 09 17:00:55 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/MessungAuthorizer.java Fri Mar 11 13:59:16 2016 +0100 @@ -84,7 +84,7 @@ messung.setReadonly(true); return messung; } - if (userInfo.getMessstellen().contains(probe.getMstId())) { + if (userInfo.belongsTo(probe.getMstId(), probe.getLaborMstId())) { messung.setOwner(true); } else { @@ -128,7 +128,7 @@ statusEdit = true; } else if (userInfo.getFunktionen().contains(1) && - userInfo.getMessstellen().contains(probe.getMstId()) && + userInfo.belongsTo(probe.getMstId(), probe.getLaborMstId()) && (status.getStatusStufe() <= 1 || status.getStatusWert() == 4) ) { statusEdit = true;
--- a/src/main/java/de/intevation/lada/util/auth/MessungIdAuthorizer.java Wed Mar 09 17:00:55 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/MessungIdAuthorizer.java Fri Mar 11 13:59:16 2016 +0100 @@ -115,7 +115,7 @@ readOnly = true; } else { - if (userInfo.getMessstellen().contains(probe.getMstId())) { + if (userInfo.belongsTo(probe.getMstId(), probe.getLaborMstId())) { owner = true; } else {
--- a/src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java Wed Mar 09 17:00:55 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java Fri Mar 11 13:59:16 2016 +0100 @@ -65,7 +65,7 @@ probe.setReadonly(true); return probe; } - if (userInfo.getMessstellen().contains(probe.getMstId())) { + if (userInfo.belongsTo(probe.getMstId(), probe.getLaborMstId())) { probe.setOwner(true); } else {
--- a/src/main/java/de/intevation/lada/util/auth/ProbeIdAuthorizer.java Wed Mar 09 17:00:55 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/ProbeIdAuthorizer.java Fri Mar 11 13:59:16 2016 +0100 @@ -98,7 +98,7 @@ readOnly = true; } else { - if (userInfo.getMessstellen().contains(probe.getMstId())) { + if (userInfo.belongsTo(probe.getMstId(), probe.getLaborMstId())) { owner = true; } else {
--- a/src/main/java/de/intevation/lada/util/auth/UserInfo.java Wed Mar 09 17:00:55 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/UserInfo.java Fri Mar 11 13:59:16 2016 +0100 @@ -25,6 +25,39 @@ private List<Integer> funktionen; private List<Auth> auth; + public class MessLaborId { + private String messstelle; + private String labor; + + /** + * @return the messstelle + */ + public String getMessstelle() { + return messstelle; + } + + /** + * @param messstelle the messstelle to set + */ + public void setMessstelle(String messstelle) { + this.messstelle = messstelle; + } + + /** + * @return the labor + */ + public String getLabor() { + return labor; + } + + /** + * @param labor the labor to set + */ + public void setLabor(String labor) { + this.labor = labor; + } + } + public UserInfo() { messstellen = new ArrayList<String>(); netzbetreiber = new ArrayList<String>(); @@ -58,6 +91,31 @@ this.userId = userId; } + public List<MessLaborId> getMessLaborId() { + List<MessLaborId> ret = new ArrayList<MessLaborId>(); + for (Auth a : auth) { + if (a.getMstId() != null) { + MessLaborId id = new MessLaborId(); + id.setMessstelle(a.getMstId()); + id.setLabor(a.getLaborMstId()); + ret.add(id); + } + } + return ret; + } + + public boolean belongsTo(String messstelle, String labor) { + for (Auth a : auth) { + if (a.getMstId().contains(messstelle) && + a.getLaborMstId() != null && + labor != null && + a.getLaborMstId().contains(labor)) { + return true; + } + } + return false; + } + /** * @return the messstellen */ @@ -72,6 +130,19 @@ } /** + * @return the labor messstellen + */ + public List<String> getLaborMessstellen() { + List<String> ret = new ArrayList<String>(); + for (Auth a : auth) { + if (a.getLaborMstId() != null) { + ret.add(a.getLaborMstId()); + } + } + return ret; + } + + /** * @return the netzbetreiber */ public List<String> getNetzbetreiber() {