All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.healthy.common.security.code.ValidateCodeBeanConfig Maven / Gradle / Ivy

There is a newer version: 1.2.1.RELEASE
Show newest version
package com.healthy.common.security.code;

import com.healthy.common.security.code.image.ImageCodeGenerator;
import com.healthy.common.security.code.sms.DefaultSmsCodeSender;
import com.healthy.common.security.code.sms.SmsCodeGenerator;
import com.healthy.common.security.code.sms.SmsCodeSender;
import com.healthy.common.security.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Verification code related extension point configuration.
 * You can override the default configuration by declaring beans of the same type or the same name.
 *
 * @author xiaomingzhang
 */
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    private SecurityProperties securityProperties;

    /**
     * Image Validate Code Generator
     *
     * @return ValidateCodeGenerator
     */
    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ValidateCodeGenerator imageValidateCodeGenerator() {
        ImageCodeGenerator codeGenerator = new ImageCodeGenerator();
        codeGenerator.setImageCodeProperties(securityProperties.getCode().getImage());
        return codeGenerator;
    }

    /**
     * Sms Validate Code Generator
     *
     * @return ValidateCodeGenerator
     */
    @Bean
    @ConditionalOnMissingBean(name = "smsValidateCodeGenerator")
    public ValidateCodeGenerator smsValidateCodeGenerator() {
        SmsCodeGenerator codeGenerator = new SmsCodeGenerator();
        codeGenerator.setSmsCodeProperties(securityProperties.getCode().getSms());
        return codeGenerator;
    }

    /**
     * SMS verification code sender
     *
     * @return SmsCodeSender
     */
    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeSender() {
        return new DefaultSmsCodeSender();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy