com.opcooc.captcha.autoconfigure.CaptchaAutoConfiguration Maven / Gradle / Ivy
/*
* Copyright © 2020-2021 organization opcooc ([email protected])
*
* 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.opcooc.captcha.autoconfigure;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.opcooc.captcha.cache.CaptchaCache;
import com.opcooc.captcha.manager.CaptchaManager;
import com.opcooc.captcha.plugin.GeneratorSliderPlugin;
import com.opcooc.captcha.plugin.GeneratorWordPlugin;
import com.opcooc.captcha.processor.CaptchaSliderProcessor;
import com.opcooc.captcha.processor.CaptchaWordProcessor;
import lombok.extern.slf4j.Slf4j;
/**
* @author opcooc
*/
@Slf4j
@Configuration
@EnableConfigurationProperties(CaptchaProperties.class)
public class CaptchaAutoConfiguration {
// Generator Plugin Configuration
@Bean
@ConditionalOnMissingBean
public GeneratorSliderPlugin generatorSliderPlugin(CaptchaProperties captchaProperties) {
return new GeneratorSliderPlugin(captchaProperties);
}
@Bean
@ConditionalOnMissingBean
public GeneratorWordPlugin generatorWordPlugin(CaptchaProperties captchaProperties) {
return new GeneratorWordPlugin(captchaProperties);
}
// Captcha Processor Configuration
@Bean
@ConditionalOnMissingBean
public CaptchaSliderProcessor captchaSliderProcessor(GeneratorSliderPlugin generatorSliderPlugin, CaptchaCache captchaCache) {
return new CaptchaSliderProcessor(generatorSliderPlugin, captchaCache);
}
@Bean
@ConditionalOnMissingBean
public CaptchaWordProcessor captchaWordProcessor(GeneratorWordPlugin generatorWordPlugin, CaptchaCache captchaCache) {
return new CaptchaWordProcessor(generatorWordPlugin, captchaCache);
}
//manager configuration
@Bean
@ConditionalOnMissingBean
public CaptchaManager captchaManager() {
return new CaptchaManager();
}
//cache configuration
@Configuration
@Import({CaptchaCacheConfiguration.Local.class, CaptchaCacheConfiguration.Custom.class})
protected static class CaptchaCacheAutoConfiguration {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy