Skip to content

Instantly share code, notes, and snippets.

View krnbr's full-sized avatar
🏠

Karanbir Singh krnbr

🏠
  • Home
  • India
View GitHub Profile
@krnbr
krnbr / TestClientConfig.java
Last active July 19, 2020 03:17
Oauth2 Client Configuration
@Configuration
public class TestClientConfig {
@Value("${test.client.base.url}")
private String testClientBaseUrl;
private Logger testWebClientLogger = LoggerFactory.getLogger("TEST_WEB_CLIENT");
/**
* The authorizedClientManager for required by the webClient
@krnbr
krnbr / application-mtls.properties
Created July 19, 2020 09:52
mutual TLS based properties
server.port=8533
spring.security.oauth2.client.registration.local.authorization-grant-type=client_credentials
spring.security.oauth2.client.registration.local.client-id=client_id
spring.security.oauth2.client.registration.local.client-secret=client_secret
oauth2.client.provider.local.token-uri.base-path=https://localhost:8353
spring.security.oauth2.client.provider.local.token-uri=${oauth2.client.provider.local.token-uri.base-path}/oauth/token
oauth2.client.registration.local.ssl-enabled=true
\--oauth2-spring-boot-client - Root
| .gitignore - Git management for ignoring not required files
| pom.xml - Maven pom.xml
+---src
| +---main
| | +---java
| | | \---in
| | | \---neuw
| | | \---oauth2
| | | | Oauth2SpringBootClientApplication.java - The SpringBootApplication main class.
// pass the base 64 encoded String of the Keystore and keystore password
KeyManagerFactory keyManagerFactory = SSLContextHelper.getKeyStore(encodedKeystoreString, keystorePassword);
// pass the base 64 encoded String of the Truststore and truststore password
TrustManagerFactory trustManagerFactory = SSLContextHelper.getTrustStore(encodedTruststoreString, truststorePassword);
// Construct the SslContext using keyManagerFactory & trustManagerFactory
SslContext sslContext = SSLContextHelper.sslContext(keyManagerFactory, trustManagerFactory);
HttpClient resourceServerHttpClient = HttpClient.create()
.tcpConfiguration(client -> client.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000))
.secure(sslContextSpec -> {
@Bean
fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain? {
val httpClient = HttpClient.create()
.tcpConfiguration{client -> client.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)}
.secure { sslContextSpec: SslProvider.SslContextSpec -> sslContextSpec.sslContext(sslContextBuilder(keyStoreContent, keyStorePassword, trustStoreContent, trustStorePassword)) }
val httpConnector: ClientHttpConnector = ReactorClientHttpConnector(httpClient)
val builder = NimbusReactiveJwtDecoder
.withJwkSetUri("https://<host>/.well-known/jwks.json")
@krnbr
krnbr / TestController
Last active July 23, 2020 05:48
TestController And TestDto
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import javax.validation.Valid;
/**
* @author Karanbir Singh on 07/23/2020
*/
@RestController
@krnbr
krnbr / TestController.java
Created July 23, 2020 06:11
Custom tags and info open api
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import javax.validation.Valid;
@krnbr
krnbr / pom.xml
Last active July 23, 2020 06:37
Spring Boot Webflux Open API 3 Swagger Specs pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath />
<!-- lookup parent from repository -->
</parent>
<groupId>in.neuw</groupId>
@krnbr
krnbr / ApisApplication.java
Last active July 23, 2020 06:43
The Spring boot Main Application
package in.neuw.apis;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
@SpringBootApplication
@krnbr
krnbr / application.yaml
Created September 1, 2021 19:49
application.yaml for the article
resilience4j:
circuitbreaker:
instances:
mockService:
slidingWindowSize: 3
slidingWindowType: COUNT_BASED
#waitDurationInOpenState: 5
waitInterval: 10000
failureRateThreshold: 50
permittedNumberOfCallsInHalfOpenState: 5