shardingsphere脱敏配置在项目中不起作用(对项目中的表字段不加密),急急急~

您好 我把encrypt-jdbc配置配到项目中 成功 可是执行项目中hirbernate执行insert 没有被加密 请问是什么原因呀
1.项目中的加密配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:encrypt="http://shardingsphere.apache.org/schema/shardingsphere/encrypt"
       xmlns:bean="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://shardingsphere.apache.org/schema/shardingsphere/encrypt
                        http://shardingsphere.apache.org/schema/shardingsphere/encrypt/encrypt.xsd
                        http://www.springframework.org/schema/util
                        http://www.springframework.org/schema/util/spring-util.xsd">


    <bean:properties id="props">
        <prop key="aes.key.value">123456</prop>
    </bean:properties>

    <encrypt:data-source id="encryptDataSource" data-source-name="dataSource">
        <encrypt:encrypt-rule>
            <encrypt:tables>
                <encrypt:table name="hi_sys_dataconf">
                    <encrypt:column logic-column="cd" plain-column="cd" cipher-column="cd_ciper"
                                    encryptor-ref="encryptor_aes"/>
                </encrypt:table>
            </encrypt:tables>
            <encrypt:encryptors>
                <encrypt:encryptor id="encryptor_aes" type="AES" props-ref="props"/>
            </encrypt:encryptors>
        </encrypt:encrypt-rule>
        <encrypt:props>
            <prop key="sql.show">true</prop>
            <prop key="query.with.cipher.column">true</prop>
        </encrypt:props>
    </encrypt:data-source>
</beans>

2.在项目中配置好以后,项目启动的时候有如下提示信息:

[12-15 10:41:50,374 INFO ] ConfigurationLogger.java:104 - EncryptRuleConfiguration:
encryptors:
  encryptor_aes:
    props:
      aes.key.value: '123456'
    type: AES
tables:
  hi_sys_dataconf:
    columns:
      cd:
        assistedQueryColumn: ''
        cipherColumn: cd_ciper
        encryptor: encryptor_aes
        plainColumn: cd

[12-15 10:41:50,375 INFO ] ConfigurationLogger.java:104 - Properties:
sql.show: 'true'
query.with.cipher.column: 'true'

[12-15 10:41:50,424 INFO ] SchemaMetaDataLoader.java:70 - Loading 98 tables' meta data.

3.原项目中的某个模块执行如下语句以后存在表中,但是并没有根据上面的加密的配置对相应的字段加密。项目中原模块的sql打印,并没有shardingsphere的sql打印。

[12-15 10:15:59,543 DEBUG] Slf4jLogFilter.java:134 - {conn-10003, pstmt-20171} update executed. effort 1. 62.1785 millis. insert into hi_sys_dataconf (fg_active, cd, des, flag, instr, na, id_parent, py, wb, zj, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

4.配置中的表的结构如下:

请问使用的是 5.0.0 吗?

shardingsphere的4.1.1版本

@luhong 哈喽,从配置上看,应该没啥问题,需要看下集成有没有问题,集成成功配置 sql.show,应该是会打日志的,输出逻辑 sql 和真实 sql。你可以本地 debug 下,看下是否有使用 SS 相关的 Connection 和 Statement。

现在是没有输出逻辑sql和真实sql 没有输出的原因是什么呀

看起来初始化是成功了,但是还要确保 Hibernate 使用了 SS 的 DataSource,你可以自己 debug 下,EncryptDataSource EncryptPreparedStatement,看下这些流程有没有进来。

对EncryptPreparedStatement加了断点 insert的时候没有起作用 这个什么原因呀

那应该是没整合对,可以提供个 demo 看下

demo都需要什么的 我整理下哈

就是和你实际项目类似的配置,能通过 demo 复现问题就行

我这个是嵌套在项目中的 做不出demo :sob: 有其他办法吗

那只能靠你 debug 调查下了,应该还是集成的问题

能远程看下吗 集成的问题我这边问题不知道出在哪里

你先研究下吧,远程得等有空才行,事情比较多

您好 请问配置完之后需要在代码中对数据源进行修改吗 现在的问题是EncryptPreparedStatement这个类都不能打断点呀

请问 这个方法是在哪里添加呢
@Bean(“tradePlatformDataSource”)
public DataSource dataSource(@Qualifier(“druidDataSource”) DataSource ds) throws SQLException {
return EncryptDataSourceFactory.createDataSource(ds, (), new Properties());
}

把原先 JDBC 数据源,换成 SS 的数据源试下。

EncryptDataSource类的这个方法没有执行 public DataSource getDataSource() {
return getDataSourceMap().values().iterator().next();
}

请问怎么换数据源呀

@luhong 数据脱敏 :: ShardingSphere 参考下 4.x 的文档。

配置文件中的shardingsphere的数据源和原先项目的数据源是配置的同一个 这样子的话还需要在代码中换数据源吗


luhong

13 分钟

EncryptDataSource类的这个方法没有执行 public DataSource getDataSource() {
return getDataSourceMap().values().iterator().next();
}

这个方法没执行是什么问题呀

我怎么确认Hibernate 使用了 SS 的 DataSource?

京ICP备2021015875号