OAuth2ClientAuthenticationFilter:
OAuth2ClientAuthenticationToken -> ClientSecretAuthenticationProvider -> OAuth2ClientAuthenticationToken
OAuth2TokenEndpointFilter:
OAuth2ClientCredentialsAuthenticationToken -> OAuth2ClientCredentialsAuthenticationProvider -> OAuth2AccessTokenAuthenticationToken
This file contains 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 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 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 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 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 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"))) { |
This file contains 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
import jakarta.servlet.ServletContext; | |
import jakarta.servlet.http.HttpServletRequest; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.core.env.Environment; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
This file contains 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 | |
@ConditionalOnWebApplication | |
@ConditionalOnNotWarDeployment() | |
public CommandLineRunner clrNotInWar() { | |
return (args) -> { | |
System.out.println("Not running as war!"); | |
}; | |
} | |
static class OnWarDeployment extends NoneNestedConditions { |