#1398 - Support EQ / "Equal to" predicate on client side encrypted entity property - @Encrypted(dbEncryption = false)

This commit is contained in:
rob bygrave
2018-05-31 16:02:49 +12:00
parent ddc00fedb6
commit 11e3649b85
9 changed files with 186 additions and 4 deletions
@@ -0,0 +1,55 @@
package org.tests.basic.encrypt;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.junit.Test;
import org.tests.model.basic.EBasicEncryptClient;
import java.time.LocalDate;
import static org.assertj.core.api.Assertions.assertThat;
public class TestEncryptClientSide extends BaseTestCase {
@Test
public void insertUpdate() {
LocalDate today = LocalDate.now();
EBasicEncryptClient bean = new EBasicEncryptClient();
bean.setDescription("hello");
bean.setStatus(EBasicEncryptClient.Status.ONE);
bean.setDob(today);
Ebean.save(bean);
EBasicEncryptClient found = Ebean.find(EBasicEncryptClient.class)
.where()
.eq("description", "hello")
.eq("status", EBasicEncryptClient.Status.ONE)
.eq("dob", today)
.findOne();
assertThat(found).isNotNull();
assertThat(found.getDescription()).isEqualTo("hello");
assertThat(found.getStatus()).isEqualTo(EBasicEncryptClient.Status.ONE);
assertThat(found.getDob()).isEqualTo(today);
found.setDescription("goodbye");
found.setStatus(EBasicEncryptClient.Status.TWO);
Ebean.save(found);
found = Ebean.find(EBasicEncryptClient.class)
.where()
.eq("description", "goodbye")
.eq("status", EBasicEncryptClient.Status.TWO)
.eq("dob", today)
.findOne();
assertThat(found).isNotNull();
assertThat(found.getDescription()).isEqualTo("goodbye");
Ebean.delete(found);
}
}
@@ -0,0 +1,87 @@
package org.tests.model.basic;
import io.ebean.annotation.Encrypted;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
import java.time.LocalDate;
@Entity
@Table(name = "e_basicenc_client")
public class EBasicEncryptClient {
public enum Status {
ONE,
TWO
}
@Id
long id;
String name;
@Encrypted(dbLength = 80, dbEncryption = false)
String description;
@Encrypted(dbLength = 20, dbEncryption = false)
LocalDate dob;
@Enumerated(EnumType.ORDINAL)
@Encrypted(dbLength = 20, dbEncryption = false)
Status status;
@Version
long version;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getDob() {
return dob;
}
public void setDob(LocalDate dob) {
this.dob = dob;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
}