jasypt解密过程源码深度分析

在springboot启动的时候会初始化ApplicationListener相关的监听类
在这里插入图片描述

加密的框架在spring.factories中定义
在这里插入图片描述

通过无参构造方法来实例化EnableEncryptablePropertiesBeanFactoryPostProcessor(容器还没托管,只是赋值给了SpringApplication的listeners变量)
在这里插入图片描述

进入springboot 的run方法,会在org.springframework.boot.SpringApplication#refreshContext中调用
在这里插入图片描述

@EnableEncryptableProperties在引入了EnableEncryptablePropertiesConfiguration的配置类
在这里插入图片描述

在org.springframework.context.support.PostProcessorRegistrationDelegate#invokeBeanFactoryPostProcessors()
中,由于enableEncryptablePropertySourcesPostProcessor实现了BeanFactoryPostProcessor和Ordered接口,所以会在这里进行实例化加载,这个时候enableEncryptablePropertySourcesPostProcessor对象由容器来托管。
在这里插入图片描述

在这里插入图片描述

调用postProcessBeanFactory方法,
1.构造Encryptable自己的属性解析器
2.获取容器所有的属性源,可以看到ApolloBootstrapPropertySources也在这里面
3.对propertySource进行包装,换成Encryptable自己的类方便操作
在这里插入图片描述
把ApolloBootstrapPropertySources包装成了EncryptableEnumerablePropertySourceWrapper类
在这里插入图片描述
执行完convertPropertySources后,属性源propSources全替换成了EncryptableEnumerablePropertySourceWrapper包装类,
delegate为源属性源,resolver为懒加载的属性解析器
在这里插入图片描述
在容器加载类的时候,比如有的service用到了redis.就会把redisTemplate给进行加载
在这里插入图片描述

redisTemplate需要注入redis相关的属性类。

在这里插入图片描述

在这里插入图片描述
绑定redis相关属性,可以看到这里的source已经是替换过的包装类了EncryptableEnumerablePropertySourceWrapper

在这里插入图片描述

给属性赋值的过程,就是循环的去包装类的属性源中找对应的name。例如循环找spring.redis.host。
在这里插入图片描述
在这里插入图片描述

最后就找到了包装类EncryptableEnumerablePropertySourceWrapper
在这里插入图片描述
如果在属性源ApolloBootstrapPropertySources 中找到了spring.redis.host 这个配置,如果是String类型的,需要判断是否需要解码
在这里插入图片描述
如果是以ENC(开头,以)结尾的字符串就需要解码,然后进行返回
在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值