-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from limboinf/master
Encrypt sensitive information.
- Loading branch information
Showing
20 changed files
with
408 additions
and
68 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...r/src/main/java/com/autohome/frostmourne/monitor/config/properties/EncryptProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.autohome.frostmourne.monitor.config.properties; | ||
|
||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 加密配置类 | ||
* | ||
* @author limbo | ||
* @since 2022/9/14 13:48 | ||
*/ | ||
@Configuration | ||
public class EncryptProperties implements InitializingBean { | ||
|
||
private static EncryptProperties prop = null; | ||
|
||
public static EncryptProperties getInstance () { | ||
return prop; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
prop = this; | ||
} | ||
|
||
/** | ||
* 密钥 | ||
*/ | ||
@Value("${encrypt.key:EX31$@*^ac1}") | ||
private String key; | ||
|
||
/** | ||
* 敏感字段列表 | ||
* | ||
* 默认会对 data_source表 properties字段值进行加密 | ||
* 对于username, password等配置等敏感字段也要进行加解密操作,避免在前端泄漏 | ||
*/ | ||
@Value("#{'${encrypt.sensitives:username,password}'.split(',')}") | ||
private List<String> sensitiveFields; | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public List<String> getSensitiveFields() { | ||
return sensitiveFields; | ||
} | ||
|
||
public void setSensitiveFields(List<String> sensitiveFields) { | ||
this.sensitiveFields = sensitiveFields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...rne-monitor/src/main/java/com/autohome/frostmourne/monitor/handler/CryptoTypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.autohome.frostmourne.monitor.handler; | ||
|
||
import com.autohome.frostmourne.monitor.tool.AESUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.ibatis.type.JdbcType; | ||
import org.apache.ibatis.type.MappedTypes; | ||
import org.apache.ibatis.type.TypeHandler; | ||
|
||
import java.sql.*; | ||
import java.util.Objects; | ||
|
||
/** | ||
* 加解密mybatis TypeHandler | ||
* | ||
* @author limbo | ||
* @since 2022/9/9 15:08 | ||
*/ | ||
@MappedTypes({String.class}) | ||
public class CryptoTypeHandler implements TypeHandler<String> { | ||
|
||
/** | ||
* 设置加密 | ||
*/ | ||
@Override | ||
public void setParameter(PreparedStatement preparedStatement, int i, String parameter, JdbcType jdbcType) throws SQLException { | ||
if (StringUtils.isNotBlank(parameter)) { | ||
preparedStatement.setString(i, AESUtils.encrypt(parameter)); | ||
} else { | ||
preparedStatement.setNull(i, Types.VARCHAR); | ||
} | ||
} | ||
|
||
/** | ||
* 设置解密 | ||
*/ | ||
@Override | ||
public String getResult(ResultSet resultSet, String columnName) throws SQLException { | ||
return decrypt(resultSet.getString(columnName)); | ||
} | ||
|
||
@Override | ||
public String getResult(ResultSet resultSet, int columnIndex) throws SQLException { | ||
return decrypt(resultSet.getString(columnIndex)); | ||
} | ||
|
||
@Override | ||
public String getResult(CallableStatement callableStatement, int columnIndex) throws SQLException { | ||
return decrypt(callableStatement.getString(columnIndex)); | ||
} | ||
|
||
private String decrypt(String result) { | ||
if (StringUtils.isNotBlank(result)) { | ||
String decrypt = AESUtils.decrypt(result); | ||
return Objects.nonNull(decrypt) ? decrypt : result; | ||
} | ||
return result; | ||
} | ||
} |
19 changes: 3 additions & 16 deletions
19
...rne-monitor/src/main/java/com/autohome/frostmourne/monitor/model/contract/DataOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,13 @@ | ||
package com.autohome.frostmourne.monitor.model.contract; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class DataOption { | ||
|
||
private String datasourceType; | ||
|
||
private List<DataSourceOption> dataSourceOptionList; | ||
|
||
public String getDatasourceType() { | ||
return datasourceType; | ||
} | ||
|
||
public void setDatasourceType(String datasourceType) { | ||
this.datasourceType = datasourceType; | ||
} | ||
|
||
public List<DataSourceOption> getDataSourceOptionList() { | ||
return dataSourceOptionList; | ||
} | ||
|
||
public void setDataSourceOptionList(List<DataSourceOption> dataSourceOptionList) { | ||
this.dataSourceOptionList = dataSourceOptionList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...tmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/model/vo/DataSourceVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.autohome.frostmourne.monitor.model.vo; | ||
|
||
import com.autohome.frostmourne.monitor.model.enums.DataSourceType; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
/** | ||
* description | ||
* | ||
* @author limbo | ||
* @since 2022/9/14 18:55 | ||
*/ | ||
@Data | ||
@Builder | ||
public class DataSourceVO { | ||
|
||
/** | ||
* 主键 | ||
*/ | ||
private Long id; | ||
|
||
/** | ||
* 数据源名称 | ||
*/ | ||
private String datasourceName; | ||
|
||
/** | ||
* 数据源类型。(Elasticsearch, Influxdb) | ||
*/ | ||
private DataSourceType datasourceType; | ||
|
||
} |
Oops, something went wrong.