diff --git a/example-common/repository-api/src/main/java/org/apache/shardingsphere/example/common/entity/User.java b/example-common/repository-api/src/main/java/org/apache/shardingsphere/example/common/entity/User.java
index 7cbbcb9994cf28207ca741e216e3318feef6633e..5f055402302b60381e4d678c61da53a2599285ad 100644
--- a/example-common/repository-api/src/main/java/org/apache/shardingsphere/example/common/entity/User.java
+++ b/example-common/repository-api/src/main/java/org/apache/shardingsphere/example/common/entity/User.java
@@ -27,6 +27,8 @@ public class User implements Serializable {
private String userName;
+ private String userNamePlain;
+
private String pwd;
private String assistedQueryPwd;
@@ -35,7 +37,7 @@ public class User implements Serializable {
return userId;
}
- public void setUserId(int userId) {
+ public void setUserId(final int userId) {
this.userId = userId;
}
@@ -43,15 +45,23 @@ public class User implements Serializable {
return userName;
}
- public void setUserName(String userName) {
+ public void setUserName(final String userName) {
this.userName = userName;
}
+ public String getUserNamePlain() {
+ return userNamePlain;
+ }
+
+ public void setUserNamePlain(final String userNamePlain) {
+ this.userNamePlain = userNamePlain;
+ }
+
public String getPwd() {
return pwd;
}
- public void setPwd(String pwd) {
+ public void setPwd(final String pwd) {
this.pwd = pwd;
}
@@ -59,7 +69,12 @@ public class User implements Serializable {
return assistedQueryPwd;
}
- public void setAssistedQueryPwd(String assistedQueryPwd) {
+ public void setAssistedQueryPwd(final String assistedQueryPwd) {
this.assistedQueryPwd = assistedQueryPwd;
}
+
+ @Override
+ public String toString() {
+ return String.format("user_id: %d, user_name: %s, user_name_plain: %s, pwd: %s, assisted_query_pwd: %s", userId, userName, userNamePlain, pwd, assistedQueryPwd);
+ }
}
diff --git a/example-common/repository-jdbc/src/main/java/org/apache/shardingsphere/example/common/jdbc/repository/UserRepositoryImpl.java b/example-common/repository-jdbc/src/main/java/org/apache/shardingsphere/example/common/jdbc/repository/UserRepositoryImpl.java
index 6604d74e33c47ec5dac336d733425e57726cf725..dd2897249fecb6520d2cbd650e12cdde0546b6be 100644
--- a/example-common/repository-jdbc/src/main/java/org/apache/shardingsphere/example/common/jdbc/repository/UserRepositoryImpl.java
+++ b/example-common/repository-jdbc/src/main/java/org/apache/shardingsphere/example/common/jdbc/repository/UserRepositoryImpl.java
@@ -39,7 +39,7 @@ public final class UserRepositoryImpl implements UserRepository {
@Override
public void createTableIfNotExists() {
- String sql = "CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_name VARCHAR(200), pwd VARCHAR(200), assisted_query_pwd VARCHAR(200), PRIMARY KEY (user_id))";
+ String sql = "CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_name VARCHAR(200), user_name_plain VARCHAR(200), pwd VARCHAR(200), assisted_query_pwd VARCHAR(200), PRIMARY KEY (user_id))";
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
statement.executeUpdate(sql);
diff --git a/example-common/repository-jpa/src/main/java/org/apache/shardingsphere/example/common/jpa/entity/UserEntity.java b/example-common/repository-jpa/src/main/java/org/apache/shardingsphere/example/common/jpa/entity/UserEntity.java
index 18334f33dfe0f2ba093353879a8872e7a2e8b920..af16cc0079f3d92d13fbd225d8fe4128e755ac85 100644
--- a/example-common/repository-jpa/src/main/java/org/apache/shardingsphere/example/common/jpa/entity/UserEntity.java
+++ b/example-common/repository-jpa/src/main/java/org/apache/shardingsphere/example/common/jpa/entity/UserEntity.java
@@ -41,6 +41,12 @@ public final class UserEntity extends User {
return super.getUserName();
}
+ @Column(name = "user_name_plain")
+ @Override
+ public String getUserNamePlain() {
+ return super.getUserNamePlain();
+ }
+
@Column(name = "pwd")
@Override
public String getPwd() {
diff --git a/example-common/repository-mybatis/src/main/resources/META-INF/mappers/UserMapper.xml b/example-common/repository-mybatis/src/main/resources/META-INF/mappers/UserMapper.xml
index 73c8793635e0de1fe5bdab19c7662754f481b035..69846447f81358f0feb76c6b790d9e1171132564 100644
--- a/example-common/repository-mybatis/src/main/resources/META-INF/mappers/UserMapper.xml
+++ b/example-common/repository-mybatis/src/main/resources/META-INF/mappers/UserMapper.xml
@@ -9,7 +9,7 @@
- CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_name VARCHAR(200), pwd VARCHAR(200), assisted_query_pwd VARCHAR(200), PRIMARY KEY (user_id));
+ CREATE TABLE IF NOT EXISTS t_user (user_id INT NOT NULL AUTO_INCREMENT, user_name VARCHAR(200), user_name_plain VARCHAR(200), pwd VARCHAR(200), assisted_query_pwd VARCHAR(200), PRIMARY KEY (user_id));
diff --git a/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java b/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java
index 1360d9b563f01e30dfc9e93c52fe874bab5ad0e6..bf84d43cc6c97c57b1f8db3c9358e0d4b8a516cd 100644
--- a/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java
+++ b/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/encrypt/table/raw/jdbc/config/EncryptDatabasesConfiguration.java
@@ -17,26 +17,46 @@
package org.apache.shardingsphere.example.encrypt.table.raw.jdbc.config;
-import org.apache.shardingsphere.api.config.encryptor.EncryptRuleConfiguration;
-import org.apache.shardingsphere.api.config.encryptor.EncryptorRuleConfiguration;
+import org.apache.shardingsphere.api.config.encrypt.EncryptColumnRuleConfiguration;
+import org.apache.shardingsphere.api.config.encrypt.EncryptRuleConfiguration;
+import org.apache.shardingsphere.api.config.encrypt.EncryptTableRuleConfiguration;
+import org.apache.shardingsphere.api.config.encrypt.EncryptorRuleConfiguration;
import org.apache.shardingsphere.example.common.DataSourceUtil;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.shardingjdbc.api.EncryptDataSourceFactory;
import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
public class EncryptDatabasesConfiguration implements ExampleConfiguration {
@Override
public DataSource getDataSource() {
+
EncryptRuleConfiguration encryptRuleConfiguration = new EncryptRuleConfiguration();
Properties properties = new Properties();
properties.setProperty("aes.key.value", "123456");
- EncryptorRuleConfiguration aesRuleConfiguration = new EncryptorRuleConfiguration("AES", "t_user.user_name", properties);
- EncryptorRuleConfiguration testRuleConfiguration = new EncryptorRuleConfiguration("assistedTest", "t_user.pwd", "t_user.assisted_query_pwd", properties);
- encryptRuleConfiguration.getEncryptorRuleConfigs().put("name_encryptor", aesRuleConfiguration);
- encryptRuleConfiguration.getEncryptorRuleConfigs().put("pwd_encryptor", testRuleConfiguration);
- return EncryptDataSourceFactory.createDataSource(DataSourceUtil.createDataSource("demo_ds"), encryptRuleConfiguration);
+ properties.setProperty("query.with.cipher.column", "true");
+ EncryptorRuleConfiguration aesRuleConfiguration = new EncryptorRuleConfiguration("aes", properties);
+ EncryptColumnRuleConfiguration columnConfigAes = new EncryptColumnRuleConfiguration("user_name_plain", "user_name", "", "name_encryptor");
+ Map columns = new HashMap<>();
+ EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration(columns);
+ columns.put("user_name", columnConfigAes);
+ encryptRuleConfiguration.getEncryptors().put("name_encryptor", aesRuleConfiguration);
+ encryptRuleConfiguration.getTables().put("t_user", tableConfig);
+ EncryptorRuleConfiguration testRuleConfiguration = new EncryptorRuleConfiguration("assistedTest", properties);
+ EncryptColumnRuleConfiguration columnConfigTest = new EncryptColumnRuleConfiguration("", "pwd", "assisted_query_pwd", "pwd_encryptor");
+ columns.put("pwd", columnConfigTest);
+ tableConfig.getColumns().putAll(columns);
+ encryptRuleConfiguration.getEncryptors().put("pwd_encryptor", testRuleConfiguration);
+ try {
+ return EncryptDataSourceFactory.createDataSource(DataSourceUtil.createDataSource("demo_ds"), encryptRuleConfiguration, properties);
+ } catch (final SQLException ex) {
+ ex.printStackTrace();
+ return null;
+ }
}
}
diff --git a/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/resources/META-INF/encrypt-databases.yaml b/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/resources/META-INF/encrypt-databases.yaml
index 5b748809faa61434f432d33cd408904e2d773bc6..72219ba737c4254f423d5012a3ef7a35469aea9d 100644
--- a/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/resources/META-INF/encrypt-databases.yaml
+++ b/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-raw-jdbc-example/src/main/resources/META-INF/encrypt-databases.yaml
@@ -1,17 +1,28 @@
dataSource: !!com.zaxxer.hikari.HikariDataSource
- driverClassName: com.mysql.jdbc.Driver
- jdbcUrl: jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
- username: root
- password:
-
+ driverClassName: com.mysql.jdbc.Driver
+ jdbcUrl: jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+ username: root
+ password:
+
encryptRule:
encryptors:
name_encryptror:
type: aes
- qualifiedColumns: t_user.name
props:
aes.key.value: 123456
pwd_encryptror:
type: assistedTest
- qualifiedColumns: t_user.pwd
- assistedQueryColumns: t_user.assisted_query_pwd
+ tables:
+ t_user:
+ columns:
+ user_name:
+ plainColumn: user_name_plain
+ cipherColumn: user_name
+ encryptor: name_encryptror
+ pwd:
+ cipherColumn: pwd
+ encryptor: pwd_encryptror
+ assistedQueryColumn: assisted_query_pwd
+
+props:
+ query.with.cipher.column: true
\ No newline at end of file
diff --git a/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-spring-boot-example/src/main/resources/application-encrypt-databases.properties b/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-spring-boot-example/src/main/resources/application-encrypt-databases.properties
index 2c26e7065022a773a5a26c82520b3238d8f87e19..53d34528fd614f48e1e252c0b42015512ef49452 100644
--- a/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-spring-boot-example/src/main/resources/application-encrypt-databases.properties
+++ b/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-spring-boot-example/src/main/resources/application-encrypt-databases.properties
@@ -7,10 +7,15 @@ spring.shardingsphere.datasource.ds.username=root
spring.shardingsphere.datasource.ds.password=
spring.shardingsphere.encrypt.encryptors.name_encryptor.type=aes
-spring.shardingsphere.encrypt.encryptors.name_encryptor.qualifiedColumns=t_user.user_name
spring.shardingsphere.encrypt.encryptors.name_encryptor.props.aes.key.value=123456
spring.shardingsphere.encrypt.encryptors.pwd_encryptor.type=assistedTest
-spring.shardingsphere.encrypt.encryptors.pwd_encryptor.qualifiedColumns=t_user.pwd
-spring.shardingsphere.encrypt.encryptors.pwd_encryptor.assistedQueryColumns=t_user.assisted_query_pwd
+spring.shardingsphere.encrypt.tables.t_user.columns.user_name.plainColumn=user_name_plain
+spring.shardingsphere.encrypt.tables.t_user.columns.user_name.cipherColumn=user_name
+spring.shardingsphere.encrypt.tables.t_user.columns.user_name.encryptor=name_encryptor
+spring.shardingsphere.encrypt.tables.t_user.columns.pwd.cipherColumn=pwd
+spring.shardingsphere.encrypt.tables.t_user.columns.pwd.assistedQueryColumn=assisted_query_pwd
+spring.shardingsphere.encrypt.tables.t_user.columns.pwd.encryptor=pwd_encryptor
+
+spring.shardingsphere.props.query.with.cipher.comlum=true
diff --git a/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-spring-namespace-example/src/main/resources/META-INF/application-encrypt-databases.xml b/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-spring-namespace-example/src/main/resources/META-INF/application-encrypt-databases.xml
index 28658ea35f0e53a0a43d3826ca473069913f94dc..5ee11cf32efa94bf6cd5835472430c1df701305b 100644
--- a/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-spring-namespace-example/src/main/resources/META-INF/application-encrypt-databases.xml
+++ b/sharding-jdbc-example/other-feature-example/encrypt-example/encrypt-spring-namespace-example/src/main/resources/META-INF/application-encrypt-databases.xml
@@ -28,8 +28,21 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+