You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/09/07 20:00:28 UTC

svn commit: r573650 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java

Author: jaz
Date: Fri Sep  7 11:00:27 2007
New Revision: 573650

URL: http://svn.apache.org/viewvc?rev=573650&view=rev
Log:
changed toSring() method to NOT display encyrpted fields for security; add new toStringInsecure() to get the insecure string value

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java?rev=573650&r1=573649&r2=573650&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java Fri Sep  7 11:00:27 2007
@@ -55,7 +55,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-
+import org.ofbiz.base.crypto.HashCrypt;
 /**
  * Generic Entity Value Object - Handles persisntence for any defined entity.
  * <p>Note that this class extends <code>Observable</code> to achieve change notification for
@@ -1140,12 +1140,47 @@
         return cachedHashCode;
     }
 
-    /** Creates a String for the entity, overrides the default toString
-     *@return    String corresponding to this entity
+    /**
+     * Creates a String for the entity, overrides the default toString
+     * This method is secure, it will not display encrypted fields
+     *
+     *@return String corresponding to this entity
      */
     public String toString() {
         StringBuffer theString = new StringBuffer();
+        theString.append("[GenericEntity:");
+        theString.append(getEntityName());
+        theString.append(']');
+
+        Iterator keyNames = new TreeSet(fields.keySet()).iterator();
+        while (keyNames.hasNext()) {
+            String curKey = (String) keyNames.next();
+            Object curValue = fields.get(curKey);
+            ModelField field = this.getModelEntity().getField(curKey);
+            if (field.getEncrypt()) {
+                String encryptField = (String) curValue;
+                curValue = HashCrypt.getDigestHash(encryptField);
+            }
+            theString.append('[');
+            theString.append(curKey);
+            theString.append(',');
+            theString.append(curValue);
+            theString.append('(');
+            theString.append(curValue != null ? curValue.getClass().getName() : "");
+            theString.append(')');
+            theString.append(']');
+        }
+        return theString.toString();
+    }
 
+    /**
+     * Creates a String for the entity, overrides the default toString
+     * This method is NOT secure, it WILL display encrypted fields
+     *
+     *@return String corresponding to this entity
+     */
+    public String toStringInsecure() {
+        StringBuffer theString = new StringBuffer();
         theString.append("[GenericEntity:");
         theString.append(getEntityName());
         theString.append(']');