Add sample for PKI Mutual-TLS client authentication method

Issue gh-1558
This commit is contained in:
Joe Grandja
2024-03-15 10:13:25 -04:00
parent 8361dabdbf
commit d6a87532a9
11 changed files with 253 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020-2022 the original author or authors.
* 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.
@@ -17,6 +17,7 @@ package sample.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@@ -34,11 +35,12 @@ public class ResourceServerConfig {
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.securityMatcher("/messages/**")
.authorizeHttpRequests()
.requestMatchers("/messages/**").hasAuthority("SCOPE_message.read")
.and()
.oauth2ResourceServer()
.jwt();
.authorizeHttpRequests(authorize ->
authorize.requestMatchers("/messages/**").hasAuthority("SCOPE_message.read")
)
.oauth2ResourceServer(oauth2ResourceServer ->
oauth2ResourceServer.jwt(Customizer.withDefaults())
);
return http.build();
}
// @formatter:on