OAuth2ClientAuthenticationFilter:
OAuth2ClientAuthenticationToken -> ClientSecretAuthenticationProvider -> OAuth2ClientAuthenticationToken
OAuth2TokenEndpointFilter:
OAuth2ClientCredentialsAuthenticationToken -> OAuth2ClientCredentialsAuthenticationProvider -> OAuth2AccessTokenAuthenticationToken
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class PreConfigDataEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { | |
@Override | |
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { | |
PropertiesPropertySourceLoader propertiesPropertySourceLoader = new PropertiesPropertySourceLoader(); | |
try { | |
List<PropertySource<?>> propertySources = propertiesPropertySourceLoader.load("Config resource 'class path resource [application.properties]' via location 'optional:classpath:/'", | |
new ClassPathResource("/application.properties")); | |
propertySources.stream().forEach((PropertySource<?> propertySource) -> { | |
Object springProfilesActive = propertySource.getProperty("spring.profiles.active"); | |
if (springProfilesActive instanceof String springProfilesActiveString) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
record $MODEL$(long id, String name) {} | |
@Bean | |
@Qualifier("$DCMODEL$-rest-client") | |
RestClient $DCMODEL$RestClient(RestClient.Builder builder) { | |
return builder.baseUrl("https://$DCMODEL$.api.com/$MODEL$s").build(); | |
} | |
interface $MODEL$Service { | |
@GetExchange |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sandipchitale.webclient; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.http.HttpHeaders; | |
import org.springframework.http.HttpStatusCode; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.http.client.reactive.ClientHttpRequest; | |
import org.springframework.http.server.reactive.ServerHttpRequest; | |
import org.springframework.web.bind.annotation.*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body(BodyInserters.fromResource(new InputStreamResource(inputStream))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public WebSecurityCustomizer webSecurityCustomizer() { | |
return (web) -> web.ignoring() | |
.requestMatchers( | |
// To avoid wrapping in MvcMatcher make sure to use AntPathRequestMatcher | |
AntPathRequestMatcher.antMatcher("/index.html"), | |
AntPathRequestMatcher.antMatcher("/**/*.css") | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
@Order(Ordered.HIGHEST_PRECEDENCE) | |
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity httpSecurity, | |
OAuth2TokenGenerator<?> tokenGenerator, | |
RegisteredClientRepository registeredClientRepository) throws Exception { | |
OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(httpSecurity); | |
OAuth2AuthorizationServerConfigurer oAuth2AuthorizationServerConfigurer = | |
httpSecurity.getConfigurer(OAuth2AuthorizationServerConfigurer.class); | |
oAuth2AuthorizationServerConfigurer.registeredClientRepository(registeredClientRepository); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Order(Ordered.LOWEST_PRECEDENCE) | |
public static class OAuth2ClientPropertiesSchemeAdjusterEnvironmentPostProcessor implements EnvironmentPostProcessor { | |
@Override | |
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { | |
String asScheme = "http"; | |
if ("true".equals(environment.getProperty("server.ssl.enabled"))) { | |
asScheme = "https"; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class OAuth2ClientPropertiesSchemeAdjusterBeanPostProcessor implements BeanPostProcessor, EnvironmentAware { | |
private Environment environment; | |
@Override | |
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | |
if (bean instanceof OAuth2ClientProperties oAuth2ClientProperties) { | |
String tokenUri = oAuth2ClientProperties.getProvider().get("as").getTokenUri(); | |
if ("true".equals(environment.getProperty("server.ssl.enabled"))) { |