Add sample for PKI Mutual-TLS client authentication method
Issue gh-1558
This commit is contained in:
@@ -131,7 +131,7 @@ public class AuthorizationServerConfig {
|
||||
// @formatter:off
|
||||
@Bean
|
||||
public JdbcRegisteredClientRepository registeredClientRepository(JdbcTemplate jdbcTemplate) {
|
||||
RegisteredClient registeredClient = RegisteredClient.withId(UUID.randomUUID().toString())
|
||||
RegisteredClient messagingClient = RegisteredClient.withId(UUID.randomUUID().toString())
|
||||
.clientId("messaging-client")
|
||||
.clientSecret("{noop}secret")
|
||||
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
|
||||
@@ -166,11 +166,25 @@ public class AuthorizationServerConfig {
|
||||
.scope("message.read")
|
||||
.build();
|
||||
|
||||
RegisteredClient mtlsDemoClient = RegisteredClient.withId(UUID.randomUUID().toString())
|
||||
.clientId("mtls-demo-client")
|
||||
.clientAuthenticationMethod(new ClientAuthenticationMethod("tls_client_auth"))
|
||||
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
|
||||
.scope("message.read")
|
||||
.scope("message.write")
|
||||
.clientSettings(
|
||||
ClientSettings.builder()
|
||||
.x509CertificateSubjectDN("CN=demo-client-sample,OU=Spring Samples,O=Spring,C=US")
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
|
||||
// Save registered client's in db as if in-memory
|
||||
JdbcRegisteredClientRepository registeredClientRepository = new JdbcRegisteredClientRepository(jdbcTemplate);
|
||||
registeredClientRepository.save(registeredClient);
|
||||
registeredClientRepository.save(messagingClient);
|
||||
registeredClientRepository.save(deviceClient);
|
||||
registeredClientRepository.save(tokenExchangeClient);
|
||||
registeredClientRepository.save(mtlsDemoClient);
|
||||
|
||||
return registeredClientRepository;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2020-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.config;
|
||||
|
||||
import org.apache.catalina.connector.Connector;
|
||||
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Joe Grandja
|
||||
* @since 1.3
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class TomcatServerConfig {
|
||||
|
||||
@Bean
|
||||
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> connectorCustomizer() {
|
||||
return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createHttpConnector());
|
||||
}
|
||||
|
||||
private Connector createHttpConnector() {
|
||||
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
|
||||
connector.setScheme("http");
|
||||
connector.setPort(9000);
|
||||
connector.setSecure(false);
|
||||
connector.setRedirectPort(9443);
|
||||
return connector;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,25 @@
|
||||
server:
|
||||
port: 9000
|
||||
port: 9443
|
||||
ssl:
|
||||
bundle: demo-authorizationserver
|
||||
client-auth: want
|
||||
|
||||
spring:
|
||||
ssl:
|
||||
bundle:
|
||||
jks:
|
||||
demo-authorizationserver:
|
||||
key:
|
||||
alias: demo-authorizationserver-sample
|
||||
password: password
|
||||
keystore:
|
||||
location: classpath:keystore.p12
|
||||
password: password
|
||||
type: PKCS12
|
||||
truststore:
|
||||
location: classpath:keystore.p12
|
||||
password: password
|
||||
type: PKCS12
|
||||
security:
|
||||
oauth2:
|
||||
client:
|
||||
|
||||
Reference in New Issue
Block a user