com.atlassian.connect.spring.internal.AtlassianConnectAutoConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atlassian-connect-spring-boot-core Show documentation
Show all versions of atlassian-connect-spring-boot-core Show documentation
Provides the core of Atlassian Connect for Spring Boot
package com.atlassian.connect.spring.internal;
import com.atlassian.connect.spring.internal.auth.LifecycleURLHelper;
import com.atlassian.connect.spring.internal.auth.jwt.JwtAuthenticationFilter;
import com.atlassian.connect.spring.internal.descriptor.AddonDescriptorLoader;
import com.atlassian.connect.spring.internal.request.oauth2.OAuth2JwtClientRegistrationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Atlassian Connect add-ons.
*/
@Configuration
@ComponentScan(basePackageClasses = {AtlassianConnectAutoConfiguration.class})
@EnableConfigurationProperties(AtlassianConnectProperties.class)
@ConditionalOnResource(resources = AddonDescriptorLoader.DESCRIPTOR_RESOURCE_PATH)
@EnableCaching
@EnableAsync
public class AtlassianConnectAutoConfiguration {
@Bean
public FilterRegistrationBean jwtAuthenticationFilterRegistrationBean(AuthenticationManager authenticationManager,
AddonDescriptorLoader addonDescriptorLoader,
AtlassianConnectProperties atlassianConnectProperties,
ServerProperties serverProperties,
LifecycleURLHelper lifecycleURLHelper) {
FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new JwtAuthenticationFilter(authenticationManager, addonDescriptorLoader,
atlassianConnectProperties, serverProperties, lifecycleURLHelper));
registrationBean.setOrder(atlassianConnectProperties.getJwtFilterOrder());
return registrationBean;
}
@Autowired
@Qualifier("oauth2-jwt-impersonation")
OAuth2JwtClientRegistrationRepository clientRegistrationRepository;
@Bean
OAuth2AuthorizedClientService authorizedClientService() {
return new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository);
}
@Configuration
@PropertySource("classpath:config/default.properties")
static class Defaults {
}
@Configuration
@Profile("production")
@PropertySource({"classpath:config/default.properties", "classpath:config/production.properties"})
static class Production {
}
}