← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21644: Added encryption for TEAVAudit when TEAVs are confidential; Same implementation as in TEAV

 

Merge authors:
  Stian Sandvold (stian-sandvold)
------------------------------------------------------------
revno: 21644 [merge]
committer: Stian Sandvold <stian.sandvold@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-01-07 13:17:43 +0100
message:
  Added encryption for TEAVAudit when TEAVs are confidential; Same implementation as in TEAV
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValue.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAudit.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValue.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueAudit.hbm.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValue.java	2016-01-04 10:26:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValue.java	2016-01-07 12:15:33 +0000
@@ -76,7 +76,6 @@
      */
     private String value;
 
-
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -91,7 +90,8 @@
         setEntityInstance( entityInstance );
     }
 
-    public TrackedEntityAttributeValue( TrackedEntityAttribute attribute, TrackedEntityInstance entityInstance, String value )
+    public TrackedEntityAttributeValue( TrackedEntityAttribute attribute, TrackedEntityInstance entityInstance,
+        String value )
     {
         setAttribute( attribute );
         setEntityInstance( entityInstance );
@@ -187,7 +187,8 @@
     @Override
     public String toString()
     {
-        return "[Tracked attribute=" + attribute + ", entityInstance=" + entityInstance + ", value='" + getValue() + "']";
+        return "[Tracked attribute=" + attribute + ", entityInstance=" + entityInstance + ", value='" + getValue() +
+            "']";
     }
 
     // -------------------------------------------------------------------------
@@ -269,8 +270,8 @@
     }
 
     /**
-     * Property which temporarily stores the attribute value. The 
-     * {@link getEncryptedValue} and {@link getPlainValue} methods handle the 
+     * Property which temporarily stores the attribute value. The
+     * {@link getEncryptedValue} and {@link getPlainValue} methods handle the
      * value when requested.
      *
      * @param value the value to be stored.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAudit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAudit.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAudit.java	2016-01-07 12:15:33 +0000
@@ -55,23 +55,32 @@
 
     private Date created;
 
-    private String value;
+    private String plainValue;
+
+    private String encryptedValue;
 
     private String modifiedBy;
 
     private AuditType auditType;
 
+    /**
+     * This value is only used to store values from setValue when we don't know
+     * if attribute is set or not.
+     */
+    private String value;
+
     public TrackedEntityAttributeValueAudit()
     {
     }
 
-    public TrackedEntityAttributeValueAudit( TrackedEntityAttributeValue trackedEntityAttributeValue, String value, String modifiedBy, AuditType auditType )
+    public TrackedEntityAttributeValueAudit( TrackedEntityAttributeValue trackedEntityAttributeValue, String value,
+        String modifiedBy, AuditType auditType )
     {
         this.attribute = trackedEntityAttributeValue.getAttribute();
         this.entityInstance = trackedEntityAttributeValue.getEntityInstance();
 
         this.created = new Date();
-        this.value = value;
+        setValue( value );
         this.modifiedBy = modifiedBy;
         this.auditType = auditType;
     }
@@ -79,7 +88,7 @@
     @Override
     public int hashCode()
     {
-        return Objects.hash( attribute, entityInstance, created, value, modifiedBy, auditType );
+        return Objects.hash( attribute, entityInstance, created, getValue(), modifiedBy, auditType );
     }
 
     @Override
@@ -100,7 +109,7 @@
         return Objects.equals( this.attribute, other.attribute )
             && Objects.equals( this.entityInstance, other.entityInstance )
             && Objects.equals( this.created, other.created )
-            && Objects.equals( this.value, other.value )
+            && Objects.equals( this.getValue(), other.getValue() )
             && Objects.equals( this.modifiedBy, other.modifiedBy )
             && Objects.equals( this.auditType, other.auditType );
     }
@@ -115,6 +124,26 @@
         this.id = id;
     }
 
+    public String getPlainValue()
+    {
+        return (!getAttribute().getConfidential() && this.value != null ? this.value : this.plainValue);
+    }
+
+    public void setPlainValue( String plainValue )
+    {
+        this.plainValue = plainValue;
+    }
+
+    public String getEncryptedValue()
+    {
+        return (getAttribute().getConfidential() && this.value != null ? this.value : this.encryptedValue);
+    }
+
+    public void setEncryptedValue( String encryptedValue )
+    {
+        this.encryptedValue = encryptedValue;
+    }
+
     @JsonProperty( "trackedEntityAttribute" )
     @JacksonXmlProperty( localName = "trackedEntityAttribute", namespace = DxfNamespaces.DXF_2_0 )
     public TrackedEntityAttribute getAttribute()
@@ -155,9 +184,16 @@
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getValue()
     {
-        return value;
+        return (getAttribute().getConfidential() ? this.getEncryptedValue() : this.getPlainValue());
     }
 
