de.bund.bva.isyfact.task.autoconfigure.IsyTaskAutoConfiguration Maven / Gradle / Ivy
package de.bund.bva.isyfact.task.autoconfigure;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import de.bund.bva.isyfact.security.oauth2.client.Authentifizierungsmanager;
import de.bund.bva.isyfact.task.config.IsyTaskConfigurationProperties;
import de.bund.bva.isyfact.task.konfiguration.HostHandler;
import de.bund.bva.isyfact.task.konfiguration.impl.LocalHostHandlerImpl;
import de.bund.bva.isyfact.task.monitoring.IsyTaskAspect;
import de.bund.bva.isyfact.task.security.AuthenticatorFactory;
import de.bund.bva.isyfact.task.security.impl.IsySecurityAuthenticatorFactory;
import de.bund.bva.isyfact.task.security.impl.NoOpAuthenticatorFactory;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.aop.TimedAspect;
@Configuration
@EnableConfigurationProperties
@EnableScheduling
public class IsyTaskAutoConfiguration {
@Bean
@ConfigurationProperties(prefix = "isy.task")
public IsyTaskConfigurationProperties isyTaskConfigurationProperties() {
return new IsyTaskConfigurationProperties();
}
@Bean
@ConditionalOnMissingBean(HostHandler.class)
public HostHandler localHostHandler() {
return new LocalHostHandlerImpl();
}
@Bean
public IsyTaskAspect isyTaskAspect(
MeterRegistry registry,
HostHandler hostHandler,
IsyTaskConfigurationProperties isyTaskConfigurationProperties,
AuthenticatorFactory authenticatorFactory
) {
return new IsyTaskAspect(registry, hostHandler, isyTaskConfigurationProperties, authenticatorFactory);
}
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
@Bean
@ConditionalOnProperty(value = "isy.task.authentication.enabled", havingValue = "false", matchIfMissing = true)
@ConditionalOnMissingBean(AuthenticatorFactory.class)
public AuthenticatorFactory authenticatorFactoryNoOp() {
return new NoOpAuthenticatorFactory();
}
@Bean
@ConditionalOnProperty(value = "isy.task.authentication.enabled")
@ConditionalOnMissingBean(AuthenticatorFactory.class)
public AuthenticatorFactory authenticatorFactoryIsySecurity(
IsyTaskConfigurationProperties configurationProperties,
Authentifizierungsmanager authentifizierungsmanager
) {
return new IsySecurityAuthenticatorFactory(configurationProperties, authentifizierungsmanager);
}
}