[Lada-commits] [PATCH 1 of 2] Load probe attribute 'laborMstId' from db and use this field to authorize

Wald Commits scm-commit at wald.intevation.org
Fri Mar 11 14:00:13 CET 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1457701156 -3600
# Node ID f5b4784d91737eebe4ec11f4f030733f64d98b9b
# Parent  9258cce7bcbd9025cb2614fe5d7d90ef13d33b08
Load probe attribute 'laborMstId' from db and use this field to authorize
objects.

diff -r 9258cce7bcbd -r f5b4784d9173 src/main/java/de/intevation/lada/model/Probe.java
--- 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;
     }
diff -r 9258cce7bcbd -r f5b4784d9173 src/main/java/de/intevation/lada/rest/UserService.java
--- 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);
diff -r 9258cce7bcbd -r f5b4784d9173 src/main/java/de/intevation/lada/util/auth/MessungAuthorizer.java
--- 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;
diff -r 9258cce7bcbd -r f5b4784d9173 src/main/java/de/intevation/lada/util/auth/MessungIdAuthorizer.java
--- 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 {
diff -r 9258cce7bcbd -r f5b4784d9173 src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java
--- 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 {
diff -r 9258cce7bcbd -r f5b4784d9173 src/main/java/de/intevation/lada/util/auth/ProbeIdAuthorizer.java
--- 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 {
diff -r 9258cce7bcbd -r f5b4784d9173 src/main/java/de/intevation/lada/util/auth/UserInfo.java
--- 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() {


More information about the Lada-commits mailing list