Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠

Karanbir Singh krnbr

🏠
  • Home
  • India
View GitHub Profile
View Setup-Ubuntu.md

sudo apt install chrony -y

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

sudo passwd root

sudo systemctl restart ssh

View MockServiceClientSnippet.java
@CircuitBreaker(name = "mockService", fallbackMethod = "fallback")
public Mono<MockServiceResponse> getMockServiceResponse() {
return mockServiceWebClient.get()
.uri(DOWNSTREAM_PATH)
.retrieve()
.bodyToMono(MockServiceResponse.class)
.doOnError(ex -> {
throw new RuntimeException("the exception message is - "+ex.getMessage());
});
}
@krnbr
krnbr / application.yaml
Created Sep 1, 2021
application.yaml for the article
View application.yaml
resilience4j:
circuitbreaker:
instances:
mockService:
slidingWindowSize: 3
slidingWindowType: COUNT_BASED
#waitDurationInOpenState: 5
waitInterval: 10000
failureRateThreshold: 50
permittedNumberOfCallsInHalfOpenState: 5
@krnbr
krnbr / TestController.java
Created Jul 23, 2020
Custom tags and info open api
View TestController.java
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 / TestController
Last active Jul 23, 2020
TestController And TestDto
View TestController
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 / ApisApplication.java
Last active Jul 23, 2020
The Spring boot Main Application
View ApisApplication.java
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 / pom.xml
Last active Jul 23, 2020
Spring Boot Webflux Open API 3 Swagger Specs pom.xml
View 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>
View Config.java
@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")
View ResourceServerWebClientChanges.java
// 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 -> {
@krnbr
krnbr / application-mtls.properties
Created Jul 19, 2020
mutual TLS based properties
View application-mtls.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