mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
#2774 Locally encrypted properties can be used in "in" queries
This commit is contained in:
1 parent
4cc012b974
commit
c5612d50fe
3 files changed
+57
-27
No files matched your search
@@ -117,29 +117,39 @@ public final class InExpression extends AbstractExpression implements IdInCommon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ElPropertyValue prop = getElProp(request);
|
ElPropertyValue prop = getElProp(request);
|
||||||
if (prop != null && !prop.isAssocId()) {
|
|
||||||
prop = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prop == null) {
|
List<Object> values = bindValues;
|
||||||
if (bindValues.size() > 0) {
|
if (prop != null && prop.isAssocId()) {
|
||||||
// if we have no property, we wrap them in a multi value wrapper.
|
values = new ArrayList<>();
|
||||||
// later the binder will decide, which bind strategy to use.
|
|
||||||
request.addBindValue(new MultiValueWrapper(bindValues));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
List<Object> idList = new ArrayList<>();
|
|
||||||
for (Object bindValue : bindValues) {
|
for (Object bindValue : bindValues) {
|
||||||
// extract the id values from the bean
|
// extract the id values from the bean
|
||||||
Object[] ids = prop.assocIdValues((EntityBean) bindValue);
|
Object[] ids = prop.assocIdValues((EntityBean) bindValue);
|
||||||
if (ids != null) {
|
if (ids != null) {
|
||||||
Collections.addAll(idList, ids);
|
Collections.addAll(values, ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!idList.isEmpty()) {
|
|
||||||
request.addBindValue(new MultiValueWrapper(idList));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (values.isEmpty()) {
|
||||||
|
// nothing in in-query
|
||||||
|
return;
|
||||||
|
} else if (prop.isDbEncrypted()) {
|
||||||
|
// bind the key as well as the value
|
||||||
|
String encryptKey = prop.beanProperty().encryptKey().getStringValue();
|
||||||
|
request.addBindEncryptKey(encryptKey);
|
||||||
|
} else if (prop.isLocalEncrypted()) {
|
||||||
|
List<Object> encValues = new ArrayList<>(values.size());
|
||||||
|
for (Object value : values) {
|
||||||
|
encValues.add(prop.localEncrypt(value));
|
||||||
|
}
|
||||||
|
// this is most likely binary garbage, so don't add it to the bind log
|
||||||
|
request.addBindEncryptKey(new MultiValueWrapper(encValues));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we have no property, we wrap them in a multi value wrapper.
|
||||||
|
// later the binder will decide, which bind strategy to use.
|
||||||
|
request.addBindValue(new MultiValueWrapper(values));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -154,17 +164,22 @@ public final class InExpression extends AbstractExpression implements IdInCommon
|
|||||||
}
|
}
|
||||||
|
|
||||||
ElPropertyValue prop = getElProp(request);
|
ElPropertyValue prop = getElProp(request);
|
||||||
if (prop != null && !prop.isAssocId()) {
|
|
||||||
prop = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prop != null) {
|
if (prop != null) {
|
||||||
request.append(prop.assocIdInExpr(propName));
|
if (prop.isAssocId()) {
|
||||||
request.append(prop.assocIdInValueExpr(not, bindValues.size()));
|
request.append(prop.assocIdInExpr(propName));
|
||||||
} else {
|
request.append(prop.assocIdInValueExpr(not, bindValues.size()));
|
||||||
request.append(propName);
|
}
|
||||||
request.appendInExpression(not, bindValues);
|
if (prop.isDbEncrypted()) {
|
||||||
|
String dsql = prop.beanProperty().decryptProperty(propName);
|
||||||
|
request.append(dsql);
|
||||||
|
request.appendInExpression(not, bindValues);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
request.append(propName);
|
||||||
|
request.appendInExpression(not, bindValues);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package org.tests.basic.encrypt;
|
package org.tests.basic.encrypt;
|
||||||
|
|
||||||
import io.ebean.xtest.BaseTestCase;
|
|
||||||
import io.ebean.DB;
|
import io.ebean.DB;
|
||||||
import io.ebean.SqlRow;
|
import io.ebean.SqlRow;
|
||||||
import io.ebean.xtest.ForPlatform;
|
|
||||||
import io.ebean.xtest.IgnorePlatform;
|
|
||||||
import io.ebean.annotation.Platform;
|
import io.ebean.annotation.Platform;
|
||||||
import io.ebean.config.dbplatform.DbEncrypt;
|
import io.ebean.config.dbplatform.DbEncrypt;
|
||||||
import io.ebean.test.LoggedSql;
|
import io.ebean.test.LoggedSql;
|
||||||
|
import io.ebean.xtest.BaseTestCase;
|
||||||
|
import io.ebean.xtest.ForPlatform;
|
||||||
|
import io.ebean.xtest.IgnorePlatform;
|
||||||
import io.ebeaninternal.api.SpiEbeanServer;
|
import io.ebeaninternal.api.SpiEbeanServer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.model.basic.EBasicEncrypt;
|
import org.tests.model.basic.EBasicEncrypt;
|
||||||
@@ -149,6 +149,11 @@ public class TestEncrypt extends BaseTestCase {
|
|||||||
|
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
|
list = DB.find(EBasicEncrypt.class).where()
|
||||||
|
.in("description", "moddesc").findList();
|
||||||
|
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
list = DB.find(EBasicEncrypt.class).where().startsWith("description", "modde").findList();
|
list = DB.find(EBasicEncrypt.class).where().startsWith("description", "modde").findList();
|
||||||
|
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, list.size());
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.tests.basic.encrypt;
|
package org.tests.basic.encrypt;
|
||||||
|
|
||||||
import io.ebean.xtest.BaseTestCase;
|
|
||||||
import io.ebean.DB;
|
import io.ebean.DB;
|
||||||
|
import io.ebean.xtest.BaseTestCase;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.model.basic.EBasicEncryptClient;
|
import org.tests.model.basic.EBasicEncryptClient;
|
||||||
|
|
||||||
@@ -50,6 +50,16 @@ public class TestEncryptClientSide extends BaseTestCase {
|
|||||||
assertThat(found).isNotNull();
|
assertThat(found).isNotNull();
|
||||||
assertThat(found.getDescription()).isEqualTo("goodbye");
|
assertThat(found.getDescription()).isEqualTo("goodbye");
|
||||||
|
|
||||||
|
found = DB.find(EBasicEncryptClient.class)
|
||||||
|
.where()
|
||||||
|
.in("description", "goodbye")
|
||||||
|
.in("status", EBasicEncryptClient.Status.TWO)
|
||||||
|
.in("dob", today)
|
||||||
|
.findOne();
|
||||||
|
assertThat(found).isNotNull();
|
||||||
|
assertThat(found.getDescription()).isEqualTo("goodbye");
|
||||||
|
|
||||||
|
|
||||||
DB.delete(found);
|
DB.delete(found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user