mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1398 - Support EQ / "Equal to" predicate on client side encrypted entity property - @Encrypted(dbEncryption = false)
This commit is contained in:
@@ -78,6 +78,11 @@ public final class BeanFkeyProperty implements ElPropertyValue {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object localEncrypt(Object value) {
|
||||
throw new IllegalArgumentException("Should not get here?");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsFormulaWithJoin() {
|
||||
return false;
|
||||
|
||||
@@ -28,6 +28,7 @@ import io.ebeaninternal.server.query.STreeProperty;
|
||||
import io.ebeaninternal.server.query.SqlBeanLoad;
|
||||
import io.ebeaninternal.server.query.SqlJoinType;
|
||||
import io.ebeaninternal.server.type.DataBind;
|
||||
import io.ebeaninternal.server.type.LocalEncryptedType;
|
||||
import io.ebeaninternal.server.type.ScalarType;
|
||||
import io.ebeaninternal.server.type.ScalarTypeBoolean;
|
||||
import io.ebeaninternal.server.type.ScalarTypeEnum;
|
||||
@@ -1246,6 +1247,11 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
return dbBind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object localEncrypt(Object value) {
|
||||
return ((LocalEncryptedType)scalarType).localEncrypt(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if DB encrypted.
|
||||
*/
|
||||
|
||||
@@ -174,6 +174,11 @@ public class ElPropertyChain implements ElPropertyValue {
|
||||
return lastElPropertyValue.isLocalEncrypted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object localEncrypt(Object value) {
|
||||
return lastElPropertyValue.localEncrypt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAssocIsEmpty(SpiExpressionRequest request, String path) {
|
||||
return lastElPropertyValue.getAssocIsEmpty(request, path);
|
||||
|
||||
@@ -52,6 +52,11 @@ public interface ElPropertyValue extends ElPropertyDeploy, ExpressionPath {
|
||||
*/
|
||||
boolean isDbEncrypted();
|
||||
|
||||
/**
|
||||
* Encrypt the input value return the encrypted value.
|
||||
*/
|
||||
Object localEncrypt(Object value);
|
||||
|
||||
/**
|
||||
* Return the value ensuring objects prior to the top scalar property are
|
||||
* automatically populated.
|
||||
|
||||
@@ -84,10 +84,11 @@ public class SimpleExpression extends AbstractValueExpression {
|
||||
// bind the key as well as the value
|
||||
String encryptKey = prop.getBeanProperty().getEncryptKey().getStringValue();
|
||||
request.addBindEncryptKey(encryptKey);
|
||||
} else if (prop.isLocalEncrypted()) {
|
||||
Object bindVal = prop.localEncrypt(value());
|
||||
request.addBindEncryptKey(bindVal);
|
||||
return;
|
||||
}
|
||||
//else if (prop.isLocalEncrypted()) {
|
||||
// not supporting this for equals (but probably could)
|
||||
// prop.getBeanProperty().getScalarType();
|
||||
}
|
||||
|
||||
request.addBindValue(value());
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
/**
|
||||
* Scalar type that wraps a local/client side encrypted value.
|
||||
*/
|
||||
public interface LocalEncryptedType {
|
||||
|
||||
/**
|
||||
* Encrypt and return the un-encrypted value.
|
||||
*/
|
||||
Object localEncrypt(Object value);
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ScalarTypeEncryptedWrapper<T> implements ScalarType<T> {
|
||||
public class ScalarTypeEncryptedWrapper<T> implements ScalarType<T>, LocalEncryptedType {
|
||||
|
||||
private final ScalarType<T> wrapped;
|
||||
|
||||
@@ -23,6 +23,12 @@ public class ScalarTypeEncryptedWrapper<T> implements ScalarType<T> {
|
||||
this.dataEncryptSupport = dataEncryptSupport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object localEncrypt(Object value) {
|
||||
String formatValue = wrapped.format(value);
|
||||
return dataEncryptSupport.encryptObject(formatValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asVersion(T value) {
|
||||
throw new RuntimeException("not supported");
|
||||
|
||||
Reference in New Issue
Block a user