Author: doogie
Date: Tue Jun 24 00:24:22 2014 New Revision: 1604976 URL: http://svn.apache.org/r1604976 Log: Remove encryptConditionFields from the condition objects; now, the encryption/decryption happens at the jdbc layer, when values are set into a PreparedStatement, or fetched from a ResultSet. This means that conditions are no longer munged to contain the encrypted value, and entities are no longer updated to temporarily contain the encrypted value. In all cases, the value of a field in memory will be unecncrypted. This fixes the following code patterns: person = delegator.create("Person", [partyId: "my-party"]); person.socialSecurityNumber = "1234"; person.store(); // this fails, the encrypted value is stored inside entity assertEquals("1234", person.socialSecurityNumber); currentValue = person.socialSecurityNumber person.store(); // this fails, the field is doubly-encrypted assertEquals(currentValue, person.socialSecurityNumber); origCondition = EntityCondition.makeCondition( "socialSecurityNumber", EntityOperator.EQUALS, "1234" ); list = delegator.findList("Person", origCondition); newCondition = EntityCondition.makeCondition( "socialSecurityNumber", EntityOperator.EQUALS, "1234" ); // this fails, because the condition is updated in-place, with the // encrypted field value. assertEquals(origCondition, newCondition); Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBuilder.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java Tue Jun 24 00:24:22 2014 @@ -141,10 +141,7 @@ public class FinAccountHelper { finAccountCode = finAccountCode.toUpperCase().replaceAll("[^0-9A-Z]", ""); // now we need to get the encrypted version of the fin account code the user passed in to look up against FinAccount - // we do this by making a temporary generic entity with same finAccountCode and then doing a match - GenericValue encryptedFinAccount = delegator.makeValue("FinAccount", UtilMisc.toMap("finAccountCode", finAccountCode)); - delegator.encryptFields(encryptedFinAccount); - String encryptedFinAccountCode = encryptedFinAccount.getString("finAccountCode"); + String encryptedFinAccountCode = (String) delegator.encryptFieldValue("FinAccount", finAccountCode); // now look for the account List<GenericValue> accounts = delegator.findByAnd("FinAccount", UtilMisc.toMap("finAccountCode", encryptedFinAccountCode), null, false); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java Tue Jun 24 00:24:22 2014 @@ -257,14 +257,20 @@ public interface Delegator { */ public GenericValue createSingle(String entityName, Object singlePkValue) throws GenericEntityException; + @Deprecated public void decryptFields(GenericEntity entity) throws GenericEntityException; + @Deprecated public void decryptFields(List<? extends GenericEntity> entities) throws GenericEntityException; + @Deprecated public void encryptFields(GenericEntity entity) throws GenericEntityException; + @Deprecated public void encryptFields(List<? extends GenericEntity> entities) throws GenericEntityException; + public Object decryptFieldValue(String entityName, String encValue) throws EntityCryptoException; + @Deprecated public Object encryptFieldValue(String entityName, Object fieldValue) throws EntityCryptoException; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Tue Jun 24 00:24:22 2014 @@ -798,7 +798,6 @@ public class GenericDelegator implements ecaRunner.evalRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_CREATE, value, false); value.setDelegator(this); - this.encryptFields(value); // if audit log on for any fields, save new value with no old value because it's a create if (value != null && value.getModelEntity().getHasFieldWithAuditLog()) { @@ -892,7 +891,6 @@ public class GenericDelegator implements ecaRunner.evalRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_CREATE, value, false); value.setDelegator(this); - this.encryptFields(value); // if audit log on for any fields, save new value with no old value because it's a create if (value != null && value.getModelEntity().getHasFieldWithAuditLog()) { @@ -1196,7 +1194,7 @@ public class GenericDelegator implements removedEntities = this.findList(entityName, condition, null, null, null, false); } - int rowsAffected = helper.removeByCondition(modelEntity, condition); + int rowsAffected = helper.removeByCondition(this, modelEntity, condition); if (testMode) { for (GenericValue entity : removedEntities) { @@ -1310,7 +1308,7 @@ public class GenericDelegator implements updatedEntities = this.findList(entityName, condition, null, null, null, false); } - int rowsAffected = helper.storeByCondition(modelEntity, fieldsToSet, condition); + int rowsAffected = helper.storeByCondition(this, modelEntity, fieldsToSet, condition); if (testMode) { for (GenericValue entity : updatedEntities) { @@ -1353,7 +1351,6 @@ public class GenericDelegator implements GenericHelper helper = getEntityHelper(value.getEntityName()); ecaRunner.evalRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_STORE, value, false); - this.encryptFields(value); // if audit log on for any fields, save old value before the update so we still have both if (value.getModelEntity().getHasFieldWithAuditLog()) { @@ -1439,7 +1436,6 @@ public class GenericDelegator implements GenericValue existing = null; try { existing = helper.findByPrimaryKey(primaryKey); - this.decryptFields(existing); } catch (GenericEntityNotFoundException e) { existing = null; } @@ -1586,7 +1582,6 @@ public class GenericDelegator implements } if (value != null) { value.setDelegator(this); - this.decryptFields(value); } if (useCache) { @@ -1770,16 +1765,14 @@ public class GenericDelegator implements if (whereEntityCondition != null) { whereEntityCondition.checkCondition(modelEntity); - whereEntityCondition = whereEntityCondition.encryptConditionFields(modelEntity, this); } if (havingEntityCondition != null) { havingEntityCondition.checkCondition(modelEntity); - havingEntityCondition = havingEntityCondition.encryptConditionFields(modelEntity, this); } ecaRunner.evalRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, false); GenericHelper helper = getEntityHelper(modelEntity.getEntityName()); - EntityListIterator eli = helper.findListIteratorByCondition(modelEntity, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderBy, findOptions); + EntityListIterator eli = helper.findListIteratorByCondition(this, modelEntity, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderBy, findOptions); eli.setDelegator(this); ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, false); @@ -1851,7 +1844,7 @@ public class GenericDelegator implements if (havingEntityCondition != null) havingEntityCondition.checkCondition(modelViewEntity); GenericHelper helper = getEntityHelper(dynamicViewEntity.getOneRealEntityName()); - EntityListIterator eli = helper.findListIteratorByCondition(modelViewEntity, whereEntityCondition, + EntityListIterator eli = helper.findListIteratorByCondition(this, modelViewEntity, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderBy, findOptions); eli.setDelegator(this); //TODO: add decrypt fields @@ -1878,16 +1871,14 @@ public class GenericDelegator implements if (whereEntityCondition != null) { whereEntityCondition.checkCondition(modelEntity); - whereEntityCondition = whereEntityCondition.encryptConditionFields(modelEntity, this); } if (havingEntityCondition != null) { havingEntityCondition.checkCondition(modelEntity); - havingEntityCondition = havingEntityCondition.encryptConditionFields(modelEntity, this); } ecaRunner.evalRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, false); GenericHelper helper = getEntityHelper(modelEntity.getEntityName()); - long count = helper.findCountByCondition(modelEntity, whereEntityCondition, havingEntityCondition, findOptions); + long count = helper.findCountByCondition(this, modelEntity, whereEntityCondition, havingEntityCondition, findOptions); ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, false); TransactionUtil.commit(beganTransaction); @@ -2625,36 +2616,16 @@ public class GenericDelegator implements * @see org.ofbiz.entity.Delegator#encryptFields(java.util.List) */ @Override + @Deprecated public void encryptFields(List<? extends GenericEntity> entities) throws GenericEntityException { - if (entities != null) { - for (GenericEntity entity: entities) { - this.encryptFields(entity); - } - } } /* (non-Javadoc) * @see org.ofbiz.entity.Delegator#encryptFields(org.ofbiz.entity.GenericEntity) */ @Override + @Deprecated public void encryptFields(GenericEntity entity) throws GenericEntityException { - ModelEntity model = entity.getModelEntity(); - String entityName = model.getEntityName(); - - Iterator<ModelField> i = model.getFieldsIterator(); - while (i.hasNext()) { - ModelField field = i.next(); - ModelField.EncryptMethod encryptMethod = field.getEncryptMethod(); - if (encryptMethod.isEncrypted()) { - Object obj = entity.get(field.getName()); - if (obj != null) { - if (obj instanceof String && UtilValidate.isEmpty(obj)) { - continue; - } - entity.dangerousSetNoCheckButFast(field, this.encryptFieldValue(entityName, encryptMethod, obj)); - } - } - } } /* (non-Javadoc) @@ -2681,49 +2652,30 @@ public class GenericDelegator implements } /* (non-Javadoc) + * @see org.ofbiz.entity.Delegator#encryptFieldValue(java.lang.String, java.lang.Object) + */ + @Override + public Object decryptFieldValue(String entityName, String encValue) throws EntityCryptoException { + if (UtilValidate.isNotEmpty(encValue)) { + return this.crypto.decrypt(entityName, encValue); + } + return null; + } + + /* (non-Javadoc) * @see org.ofbiz.entity.Delegator#decryptFields(java.util.List) */ @Override + @Deprecated public void decryptFields(List<? extends GenericEntity> entities) throws GenericEntityException { - if (entities != null) { - for (GenericEntity entity: entities) { - this.decryptFields(entity); - } - } } /* (non-Javadoc) * @see org.ofbiz.entity.Delegator#decryptFields(org.ofbiz.entity.GenericEntity) */ @Override + @Deprecated public void decryptFields(GenericEntity entity) throws GenericEntityException { - ModelEntity model = entity.getModelEntity(); - String entityName = model.getEntityName(); - - Iterator<ModelField> i = model.getFieldsIterator(); - while (i.hasNext()) { - ModelField field = i.next(); - ModelField.EncryptMethod encryptMethod = field.getEncryptMethod(); - if (encryptMethod.isEncrypted()) { - String keyName = entityName; - if (model instanceof ModelViewEntity) { - ModelViewEntity modelView = (ModelViewEntity) model; - keyName = modelView.getAliasedEntity(modelView.getAlias(field.getName()).getEntityAlias(), modelReader).getEntityName(); - } - - String encValue = (String) entity.get(field.getName()); - if (UtilValidate.isNotEmpty(encValue)) { - try { - entity.dangerousSetNoCheckButFast(field, crypto.decrypt(keyName, encValue)); - } catch (EntityCryptoException e) { - // not fatal -- allow returning of the encrypted value - if (Debug.warningOn()) { - Debug.logWarning(e, "Problem decrypting field [" + entityName + " / " + field.getName() + "]", module); - } - } - } - } - } } /* (non-Javadoc) Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java Tue Jun 24 00:24:22 2014 @@ -135,8 +135,6 @@ public abstract class EntityCondition ex abstract public EntityCondition freeze(); - abstract public EntityCondition encryptConditionFields(ModelEntity modelEntity, Delegator delegator); - public void visit(EntityConditionVisitor visitor) { throw new IllegalArgumentException(getClass().getName() + ".visit not implemented"); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBuilder.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBuilder.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBuilder.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBuilder.java Tue Jun 24 00:24:22 2014 @@ -74,10 +74,6 @@ public class EntityConditionBuilder exte public EntityCondition freeze() { return condition.freeze(); } - - public EntityCondition encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - return condition.encryptConditionFields(modelEntity, delegator); - } } @Override Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java Tue Jun 24 00:24:22 2014 @@ -46,11 +46,6 @@ public abstract class EntityConditionFun public EntityCondition freeze() { return new NOT(condition.freeze()); } - @Override - public EntityCondition encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - // nothing to do here... - return this; - } } protected Integer idInt = null; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java Tue Jun 24 00:24:22 2014 @@ -97,22 +97,6 @@ public abstract class EntityConditionLis } @Override - public EntityCondition encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - List<T> newList = new ArrayList<T>(this.conditionList.size()); - boolean changed = false; - for (T cond: this.conditionList) { - EntityCondition newCondition = cond.encryptConditionFields(modelEntity, delegator); - changed |= newCondition != cond; - newList.add((T) newCondition); - } - if (changed) { - return operator.freeze(newList); - } else { - return this; - } - } - - @Override public boolean equals(Object obj) { if (!(obj instanceof EntityConditionListBase<?>)) return false; EntityConditionListBase<?> other = UtilGenerics.cast(obj); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java Tue Jun 24 00:24:22 2014 @@ -117,15 +117,6 @@ public class EntityConditionSubSelect ex return new EntityConditionSubSelect(localModelEntity, keyFieldName, (whereCond != null ? whereCond.freeze() : null), requireAll); } - @Override - public EntityConditionValue encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - EntityCondition newWhereCond = whereCond.encryptConditionFields(modelEntity, delegator); - if (newWhereCond != whereCond) { - return new EntityConditionSubSelect(localModelEntity, keyFieldName, newWhereCond, requireAll); - } - return this; - } - public String getKeyFieldName() { return this.keyFieldName; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java Tue Jun 24 00:24:22 2014 @@ -60,11 +60,6 @@ public abstract class EntityConditionVal } @Override - public EntityConditionValue encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - return this; - } - - @Override public ModelField getModelField(ModelEntity modelEntity) { return null; } @@ -107,8 +102,6 @@ public abstract class EntityConditionVal public abstract EntityConditionValue freeze(); - public abstract EntityConditionValue encryptConditionFields(ModelEntity modelEntity, Delegator delegator); - public abstract void visit(EntityConditionVisitor visitor); public void accept(EntityConditionVisitor visitor) { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java Tue Jun 24 00:24:22 2014 @@ -94,12 +94,6 @@ public final class EntityDateFilterCondi return this; } - @Override - public EntityCondition encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - // nothing to do here... - return this; - } - protected EntityCondition makeCondition() { return makeCondition(UtilDateTime.nowTimestamp(), fromDateName, thruDateName); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java Tue Jun 24 00:24:22 2014 @@ -153,45 +153,6 @@ public final class EntityExpr extends En } @Override - public EntityCondition encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - if (rhs == null) { - return this; - } - if (operator.getClass().equals(EntityJoinOperator.class)) { - EntityCondition newLhs = ((EntityCondition) lhs).encryptConditionFields(modelEntity, delegator); - EntityCondition newRhs = ((EntityCondition) rhs).encryptConditionFields(modelEntity, delegator); - if (newLhs != lhs || newRhs != rhs) { - return EntityCondition.makeCondition(newLhs, UtilGenerics.<EntityJoinOperator>cast(this.operator), newRhs); - } - return this; - } - if (rhs instanceof EntityConditionValue) { - EntityConditionValue newRhs = ((EntityConditionValue) rhs).encryptConditionFields(modelEntity, delegator); - if (newRhs != rhs) { - return EntityCondition.makeCondition(this.lhs, (EntityComparisonOperator) this.operator, newRhs); - } else { - return this; - } - } - ModelField modelField; - if (this.lhs instanceof String) { - modelField = modelEntity.getField((String) this.lhs); - } else if (this.lhs instanceof EntityFieldValue) { - modelField = ((EntityFieldValue) this.lhs).getModelField(modelEntity); - } else { - return this; - } - if (modelField != null && modelField.getEncryptMethod().isEncrypted()) { - try { - return EntityCondition.makeCondition(this.lhs, (EntityComparisonOperator) this.operator, delegator.encryptFieldValue(modelEntity.getEntityName(), modelField.getEncryptMethod(), this.rhs)); - } catch (EntityCryptoException e) { - Debug.logWarning(e, "Error encrypting field [" + modelEntity.getEntityName() + "." + modelField.getName() + "] with value: " + this.rhs, module); - } - } - return this; - } - - @Override public void visit(EntityConditionVisitor visitor) { visitor.acceptEntityOperator(operator, lhs, rhs); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java Tue Jun 24 00:24:22 2014 @@ -194,9 +194,4 @@ public class EntityFieldValue extends En public EntityConditionValue freeze() { return this; } - - @Override - public EntityConditionValue encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - return this; - } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java Tue Jun 24 00:24:22 2014 @@ -119,32 +119,12 @@ public abstract class EntityFunction<T e protected EntityFunctionSingle(Fetcher<T> fetcher, SQLFunction function, Object value) { super(fetcher, function, value); } - - public EntityConditionValue encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - if (nested != null) { - EntityConditionValue newNested = nested.encryptConditionFields(modelEntity, delegator); - if (newNested != nested) { - return new EntityFunctionSingle<T>(fetcher, function, newNested) {}; - } - } else { - // FIXME - } - return this; - } } public static abstract class EntityFunctionNested<T extends Comparable<?>> extends EntityFunction<T> { protected EntityFunctionNested(Fetcher<T> fetcher, SQLFunction function, EntityConditionValue nested) { super(fetcher, function, nested); } - - public EntityConditionValue encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - EntityConditionValue newNested = nested.encryptConditionFields(modelEntity, delegator); - if (newNested != nested) { - return new EntityFunctionSingle<T>(fetcher, function, newNested) {}; - } - return this; - } } protected final SQLFunction function; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java Tue Jun 24 00:24:22 2014 @@ -82,12 +82,6 @@ public final class EntityWhereString ext } @Override - public EntityCondition encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { - // nothing to do here... - return this; - } - - @Override public void visit(EntityConditionVisitor visitor) { visitor.acceptEntityWhereString(this); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Tue Jun 24 00:24:22 2014 @@ -120,7 +120,7 @@ public class GenericDAO { throw new GenericModelException("Could not find ModelEntity record for entityName: " + entity.getEntityName()); } - SQLProcessor sqlP = new SQLProcessor(helperInfo); + SQLProcessor sqlP = new SQLProcessor(entity.getDelegator(), helperInfo); try { return singleInsert(entity, modelEntity, modelEntity.getFieldsUnmodifiable(), sqlP); @@ -225,7 +225,7 @@ public class GenericDAO { } private int customUpdate(GenericEntity entity, ModelEntity modelEntity, List<ModelField> fieldsToSave) throws GenericEntityException { - SQLProcessor sqlP = new SQLProcessor(helperInfo); + SQLProcessor sqlP = new SQLProcessor(entity.getDelegator(), helperInfo); try { return singleUpdate(entity, modelEntity, fieldsToSave, sqlP); } catch (GenericEntityException e) { @@ -302,8 +302,8 @@ public class GenericDAO { return retVal; } - public int updateByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { - SQLProcessor sqlP = new SQLProcessor(helperInfo); + public int updateByCondition(Delegator delegator, ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { + SQLProcessor sqlP = new SQLProcessor(delegator, helperInfo); try { return updateByCondition(modelEntity, fieldsToSet, condition, sqlP); @@ -497,7 +497,7 @@ public class GenericDAO { /* ====================================================================== */ public void select(GenericEntity entity) throws GenericEntityException { - SQLProcessor sqlP = new SQLProcessor(helperInfo); + SQLProcessor sqlP = new SQLProcessor(entity.getDelegator(), helperInfo); try { select(entity, sqlP); @@ -597,7 +597,7 @@ public class GenericDAO { sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, modelFieldTypeReader, datasource)); sqlBuffer.append(SqlJdbcUtil.makeWhereClause(modelEntity, modelEntity.getPkFieldsUnmodifiable(), entity, "AND", datasource.getJoinStyle())); - SQLProcessor sqlP = new SQLProcessor(helperInfo); + SQLProcessor sqlP = new SQLProcessor(entity.getDelegator(), helperInfo); try { sqlP.prepareStatement(sqlBuffer.toString(), true, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); @@ -633,7 +633,7 @@ public class GenericDAO { *@return EntityListIterator representing the result of the query: NOTE THAT THIS MUST BE CLOSED WHEN YOU ARE * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. */ - public EntityListIterator selectListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, + public EntityListIterator selectListIteratorByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException { if (modelEntity == null) { @@ -769,7 +769,7 @@ public class GenericDAO { // make the final SQL String String sql = sqlBuffer.toString(); - SQLProcessor sqlP = new SQLProcessor(helperInfo); + SQLProcessor sqlP = new SQLProcessor(delegator, helperInfo); sqlP.prepareStatement(sql, findOptions.getSpecifyTypeAndConcur(), findOptions.getResultSetType(), findOptions.getResultSetConcurrency(), findOptions.getFetchSize(), findOptions.getMaxRows()); @@ -912,7 +912,7 @@ public class GenericDAO { public List<GenericValue> selectByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) throws GenericEntityException { - SQLProcessor sqlP = new SQLProcessor(helperInfo); + SQLProcessor sqlP = new SQLProcessor(value.getDelegator(), helperInfo); // get the tables names String atable = modelEntityOne.getTableName(datasource); @@ -1013,11 +1013,11 @@ public class GenericDAO { return retlist; } - public long selectCountByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { - return selectCountByCondition(modelEntity, whereEntityCondition, havingEntityCondition, null, findOptions); + public long selectCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { + return selectCountByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, null, findOptions); } - public long selectCountByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, List<ModelField> selectFields, EntityFindOptions findOptions) throws GenericEntityException { + public long selectCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, List<ModelField> selectFields, EntityFindOptions findOptions) throws GenericEntityException { if (modelEntity == null) { return 0; } @@ -1112,7 +1112,7 @@ public class GenericDAO { String sql = sqlBuffer.toString(); if (Debug.verboseOn()) Debug.logVerbose("Count select sql: " + sql, module); - SQLProcessor sqlP = new SQLProcessor(helperInfo); + SQLProcessor sqlP = new SQLProcessor(delegator, helperInfo); sqlP.prepareStatement(sql, findOptions.getSpecifyTypeAndConcur(), findOptions.getResultSetType(), findOptions.getResultSetConcurrency(), findOptions.getFetchSize(), findOptions.getMaxRows()); if (verboseOn) { @@ -1154,7 +1154,7 @@ public class GenericDAO { /* ====================================================================== */ public int delete(GenericEntity entity) throws GenericEntityException { - SQLProcessor sqlP = new SQLProcessor(helperInfo); + SQLProcessor sqlP = new SQLProcessor(entity.getDelegator(), helperInfo); try { return delete(entity, sqlP); @@ -1191,8 +1191,8 @@ public class GenericDAO { return retVal; } - public int deleteByCondition(ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException { - SQLProcessor sqlP = new SQLProcessor(helperInfo); + public int deleteByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException { + SQLProcessor sqlP = new SQLProcessor(delegator, helperInfo); try { return deleteByCondition(modelEntity, condition, sqlP); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java Tue Jun 24 00:24:22 2014 @@ -27,6 +27,7 @@ import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.Future; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericPK; import org.ofbiz.entity.GenericValue; @@ -93,11 +94,11 @@ public interface GenericHelper { *@return EntityListIterator representing the result of the query: NOTE THAT THIS MUST BE CLOSED WHEN YOU ARE * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. */ - public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, + public EntityListIterator findListIteratorByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException; - public long findCountByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, + public long findCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException; /** Removes/deletes Generic Entity records found by all the specified condition @@ -105,7 +106,7 @@ public interface GenericHelper { *@param condition The condition that restricts the list of removed values *@return int representing number of rows effected by this operation */ - public int removeByCondition(ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException; + public int removeByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException; /** Stores a group of values in a single query *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file @@ -114,7 +115,7 @@ public interface GenericHelper { *@return int representing number of rows effected by this operation *@throws GenericEntityException */ - public int storeByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException; + public int storeByCondition(Delegator delegator, ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException; /** Store the Entity from the GenericValue to the persistent store *@param value GenericValue instance containing the entity Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java Tue Jun 24 00:24:22 2014 @@ -27,6 +27,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericPK; import org.ofbiz.entity.GenericValue; @@ -139,10 +140,10 @@ public class GenericHelperDAO implements *@return EntityListIterator representing the result of the query: NOTE THAT THIS MUST BE CLOSED WHEN YOU ARE * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. */ - public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, + public EntityListIterator findListIteratorByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException { - return genericDAO.selectListIteratorByCondition(modelEntity, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderBy, findOptions); + return genericDAO.selectListIteratorByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderBy, findOptions); } public List<GenericValue> findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, @@ -150,8 +151,8 @@ public class GenericHelperDAO implements return genericDAO.selectByMultiRelation(value, modelRelationOne, modelEntityOne, modelRelationTwo, modelEntityTwo, orderBy); } - public long findCountByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { - return genericDAO.selectCountByCondition(modelEntity, whereEntityCondition, havingEntityCondition, findOptions); + public long findCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { + return genericDAO.selectCountByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, findOptions); } /** Removes/deletes Generic Entity records found by all the specified condition @@ -159,11 +160,11 @@ public class GenericHelperDAO implements *@param condition The condition that restricts the list of removed values *@return int representing number of rows effected by this operation */ - public int removeByCondition(ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException { + public int removeByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException { if (modelEntity == null || condition == null) { return 0; } - return genericDAO.deleteByCondition(modelEntity, condition); + return genericDAO.deleteByCondition(delegator, modelEntity, condition); } /** Store the Entity from the GenericValue to the persistent store @@ -184,11 +185,11 @@ public class GenericHelperDAO implements *@return int representing number of rows effected by this operation *@throws GenericEntityException */ - public int storeByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { + public int storeByCondition(Delegator delegator, ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { if (modelEntity == null || condition == null) { return 0; } - return genericDAO.updateByCondition(modelEntity, fieldsToSet, condition); + return genericDAO.updateByCondition(delegator, modelEntity, fieldsToSet, condition); } /** Check the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the server Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java Tue Jun 24 00:24:22 2014 @@ -33,6 +33,7 @@ import java.util.concurrent.ExecutorServ import org.ofbiz.base.concurrent.ExecutionPool; import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericNotImplementedException; import org.ofbiz.entity.GenericPK; @@ -382,13 +383,13 @@ public class MemoryHelper implements Gen return null; } - public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, + public EntityListIterator findListIteratorByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException { return null; } - public long findCountByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { + public long findCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { return 0; } @@ -409,11 +410,11 @@ public class MemoryHelper implements Gen return removeAll(removeList); } - public int removeByCondition(ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException { + public int removeByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException { return removeFromCache(modelEntity.getEntityName(), condition); } - public int storeByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { + public int storeByCondition(Delegator delegator, ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { return 0; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java Tue Jun 24 00:24:22 2014 @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.List; import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericDataSourceException; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.config.model.Datasource; @@ -58,6 +59,8 @@ public class SQLProcessor { public static int MAX_CONNECTIONS = 1000; public static boolean ENABLE_TEST = false; + private final Delegator delegator; + /** The datasource helper (see entityengine.xml <datasource name="..">) */ private GenericHelperInfo helperInfo; @@ -89,7 +92,8 @@ public class SQLProcessor { * * @param helperInfo The datasource helper (see entityengine.xml <datasource name="..">) */ - public SQLProcessor(GenericHelperInfo helperInfo) { + public SQLProcessor(Delegator delegator, GenericHelperInfo helperInfo) { + this.delegator = delegator; this.helperInfo = helperInfo; this._manualTX = true; } @@ -101,7 +105,8 @@ public class SQLProcessor { * @param helperInfo The datasource helper (see entityengine.xml <datasource name="..">) * @param connection The connection to be used */ - public SQLProcessor(GenericHelperInfo helperInfo, Connection connection) { + public SQLProcessor(Delegator delegator, GenericHelperInfo helperInfo, Connection connection) { + this.delegator = delegator; this.helperInfo = helperInfo; this._connection = connection; @@ -111,6 +116,10 @@ public class SQLProcessor { } } + public Delegator getDelegator() { + return delegator; + } + ResultSetMetaData getResultSetMetaData() { if (_rsmd == null) { // try the ResultSet, if not null, or try the PreparedStatement, also if not null Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java Tue Jun 24 00:24:22 2014 @@ -526,12 +526,23 @@ public class SqlJdbcUtil { entity.getEntityName() + "." + curField.getName() + "."); } + ModelEntity model = entity.getModelEntity(); + String encryptionKeyName = entity.getEntityName(); + if (curField.getEncryptMethod().isEncrypted() && model instanceof ModelViewEntity) { + ModelViewEntity modelView = (ModelViewEntity) model; + encryptionKeyName = modelView.getAliasedEntity(modelView.getAlias(curField.getName()).getEntityAlias(), entity.getDelegator().getModelReader()).getEntityName(); + } + // ----- Try out the new handler code ----- JdbcValueHandler<?> handler = mft.getJdbcValueHandler(); if (handler != null) { try { - entity.dangerousSetNoCheckButFast(curField, handler.getValue(rs, ind)); + Object jdbcValue = handler.getValue(rs, ind); + if (jdbcValue instanceof String && curField.getEncryptMethod().isEncrypted()) { + jdbcValue = entity.getDelegator().decryptFieldValue(encryptionKeyName, (String) jdbcValue); + } + entity.dangerousSetNoCheckButFast(curField, jdbcValue); return; } catch (Exception e) { Debug.logError(e, module); @@ -585,6 +596,9 @@ public class SqlJdbcUtil { } } else { String value = rs.getString(ind); + if (value instanceof String && curField.getEncryptMethod().isEncrypted()) { + value = (String) entity.getDelegator().decryptFieldValue(encryptionKeyName, value); + } entity.dangerousSetNoCheckButFast(curField, value); } break; @@ -777,6 +791,10 @@ public class SqlJdbcUtil { // ----- Try out the new handler code ----- + ModelField.EncryptMethod encryptMethod = modelField.getEncryptMethod(); + if (encryptMethod.isEncrypted()) { + fieldValue = sqlP.getDelegator().encryptFieldValue(entityName, encryptMethod, fieldValue); + } JdbcValueHandler<T> handler = UtilGenerics.cast(mft.getJdbcValueHandler()); if (handler != null) { try { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java Tue Jun 24 00:24:22 2014 @@ -70,7 +70,7 @@ public class EntityCryptoTestSuite exten entity.setString("encryptedValue", nanoTime); entity.setString("saltedEncryptedValue", nanoTime); entity.store(); - entity.refresh(); // this is a bug; store() ends up setting the encrypted value *into* the entity + //entity.refresh(); // this is a bug; store() ends up setting the encrypted value *into* the entity assertEquals(nanoTime, entity.getString("unencryptedValue")); assertEquals(nanoTime, entity.getString("encryptedValue")); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java?rev=1604976&r1=1604975&r2=1604976&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java Tue Jun 24 00:24:22 2014 @@ -181,9 +181,6 @@ public class EntityListIterator implemen value.setDelegator(this.delegator); value.synchronizedWithDatasource(); this.haveMadeValue = true; - if (delegator != null) { - delegator.decryptFields(value); - } return value; } @@ -498,7 +495,7 @@ public class EntityListIterator implemen efo = new EntityFindOptions(); efo.setDistinct(distinctQuery); } - resultSize = (int) genericDAO.selectCountByCondition(modelEntity, whereCondition, havingCondition, selectFields, efo); + resultSize = (int) genericDAO.selectCountByCondition(sqlp.getDelegator(), modelEntity, whereCondition, havingCondition, selectFields, efo); } return resultSize; } else if (this.last()) { |
Free forum by Nabble | Edit this page |