암복호화 추가
parent
6a514198e6
commit
909bd7dcfe
@ -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;
|
||||
}
|
||||
}
|
@ -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<String, Object> map = (Map<String, Object>)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<String, Object> map = (Map<String, Object>)obj;
|
||||
if (map.containsKey(key)) {
|
||||
decrypt(
|
||||
() -> (String)map.get(key),
|
||||
(v) -> map.put(key, v)
|
||||
);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue