shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Encryption rules do not support uppercase fields

Open yanyzy opened this issue 7 years ago • 4 comments

Bug Report

Which version of ShardingSphere did you use?

4.0.0-RC3-SNAPSHOT

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Sql:

 <insert id="saveSysUser" parameterType="com.mlt.demo.entity.SysUser">
		insert into SYS_USER (ID,
		 NAME,
		 AGE)
		values (#{id,jdbcType=VARCHAR},
                #{name,jdbcType=VARCHAR},
                #{age,jdbcType=VARCHAR}
		)
	</insert>

Config:

spring:
  shardingsphere:
    datasource:
    ···
    
    encrypt:
      encryptors:
        encryptor_aes:
          type: aes
          props:
            aes.key.value: aes-dg
        encryptor_md5:
          type: md5
      tables:
        SYS_USER:
          columns:
            AGE:
              plainColumn: AGE
              cipherColumn: AGE_CIPHER
              encryptor: encryptor_aes

error:

	at java.util.ArrayList.elementData(ArrayList.java:422)
	at java.util.ArrayList.get(ArrayList.java:435)
	at org.apache.shardingsphere.core.preprocessor.segment.insert.InsertValueContext.getValue(InsertValueContext.java:86)
	at org.apache.shardingsphere.core.rewrite.feature.encrypt.parameter.impl.EncryptInsertValueParameterRewriter.encryptInsertValues(EncryptInsertValueParameterRewriter.java:75)
	at org.apache.shardingsphere.core.rewrite.feature.encrypt.parameter.impl.EncryptInsertValueParameterRewriter.rewrite(EncryptInsertValueParameterRewriter.java:63)
	at org.apache.shardingsphere.core.rewrite.feature.encrypt.context.EncryptSQLRewriteContextDecorator.decorate(EncryptSQLRewriteContextDecorator.java:43)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.EncryptPreparedStatement.getSQLUnit(EncryptPreparedStatement.java:157)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.EncryptPreparedStatement.execute(EncryptPreparedStatement.java:127)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
	... 52 more

yanyzy avatar Oct 17 '19 07:10 yanyzy

Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.lang.ArrayIndexOutOfBoundsException: -1
### The error may involve com.mlt.demo.mapper.SysUserMapper.saveSysUser-Inline
### The error occurred while setting parameters
### SQL: insert into SYS_USER (ID,    NAME,    AGE)   values (?,                 ?,                 ?   )
### Cause: java.lang.ArrayIndexOutOfBoundsException: -1
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
	... 46 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.ArrayList.elementData(ArrayList.java:422)
	at java.util.ArrayList.get(ArrayList.java:435)
	at org.apache.shardingsphere.core.preprocessor.segment.insert.InsertValueContext.getValue(InsertValueContext.java:86)
	at org.apache.shardingsphere.core.rewrite.feature.encrypt.parameter.impl.EncryptInsertValueParameterRewriter.encryptInsertValues(EncryptInsertValueParameterRewriter.java:75)
	at org.apache.shardingsphere.core.rewrite.feature.encrypt.parameter.impl.EncryptInsertValueParameterRewriter.rewrite(EncryptInsertValueParameterRewriter.java:63)
	at org.apache.shardingsphere.core.rewrite.feature.encrypt.context.EncryptSQLRewriteContextDecorator.decorate(EncryptSQLRewriteContextDecorator.java:43)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.EncryptPreparedStatement.getSQLUnit(EncryptPreparedStatement.java:157)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.EncryptPreparedStatement.execute(EncryptPreparedStatement.java:127)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
	... 52 more

yanyzy avatar Oct 17 '19 08:10 yanyzy

Please assign me to fix this bug.(I have the same problem when i use encrypt jdbc but i had fixed it and now the code is running in product environment) @terrymanu

HongJinFeng avatar Dec 18 '19 10:12 HongJinFeng

@HongJinFeng Looking forward to your pull request!

yanyzy avatar Dec 18 '19 10:12 yanyzy

Thanks, It may on weaekend because still need to work on weekday.

HongJinFeng avatar Dec 18 '19 14:12 HongJinFeng