Skip to content

Commit

Permalink
feat: support the use of ciphertext passwords in yml.
Browse files Browse the repository at this point in the history
feat: support the use of ciphertext passwords in yml.
  • Loading branch information
CorvusYe authored May 23, 2024
2 parents 6267e04 + da51bb7 commit c991bd7
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 5 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ This source code is licensed under Apache 2.0 License.

## Feature

- feat: support the use of ciphertext passwords in yml.
- feat: expanding the `insertSelectiveBatch` interface in `NebulaDaoBasic`.

# 1.2.2

## Bugfix
Expand Down Expand Up @@ -73,8 +76,8 @@ This source code is licensed under Apache 2.0 License.
- feat: support `<nGQL>` include query pieces. ([#212](https://github.com/nebula-contrib/ngbatis/pull/212), via [dieyi](https://github.com/1244453393))
- feat: extending `NgPath`, when 'with prop' is used in nGQL, edge attributes can be obtained from NgPath. ([#228](https://github.com/nebula-contrib/ngbatis/pull/228), via [dieyi](https://github.com/1244453393))
- feat: expanding the `insertEdgeBatch` interface in `NebulaDaoBasic`. ([#244](https://github.com/nebula-contrib/ngbatis/pull/244), via [Sunhb](https://github.com/shbone))
- feat: expanding the `deleteByIdBatch` interface in `NebulaDaoBasic`. ([#247](https://github.com/nebula-contrib/ngbatis/pull/244), via [Sunhb](https://github.com/shbone))
- feat: expanding the `listEndNodes` interface in `NebulaDaoBasic`. ([#247](https://github.com/nebula-contrib/ngbatis/pull/272), via [knqiufan](https://github.com/knqiufan))
- feat: expanding the `deleteByIdBatch` interface in `NebulaDaoBasic`. ([#247](https://github.com/nebula-contrib/ngbatis/pull/247), via [Sunhb](https://github.com/shbone))
- feat: expanding the `listEndNodes` interface in `NebulaDaoBasic`. ([#272](https://github.com/nebula-contrib/ngbatis/pull/272), via [knqiufan](https://github.com/knqiufan))
- feat: support specify space by param

## Bugfix
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ye.weicheng.ngbatis.demo.config;

// Copyright (c) 2024 All project authors. All rights reserved.
//
// This source code is licensed under Apache 2.0 License.

import java.util.Base64;
import org.nebula.contrib.ngbatis.PasswordDecoder;
import org.springframework.stereotype.Component;

/**
* yml 明码解密器的组建示例,使用 Base64 的方式
* 如 yml 使用的是明文密码,则不需要这个 bean
*
* @author yeweicheng
* @since 2024-05-23 7:39
* <br>Now is history!
*/
@Component
public class Base64PasswordDecoder implements PasswordDecoder {

@Override
public String decode(String password) {
return new String(Base64.getDecoder().decode(password));
}

}
2 changes: 1 addition & 1 deletion ngbatis-demo/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ nebula:
use-session-pool: false
hosts: 127.0.0.1:19669
username: root
password: nebula
password: bmVidWxh
space: test
pool-config:
min-conns-size: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
Expand Down Expand Up @@ -59,10 +60,19 @@ public NgbatisBeanFactoryPostProcessor(NebulaJdbcProperties nebulaJdbcProperties
@Override
public void postProcessBeanFactory(
ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
setBeans(configurableListableBeanFactory);
NebulaPool nebulaPool = nebulaPool();
mapperContext(nebulaPool);
}

private void setBeans(ConfigurableListableBeanFactory beanFactory) {
ObjectProvider<PasswordDecoder> passwordDecoders =
beanFactory.getBeanProvider(PasswordDecoder.class);

PasswordDecoder passwordDecoder = passwordDecoders.getIfAvailable();
nebulaJdbcProperties.setPasswordDecoder(passwordDecoder);
}

public MapperContext mapperContext(NebulaPool nebulaPool) {
DaoResourceLoader daoBasicResourceLoader = new DaoResourceLoader(parseCfgProps);
MapperContext context = MapperContext.newInstance();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/nebula/contrib/ngbatis/PasswordDecoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.nebula.contrib.ngbatis;

// Copyright (c) 2024 All project authors. All rights reserved.
//
// This source code is licensed under Apache 2.0 License.

/**
* 用于:从配置中得到的密码,可以解密获得明文密码
*
* @author yeweicheng
* @since 2024-05-23 7:31
* <br>Now is history!
*/
public interface PasswordDecoder {

String decode(String password);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.vesoft.nebula.client.graph.data.HostAddress;
import java.util.ArrayList;
import java.util.List;
import org.nebula.contrib.ngbatis.PasswordDecoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -53,6 +55,9 @@ public class NebulaJdbcProperties {
*/
private String space;

@Autowired(required = false)
private PasswordDecoder passwordDecoder;

public NebulaJdbcProperties() {
}

Expand Down Expand Up @@ -101,7 +106,7 @@ public NebulaJdbcProperties setUsername(String username) {
}

public String getPassword() {
return password;
return passwordDecoder == null ? password : passwordDecoder.decode(password);
}

public NebulaJdbcProperties setPassword(String password) {
Expand All @@ -127,5 +132,13 @@ public NebulaJdbcProperties setNgbatis(NgbatisConfig ngbatis) {
return this;
}


public PasswordDecoder getPasswordDecoder() {
return passwordDecoder;
}

public void setPasswordDecoder(PasswordDecoder passwordDecoder) {
this.passwordDecoder = passwordDecoder;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ default void insertBatch(List<T> ts) {
* 批量插入非空字段
* @param ts 当前Tag下多个顶点
*/
default void insertSelectiveBatch(List<? extends T> ts){
default void insertSelectiveBatch(List<? extends T> ts) {
MethodModel methodModel = getMethodModel();
ClassModel classModel = getClassModel(this.getClass());
MapperProxy.invoke(classModel,methodModel,ts);
Expand Down

0 comments on commit c991bd7

Please sign in to comment.