+    /**
+     * Property which temporarily stores the attribute value. The
+     * {@link getEncryptedValue} and {@link getPlainValue} methods handle the
+     * value when requested.
+     *
+     * @param value the value to be stored.
+     */
     public void setValue( String value )
     {
         this.value = value;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValue.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValue.hbm.xml	2016-01-04 10:26:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValue.hbm.xml	2016-01-07 12:15:33 +0000
@@ -1,25 +1,29 @@
 <?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping PUBLIC
-  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
-  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
 
 <hibernate-mapping>
-  <class name="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue" table="trackedentityattributevalue">
-
-    <composite-id>
-      <key-many-to-one name="entityInstance" class="org.hisp.dhis.trackedentity.TrackedEntityInstance" column="trackedentityinstanceid"
-        foreign-key="fk_attributevalue_trackedentityinstanceid" />
-      <key-many-to-one name="attribute" class="org.hisp.dhis.trackedentity.TrackedEntityAttribute" column="trackedentityattributeid"
-        foreign-key="fk_attributevalue_trackedentityattributeid" />
-    </composite-id>
-
-    <property name="created" type="timestamp" />
-
-    <property name="lastUpdated" type="timestamp" />
-
-    <property name="plainValue" column="value" access="property" length="50000" />
-
-    <property name="encryptedValue" column="encryptedvalue" access="property" type="AESEncryptedString" />
-
-  </class>
+    <class name="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue"
+           table="trackedentityattributevalue">
+
+        <composite-id>
+            <key-many-to-one name="entityInstance" class="org.hisp.dhis.trackedentity.TrackedEntityInstance"
+                             column="trackedentityinstanceid"
+                             foreign-key="fk_attributevalue_trackedentityinstanceid"/>
+            <key-many-to-one name="attribute" class="org.hisp.dhis.trackedentity.TrackedEntityAttribute"
+                             column="trackedentityattributeid"
+                             foreign-key="fk_attributevalue_trackedentityattributeid"/>
+        </composite-id>
+
+        <property name="created" type="timestamp"/>
+
+        <property name="lastUpdated" type="timestamp"/>
+
+        <property name="plainValue" column="value" access="property" length="50000"/>
+
+        <property name="encryptedValue" column="encryptedvalue" access="property" type="AESEncryptedString"
+                  length="50000"/>
+
+    </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueAudit.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueAudit.hbm.xml	2015-12-07 12:49:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueAudit.hbm.xml	2016-01-07 12:15:33 +0000
@@ -1,33 +1,39 @@
 <?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping PUBLIC
-  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
-  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
 
 <hibernate-mapping>
-  <class name="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit" table="trackedentityattributevalueaudit">
-
-    <id name="id" column="trackedentityattributevalueauditid">
-      <generator class="native" />
-    </id>
-
-    <many-to-one name="entityInstance" class="org.hisp.dhis.trackedentity.TrackedEntityInstance" column="trackedentityinstanceid"
-      foreign-key="fk_attributevalueaudit_trackedentityinstanceid" />
-
-    <many-to-one name="attribute" class="org.hisp.dhis.trackedentity.TrackedEntityAttribute" column="trackedentityattributeid"
-      foreign-key="fk_attributevalueaudit_trackedentityattributeid" />
-
-    <property name="value" length="50000" />
-
-    <property name="created" type="timestamp" />
-
-    <property name="modifiedBy" />
-
-    <property name="auditType" column="audittype" length="100" not-null="true">
-      <type name="org.hibernate.type.EnumType">
-        <param name="enumClass">org.hisp.dhis.common.AuditType</param>
-        <param name="type">12</param>
-      </type>
-    </property>
-
-  </class>
+    <class name="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit"
+           table="trackedentityattributevalueaudit">
+
+        <id name="id" column="trackedentityattributevalueauditid">
+            <generator class="native"/>
+        </id>
+
+        <many-to-one name="entityInstance" class="org.hisp.dhis.trackedentity.TrackedEntityInstance"
+                     column="trackedentityinstanceid"
+                     foreign-key="fk_attributevalueaudit_trackedentityinstanceid"/>
+
+        <many-to-one name="attribute" class="org.hisp.dhis.trackedentity.TrackedEntityAttribute"
+                     column="trackedentityattributeid"
+                     foreign-key="fk_attributevalueaudit_trackedentityattributeid"/>
+
+        <property name="plainValue" column="value" access="property" length="50000"/>
+
+        <property name="encryptedValue" length="50000" column="encryptedvalue" access="property"
+                  type="AESEncryptedString"/>
+
+        <property name="created" type="timestamp"/>
+
+        <property name="modifiedBy"/>
+
+        <property name="auditType" column="audittype" length="100" not-null="true">
+            <type name="org.hibernate.type.EnumType">
+                <param name="enumClass">org.hisp.dhis.common.AuditType</param>
+                <param name="type">12</param>
+            </type>
+        </property>
+
+    </class>
 </hibernate-mapping>