/*
 * Copyright © 2018 organization baomidou
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hzya.frame.DataSource.impl;

import com.baomidou.dynamic.datasource.event.DataSourceInitEvent;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.hzya.frame.util.AESUtil;
import lombok.extern.slf4j.Slf4j;

import javax.sql.DataSource;

/**
 * 多数据源默认解密事件
 *
 * @author TaoYu
 */
@Slf4j
public class EncDataSourceInitEvent implements DataSourceInitEvent {

    /**
     * @Author lvleigang
     * @Description  数据源初始化解密，目前只解密密码
     * @Date 11:00 上午 2024/4/11
     * @param dataSourceProperty
     * @return void
     **/
    @Override
    public void beforeCreate(DataSourceProperty dataSourceProperty) {
        dataSourceProperty.setPassword(AESUtil.decrypt(dataSourceProperty.getPassword()));
    }

    @Override
    public void afterCreate(DataSource dataSource) {

    }

}