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
<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> |
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 | |
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") |
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
// 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 -> { |
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
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 |
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
\--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. |
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
spring.security.oauth2.client.registration.<identifier>.authorization-grant-type=client_credentials | |
spring.security.oauth2.client.registration.<identifier>.client-id=client_id | |
spring.security.oauth2.client.registration.<identifier>.client-secret=client_secret | |
spring.security.oauth2.client.provider.<identifier>.token-uri=http://localhost:8353/oauth/token |
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
@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 |
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
\--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. |
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
public class JKStoBase64String { | |
private static final int BUFFER_SIZE = 65535; | |
public static byte[] convertFileToByteArray(String certificateFilePath) throws Exception { | |
if (certificateFilePath == null || certificateFilePath.isEmpty()) { | |
throw new Exception("file path should not be null or empty"); | |
} | |
File file = new File(certificateFilePath); | |
if (!file.exists()) { | |
throw new Exception("file not exist : " + file.getAbsolutePath()); |
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
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-oauth2-jose</artifactId> | |
</dependency> |