Unverified Commit e37ea5a7 authored by Liang Zhang's avatar Liang Zhang Committed by GitHub
Browse files

Merge pull request #157 from tuohai666/dev

update for encrypt
parents bceeb5ba beb96753
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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);
+6 −0
Original line number Diff line number Diff line
@@ -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() {
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
    </resultMap>

    <update id="createTableIfNotExists">
        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));
    </update>

    <update id="truncateTable">
+14 −5
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@

package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;

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.orchestration.config.OrchestrationConfiguration;
@@ -27,6 +29,8 @@ import org.apache.shardingsphere.shardingjdbc.orchestration.api.OrchestrationEnc

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class LocalEncryptConfiguration implements ExampleConfiguration {
@@ -40,7 +44,6 @@ public class LocalEncryptConfiguration implements ExampleConfiguration {
    @Override
    public DataSource getDataSource() throws SQLException {
        return OrchestrationEncryptDataSourceFactory.createDataSource(DataSourceUtil.createDataSource("demo_ds"), getEncryptRuleConfiguration(), new Properties(), getOrchestrationConfiguration());
        
    }
    
    private OrchestrationConfiguration getOrchestrationConfiguration() {
@@ -51,8 +54,14 @@ public class LocalEncryptConfiguration implements ExampleConfiguration {
        EncryptRuleConfiguration result = new EncryptRuleConfiguration();
        Properties properties = new Properties();
        properties.setProperty("aes.key.value", "123456");
        EncryptorRuleConfiguration encryptorRuleConfig = new EncryptorRuleConfiguration("aes", "t_order.status", properties);
        result.getEncryptorRuleConfigs().put("order_encryptor", encryptorRuleConfig);
        EncryptorRuleConfiguration aesRuleConfiguration = new EncryptorRuleConfiguration("aes", properties);
        EncryptColumnRuleConfiguration columnConfigAes = new EncryptColumnRuleConfiguration("", "status", "", "status_encryptor");
        Map<String, EncryptColumnRuleConfiguration> columns = new HashMap<>();
        EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration(columns);
        columns.put("status", columnConfigAes);
        tableConfig.getColumns().putAll(columns);
        result.getEncryptors().put("status_encryptor", aesRuleConfiguration);
        result.getTables().put("t_order", tableConfig);
        return result;
    }
}
Loading