From 909bd7dcfe5542c816194a915591de91197632ee Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Tue, 19 Dec 2023 16:38:38 +0900 Subject: [PATCH] =?UTF-8?q?=EC=95=94=EB=B3=B5=ED=98=B8=ED=99=94=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cokr/xit/fims/EncryptionConfig.java | 43 ++++++++++++ .../java/cokr/xit/fims/FimsApplication.java | 4 +- .../xit/fims/payer/dao/PayerEncryptor.java | 66 +++++++++++++++++++ .../resources/sql/mapper/base/test-mapper.xml | 2 + src/main/resources/sql/mybatis-config.xml | 4 -- 5 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 src/main/java/cokr/xit/fims/EncryptionConfig.java create mode 100644 src/main/java/cokr/xit/fims/payer/dao/PayerEncryptor.java diff --git a/src/main/java/cokr/xit/fims/EncryptionConfig.java b/src/main/java/cokr/xit/fims/EncryptionConfig.java new file mode 100644 index 00000000..8975a08e --- /dev/null +++ b/src/main/java/cokr/xit/fims/EncryptionConfig.java @@ -0,0 +1,43 @@ +package cokr.xit.fims; + +import javax.annotation.Resource; + +import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import cokr.xit.fims.payer.dao.PayerEncryptor; +import cokr.xit.foundation.data.ARIA; +import cokr.xit.foundation.data.paging.EncryptionSupport; + +@Configuration +public class EncryptionConfig { + @Resource(name = "sqlSession") + private DefaultSqlSessionFactory sqlSessionFactory; + + @Bean + ARIA encryptor() { + return new ARIA() + .setKey("Copyright (c) 2015 - (주)엑스아이티") + .setAlgorithm("SHA-256"); + } + + @Bean + PayerEncryptor payerEncryptor() { + PayerEncryptor bean = new PayerEncryptor(); + bean.setARIA(encryptor()); + return bean; + } + + @Bean + EncryptionSupport encryptionSupport() { + EncryptionSupport support = new EncryptionSupport(); + support.setEncryptor(encryptor()); + support.setEnabled(true); + support.setAdaptors(payerEncryptor()); + + sqlSessionFactory.getConfiguration().addInterceptor(support); + + return support; + } +} \ No newline at end of file diff --git a/src/main/java/cokr/xit/fims/FimsApplication.java b/src/main/java/cokr/xit/fims/FimsApplication.java index fbfb3a30..ebcff3ae 100644 --- a/src/main/java/cokr/xit/fims/FimsApplication.java +++ b/src/main/java/cokr/xit/fims/FimsApplication.java @@ -7,9 +7,7 @@ import cokr.xit.base.boot.XitBaseApplication; @ImportResource("classpath:spring/context-*.xml") public class FimsApplication extends XitBaseApplication { - public static void main(String[] args) { SpringApplication.run(FimsApplication.class, args); } - -} \ No newline at end of file +} diff --git a/src/main/java/cokr/xit/fims/payer/dao/PayerEncryptor.java b/src/main/java/cokr/xit/fims/payer/dao/PayerEncryptor.java new file mode 100644 index 00000000..b0d25708 --- /dev/null +++ b/src/main/java/cokr/xit/fims/payer/dao/PayerEncryptor.java @@ -0,0 +1,66 @@ +package cokr.xit.fims.payer.dao; + +import java.util.Map; +import java.util.regex.Pattern; + +import cokr.xit.fims.payer.Payer; +import cokr.xit.fims.payer.PayerQuery; +import cokr.xit.foundation.data.paging.EncryptionSupport; + +public class PayerEncryptor extends EncryptionSupport.Adaptor { + private static final Pattern rtpyrNoPattern = Pattern.compile("\\d*"); + + @Override + public boolean supports(Object obj) { + return obj instanceof Map + || obj instanceof Payer + || obj instanceof PayerQuery; + } + + @Override + public boolean isEncrypted(String str) { + return !rtpyrNoPattern.matcher(str).matches(); + } + + @Override + public PayerEncryptor encrypt() { + if (obj instanceof Payer) { + Payer payer = (Payer)obj; + encrypt(payer::getRtpyrNo, payer::setRtpyrNo); + } else if (obj instanceof PayerQuery) { + PayerQuery req = (PayerQuery)obj; + encrypt(req::getRtpyrNo, req::setRtpyrNo); + } else if (obj instanceof Map) { + String key = "RTPYR_NO"; + Map map = (Map)obj; + if (map.containsKey(key)) { + encrypt( + () -> (String)map.get(key), + (v) -> map.put(key, v) + ); + } + } + return this; + } + + @Override + public PayerEncryptor decrypt() { + if (obj instanceof Payer) { + Payer payer = (Payer)obj; + decrypt(payer::getRtpyrNo, payer::setRtpyrNo); + } else if (obj instanceof PayerQuery) { + PayerQuery req = (PayerQuery)obj; + decrypt(req::getRtpyrNo, req::setRtpyrNo); + } else if (obj instanceof Map) { + String key = "RTPYR_NO"; + Map map = (Map)obj; + if (map.containsKey(key)) { + decrypt( + () -> (String)map.get(key), + (v) -> map.put(key, v) + ); + } + } + return this; + } +} \ No newline at end of file diff --git a/src/main/resources/sql/mapper/base/test-mapper.xml b/src/main/resources/sql/mapper/base/test-mapper.xml index d6741306..8a897ec0 100644 --- a/src/main/resources/sql/mapper/base/test-mapper.xml +++ b/src/main/resources/sql/mapper/base/test-mapper.xml @@ -2,6 +2,8 @@ + + ${sql} ${sql} diff --git a/src/main/resources/sql/mybatis-config.xml b/src/main/resources/sql/mybatis-config.xml index 44b31575..faa9415d 100644 --- a/src/main/resources/sql/mybatis-config.xml +++ b/src/main/resources/sql/mybatis-config.xml @@ -17,9 +17,5 @@ - - - - \ No newline at end of file