本文整理汇总了Java中org.ofbiz.entity.model.ModelField.getEncrypt方法的典型用法代码示例。如果您正苦于以下问题:Java ModelField.getEncrypt方法的具体用法?Java ModelField.getEncrypt怎么用?Java ModelField.getEncrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ofbiz.entity.model.ModelField
的用法示例。
在下文中一共展示了ModelField.getEncrypt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encryptFields
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
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();
if (field.getEncrypt()) {
Object obj = entity.get(field.getName());
if (obj != null) {
if (obj instanceof String && UtilValidate.isEmpty(obj)) {
continue;
}
entity.dangerousSetNoCheckButFast(field, this.encryptFieldValue(entityName, obj));
}
}
}
}
示例2: decryptFields
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
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();
if (field.getEncrypt()) {
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
Debug.logWarning(e, "Problem decrypting field [" + entityName + " / " + field.getName() + "]", module);
}
}
}
}
}
示例3: toString
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
/**
* 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
*/
@Override
public String toString() {
StringBuilder theString = new StringBuilder();
theString.append("[GenericEntity:");
theString.append(getEntityName());
theString.append(']');
for (String curKey: new TreeSet<String>(fields.keySet())) {
Object curValue = fields.get(curKey);
ModelField field = this.getModelEntity().getField(curKey);
if (field.getEncrypt() && curValue instanceof String) {
String encryptField = (String) curValue;
// the encryptField may not actually be UTF8, it could be any
// random encoding; just treat it as a series of raw bytes.
// This won't give the same output as the value stored in the
// database, but should be good enough for printing
curValue = HashCrypt.cryptBytes(null, null, encryptField.getBytes());
}
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();
}
示例4: encryptConditionFields
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
@Override
public void encryptConditionFields(ModelEntity modelEntity, Delegator delegator) {
if (this.lhs instanceof String) {
ModelField modelField = modelEntity.getField((String) this.lhs);
if (modelField != null && modelField.getEncrypt()) {
if (!(rhs instanceof EntityConditionValue)) {
try {
this.rhs = delegator.encryptFieldValue(modelEntity.getEntityName(), this.rhs);
} catch (EntityCryptoException e) {
Debug.logWarning(e, "Error encrypting field [" + modelEntity.getEntityName() + "." + modelField.getName() + "] with value: " + this.rhs, module);
}
}
}
}
}