Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
Marcus Da Coregio | 7d9bf3ecd4 | |
Marcus Da Coregio | 46b4e25e7a | |
Marcus Da Coregio | fb1a0e96c0 | |
Marcus Da Coregio | bb7b822ada | |
Eleftheria Stein | 23b80ce2d8 | |
Eleftheria Stein | 9d13cfee7b | |
Marcus Da Coregio | 5db444a305 | |
Marcus Da Coregio | 90e38e4670 | |
Marcus Da Coregio | f3d83b373c | |
Marcus Da Coregio | e78a1f73ef | |
Marcus Da Coregio | 1181eb2b3d | |
Marcus Da Coregio | 526bc16f7e |
24
build.gradle
24
build.gradle
|
@ -20,4 +20,26 @@ allprojects {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasProperty('buildScan')) {
|
||||||
|
buildScan {
|
||||||
|
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
|
||||||
|
termsOfServiceAgree = 'yes'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('runAllTests') {
|
||||||
|
var allTasks = rootProject.getAllTasks(true)
|
||||||
|
var allTestsTasks = allTasks.values().collect { t ->
|
||||||
|
t.findAll { it.name == 'test' || it.name == 'integrationTest' }
|
||||||
|
}.flatten()
|
||||||
|
it.dependsOn {
|
||||||
|
allTestsTasks
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError
|
org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
org.gradle.caching=true
|
org.gradle.caching=true
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class HelloTests {
|
public class HelloTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -19,4 +19,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class HelloTests {
|
public class HelloTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -25,4 +25,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -23,4 +23,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class HelloSecurityTests {
|
public class HelloSecurityTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class HelloSecurityTests {
|
public class HelloSecurityTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -19,4 +19,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class HelloTests {
|
public class HelloTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class HelloMethodApplicationTests {
|
public class HelloMethodApplicationTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -24,4 +24,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -36,7 +36,7 @@ import static org.springframework.security.test.web.reactive.server.SecurityMock
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class OAuth2LoginApplicationTests {
|
public class OAuth2LoginApplicationTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
@ActiveProfiles("test")
|
@ActiveProfiles("test")
|
||||||
public class ServerOAuth2ResourceServerApplicationITests {
|
public class ServerOAuth2ResourceServerApplicationITests {
|
||||||
|
|
||||||
|
|
|
@ -24,4 +24,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -39,7 +39,7 @@ import static org.springframework.security.test.web.reactive.server.SecurityMock
|
||||||
|
|
||||||
@WebFluxTest
|
@WebFluxTest
|
||||||
@Import({ SecurityConfiguration.class, OAuth2WebClientController.class })
|
@Import({ SecurityConfiguration.class, OAuth2WebClientController.class })
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class OAuth2WebClientControllerTests {
|
public class OAuth2WebClientControllerTests {
|
||||||
|
|
||||||
private static MockWebServer web = new MockWebServer();
|
private static MockWebServer web = new MockWebServer();
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class OAuth2WebClientWebFluxApplicationTests {
|
public class OAuth2WebClientWebFluxApplicationTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -39,7 +39,7 @@ import static org.springframework.security.test.web.reactive.server.SecurityMock
|
||||||
|
|
||||||
@WebFluxTest
|
@WebFluxTest
|
||||||
@Import({ SecurityConfiguration.class, RegisteredOAuth2AuthorizedClientController.class })
|
@Import({ SecurityConfiguration.class, RegisteredOAuth2AuthorizedClientController.class })
|
||||||
@AutoConfigureWebTestClient
|
@AutoConfigureWebTestClient(timeout = "36000")
|
||||||
public class RegisteredOAuth2AuthorizedClientControllerTests {
|
public class RegisteredOAuth2AuthorizedClientControllerTests {
|
||||||
|
|
||||||
private static MockWebServer web = new MockWebServer();
|
private static MockWebServer web = new MockWebServer();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -14,7 +14,7 @@ dependencies {
|
||||||
aspect "org.springframework.security:spring-security-aspects"
|
aspect "org.springframework.security:spring-security-aspects"
|
||||||
|
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -31,6 +31,7 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -34,4 +34,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,26 +18,27 @@ package example;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
// @formatter:off
|
@Bean
|
||||||
@Override
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.antMatchers("/login", "/resources/**").permitAll()
|
.antMatchers("/login", "/resources/**").permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.jee((jee) -> jee.mappableRoles("USER", "ADMIN"));
|
.jee((jee) -> jee.mappableRoles("USER", "ADMIN"));
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -34,4 +34,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
|
@ -18,31 +18,30 @@ package example;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import static org.springframework.security.config.Customizer.withDefaults;
|
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
// @formatter:off
|
public SecurityFilterChain securityFilterChain(HttpSecurity http, UserDetailsService users) throws Exception {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeRequests((authorize) -> authorize
|
.authorizeRequests((authorize) -> authorize
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.formLogin((form) -> form
|
.formLogin((form) -> form
|
||||||
.loginPage("/login")
|
.loginPage("/login")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
)
|
)
|
||||||
.rememberMe(withDefaults());
|
.rememberMe((rememberMe) -> rememberMe.userDetailsService(users));
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -34,4 +34,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,28 +18,29 @@ package example;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
// @formatter:off
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeRequests((authorize) -> authorize
|
.authorizeRequests((authorize) -> authorize
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.formLogin((form) -> form
|
.formLogin((form) -> form
|
||||||
.loginPage("/login")
|
.loginPage("/login")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
);
|
);
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -34,4 +34,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,13 @@ package example;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.hsqldb:hsqldb:2.5.1"
|
implementation "org.hsqldb:hsqldb:2.5.1"
|
||||||
|
@ -36,4 +36,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,8 @@ public class DataSourceConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
public DataSource dataSource() {
|
public DataSource dataSource() {
|
||||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
||||||
return builder.setType(EmbeddedDatabaseType.HSQL).build();
|
return builder.setType(EmbeddedDatabaseType.HSQL)
|
||||||
|
.addScript("classpath:org/springframework/security/core/userdetails/jdbc/users.ddl").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,28 +17,27 @@ package example;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.provisioning.JdbcUserDetailsManager;
|
||||||
|
import org.springframework.security.provisioning.UserDetailsManager;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Autowired
|
@Bean
|
||||||
DataSource dataSource;
|
UserDetailsManager users(DataSource dataSource) {
|
||||||
|
UserDetails user = User.builder().username("user")
|
||||||
// @formatter:off
|
.password("{bcrypt}$2a$10$AiyMWI4UBLozgXq6itzyVuxrtofjcPzn/WS3fOrcqgzdax9jB7Io.").roles("USER").build();
|
||||||
@Autowired
|
UserDetails admin = User.builder().username("admin")
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
.password("{bcrypt}$2a$10$AiyMWI4UBLozgXq6itzyVuxrtofjcPzn/WS3fOrcqgzdax9jB7Io.").roles("USER", "ADMIN")
|
||||||
auth
|
.build();
|
||||||
.jdbcAuthentication()
|
JdbcUserDetailsManager users = new JdbcUserDetailsManager(dataSource);
|
||||||
.dataSource(this.dataSource)
|
users.createUser(user);
|
||||||
.withDefaultSchema()
|
users.createUser(admin);
|
||||||
.withUser(User.withDefaultPasswordEncoder().username("user").password("password").roles("USER"))
|
return users;
|
||||||
.withUser(User.withDefaultPasswordEncoder().username("admin").password("password").roles("ADMIN", "USER"));
|
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -37,4 +37,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -32,4 +32,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,27 +18,28 @@ package example;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
import static org.springframework.security.config.Customizer.withDefaults;
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
// @formatter:off
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.x509(withDefaults());
|
.x509(withDefaults());
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -9,9 +9,9 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.11")
|
||||||
implementation platform("org.springframework.data:spring-data-releasetrain:Neumann-SR5")
|
implementation platform("org.springframework.data:spring-data-releasetrain:Neumann-SR9")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -34,4 +34,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -34,4 +34,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,28 +18,29 @@ package example;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
import static org.springframework.security.config.Customizer.withDefaults;
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
// @formatter:off
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.httpBasic(withDefaults())
|
.httpBasic(withDefaults())
|
||||||
.formLogin(withDefaults());
|
.formLogin(withDefaults());
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -37,4 +37,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,28 +18,29 @@ package example;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
import static org.springframework.security.config.Customizer.withDefaults;
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
// @formatter:off
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.httpBasic(withDefaults())
|
.httpBasic(withDefaults())
|
||||||
.formLogin(withDefaults());
|
.formLogin(withDefaults());
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -37,4 +37,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -34,4 +34,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,35 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
import static org.springframework.security.config.Customizer.withDefaults;
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
// @formatter:off
|
||||||
|
http
|
||||||
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
|
.anyRequest().authenticated()
|
||||||
|
)
|
||||||
|
.formLogin(withDefaults())
|
||||||
|
.sessionManagement((sessions) -> sessions
|
||||||
|
.sessionConcurrency((concurrency) -> concurrency
|
||||||
|
.maximumSessions(1)
|
||||||
|
.expiredUrl("/login?expired")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
|
}
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -44,21 +62,4 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||||
}
|
}
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
// @formatter:off
|
|
||||||
@Override
|
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
|
||||||
http
|
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
|
||||||
.anyRequest().authenticated()
|
|
||||||
)
|
|
||||||
.formLogin(withDefaults())
|
|
||||||
.sessionManagement((sessions) -> sessions
|
|
||||||
.sessionConcurrency((concurrency) -> concurrency
|
|
||||||
.maximumSessions(1)
|
|
||||||
.expiredUrl("/login?expired")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ It uses https://simplesamlphp.org/[SimpleSAMLphp] as its asserting party.
|
||||||
The sample application uses Spring Boot and the `spring-security-saml2-service-provider`
|
The sample application uses Spring Boot and the `spring-security-saml2-service-provider`
|
||||||
module which is new in Spring Security 5.2.
|
module which is new in Spring Security 5.2.
|
||||||
|
|
||||||
The https://docs.spring.io/spring-security/site/docs/5.6.0-SNAPSHOT/reference/html5/#servlet-saml2login-logout[SAML 2.0 Logout feature] is new in Spring Security 5.6.
|
The https://docs.spring.io/spring-security/reference/servlet/saml2/logout.html[SAML 2.0 Logout feature] is new in Spring Security 5.6.
|
||||||
|
|
||||||
== Goals
|
== Goals
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ The following features are implemented in the MVP:
|
||||||
|
|
||||||
On this sample, the SAML 2.0 Logout is using the HTTP-POST binding.
|
On this sample, the SAML 2.0 Logout is using the HTTP-POST binding.
|
||||||
|
|
||||||
You can refer to the https://docs.spring.io/spring-security/site/docs/5.6.0-SNAPSHOT/reference/html5/#servlet-saml2login-logout[reference documentation] for more details about the RP- and AP-initiated SAML 2.0 Logout.
|
You can refer to the https://docs.spring.io/spring-security/reference/servlet/saml2/logout.html[reference documentation] for more details about the RP- and AP-initiated SAML 2.0 Logout.
|
||||||
|
|
||||||
== Run the Sample
|
== Run the Sample
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ dependencies {
|
||||||
implementation "org.opensaml:opensaml-saml-impl:4.1.1"
|
implementation "org.opensaml:opensaml-saml-impl:4.1.1"
|
||||||
}
|
}
|
||||||
implementation platform("org.springframework:spring-framework-bom:5.3.11")
|
implementation platform("org.springframework:spring-framework-bom:5.3.11")
|
||||||
implementation platform("org.springframework.security:spring-security-bom:5.6.0-SNAPSHOT")
|
implementation platform("org.springframework.security:spring-security-bom:5.6.0")
|
||||||
implementation platform("org.junit:junit-bom:5.7.0")
|
implementation platform("org.junit:junit-bom:5.7.0")
|
||||||
|
|
||||||
implementation "org.springframework.security:spring-security-config"
|
implementation "org.springframework.security:spring-security-config"
|
||||||
|
@ -63,4 +63,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -20,4 +20,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -23,4 +23,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -20,10 +20,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
import static org.springframework.security.config.Customizer.withDefaults;
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
|
@ -34,19 +34,20 @@ import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
// @formatter:off
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.httpBasic(withDefaults())
|
.httpBasic(withDefaults())
|
||||||
.formLogin(withDefaults());
|
.formLogin(withDefaults());
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -19,4 +19,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -19,4 +19,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.Customizer;
|
import org.springframework.security.config.Customizer;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
|
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
|
||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
|
@ -43,6 +42,7 @@ import org.springframework.security.oauth2.jwt.NimbusJwtEncoder;
|
||||||
import org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationEntryPoint;
|
import org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationEntryPoint;
|
||||||
import org.springframework.security.oauth2.server.resource.web.access.BearerTokenAccessDeniedHandler;
|
import org.springframework.security.oauth2.server.resource.web.access.BearerTokenAccessDeniedHandler;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Security configuration for the main application.
|
* Security configuration for the main application.
|
||||||
|
@ -50,7 +50,7 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
* @author Josh Cummings
|
* @author Josh Cummings
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class RestConfig extends WebSecurityConfigurerAdapter {
|
public class RestConfig {
|
||||||
|
|
||||||
@Value("${jwt.public.key}")
|
@Value("${jwt.public.key}")
|
||||||
RSAPublicKey key;
|
RSAPublicKey key;
|
||||||
|
@ -58,22 +58,23 @@ public class RestConfig extends WebSecurityConfigurerAdapter {
|
||||||
@Value("${jwt.private.key}")
|
@Value("${jwt.private.key}")
|
||||||
RSAPrivateKey priv;
|
RSAPrivateKey priv;
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.csrf((csrf) -> csrf.ignoringAntMatchers("/token"))
|
.csrf((csrf) -> csrf.ignoringAntMatchers("/token"))
|
||||||
.httpBasic(Customizer.withDefaults())
|
.httpBasic(Customizer.withDefaults())
|
||||||
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
|
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
|
||||||
.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
.exceptionHandling((exceptions) -> exceptions
|
.exceptionHandling((exceptions) -> exceptions
|
||||||
.authenticationEntryPoint(new BearerTokenAuthenticationEntryPoint())
|
.authenticationEntryPoint(new BearerTokenAuthenticationEntryPoint())
|
||||||
.accessDeniedHandler(new BearerTokenAccessDeniedHandler())
|
.accessDeniedHandler(new BearerTokenAccessDeniedHandler())
|
||||||
);
|
);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -16,10 +16,12 @@
|
||||||
|
|
||||||
package example.web;
|
package example.web;
|
||||||
|
|
||||||
|
import example.RestConfig;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
|
||||||
|
@ -35,6 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
* @author Josh Cummings
|
* @author Josh Cummings
|
||||||
*/
|
*/
|
||||||
@WebMvcTest({ HelloController.class, TokenController.class })
|
@WebMvcTest({ HelloController.class, TokenController.class })
|
||||||
|
@Import(RestConfig.class)
|
||||||
public class HelloControllerTests {
|
public class HelloControllerTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -22,4 +22,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -24,4 +24,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
|
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
|
||||||
import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest;
|
import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest;
|
||||||
|
@ -63,6 +62,7 @@ import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
|
||||||
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
|
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
|
||||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||||
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
|
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.web.util.UriComponents;
|
import org.springframework.web.util.UriComponents;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
@ -328,21 +328,22 @@ public class OAuth2LoginApplicationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public static class SecurityTestConfig extends WebSecurityConfigurerAdapter {
|
public static class SecurityTestConfig {
|
||||||
|
|
||||||
// @formatter:off
|
@Bean
|
||||||
@Override
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.oauth2Login((oauth2) -> oauth2
|
.oauth2Login((oauth2) -> oauth2
|
||||||
.tokenEndpoint((token) -> token.accessTokenResponseClient(mockAccessTokenResponseClient()))
|
.tokenEndpoint((token) -> token.accessTokenResponseClient(mockAccessTokenResponseClient()))
|
||||||
.userInfoEndpoint((userInfo) -> userInfo.userService(mockUserService()))
|
.userInfoEndpoint((userInfo) -> userInfo.userService(mockUserService()))
|
||||||
);
|
);
|
||||||
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
private OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> mockAccessTokenResponseClient() {
|
private OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> mockAccessTokenResponseClient() {
|
||||||
OAuth2AccessTokenResponse accessTokenResponse = OAuth2AccessTokenResponse.withToken("access-token-1234")
|
OAuth2AccessTokenResponse accessTokenResponse = OAuth2AccessTokenResponse.withToken("access-token-1234")
|
||||||
|
|
|
@ -21,4 +21,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -20,10 +20,10 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
|
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
|
||||||
import org.springframework.security.oauth2.jwt.JwtDecoder;
|
import org.springframework.security.oauth2.jwt.JwtDecoder;
|
||||||
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
|
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth resource configuration.
|
* OAuth resource configuration.
|
||||||
|
@ -31,22 +31,23 @@ import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
|
||||||
* @author Josh Cummings
|
* @author Josh Cummings
|
||||||
*/
|
*/
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class OAuth2ResourceServerSecurityConfiguration {
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri}")
|
@Value("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri}")
|
||||||
String jwkSetUri;
|
String jwkSetUri;
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.antMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
|
.antMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
|
||||||
.antMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
|
.antMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
|
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@WebMvcTest(OAuth2ResourceServerController.class)
|
@WebMvcTest(OAuth2ResourceServerController.class)
|
||||||
|
@Import(OAuth2ResourceServerSecurityConfiguration.class)
|
||||||
public class OAuth2ResourceServerControllerTests {
|
public class OAuth2ResourceServerControllerTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -37,4 +37,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -42,9 +42,9 @@ import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.oauth2.jwt.JwtDecoder;
|
import org.springframework.security.oauth2.jwt.JwtDecoder;
|
||||||
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
|
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
import static org.springframework.security.config.Customizer.withDefaults;
|
import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ import static org.springframework.security.config.Customizer.withDefaults;
|
||||||
* @author Josh Cummings
|
* @author Josh Cummings
|
||||||
*/
|
*/
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class OAuth2ResourceServerSecurityConfiguration {
|
||||||
|
|
||||||
private final JWSAlgorithm jwsAlgorithm = JWSAlgorithm.RS256;
|
private final JWSAlgorithm jwsAlgorithm = JWSAlgorithm.RS256;
|
||||||
|
|
||||||
|
@ -68,16 +68,17 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
|
||||||
@Value("${sample.jwe-key-value}")
|
@Value("${sample.jwe-key-value}")
|
||||||
RSAPrivateKey key;
|
RSAPrivateKey key;
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.antMatchers("/message/**").hasAuthority("SCOPE_message:read")
|
.antMatchers("/message/**").hasAuthority("SCOPE_message:read")
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.oauth2ResourceServer((oauth2) -> oauth2.jwt(withDefaults()));
|
.oauth2ResourceServer((oauth2) -> oauth2.jwt(withDefaults()));
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -38,4 +38,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -38,4 +38,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
|
@ -16,10 +16,11 @@
|
||||||
package example;
|
package example;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth2 Security Configuration.
|
* OAuth2 Security Configuration.
|
||||||
|
@ -27,7 +28,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
||||||
* @author Josh Cummings
|
* @author Josh Cummings
|
||||||
*/
|
*/
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class OAuth2ResourceServerSecurityConfiguration {
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.resourceserver.opaque.introspection-uri}")
|
@Value("${spring.security.oauth2.resourceserver.opaque.introspection-uri}")
|
||||||
String introspectionUri;
|
String introspectionUri;
|
||||||
|
@ -38,22 +39,23 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
|
||||||
@Value("${spring.security.oauth2.resourceserver.opaque.introspection-client-secret}")
|
@Value("${spring.security.oauth2.resourceserver.opaque.introspection-client-secret}")
|
||||||
String clientSecret;
|
String clientSecret;
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
http
|
http
|
||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.mvcMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
|
.mvcMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
|
||||||
.mvcMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
|
.mvcMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
|
||||||
.oauth2ResourceServer((oauth2) -> oauth2
|
|
||||||
.opaqueToken((opaque) -> opaque
|
|
||||||
.introspectionUri(this.introspectionUri)
|
|
||||||
.introspectionClientCredentials(this.clientId, this.clientSecret)
|
|
||||||
)
|
)
|
||||||
);
|
.oauth2ResourceServer((oauth2) -> oauth2
|
||||||
|
.opaqueToken((opaque) -> opaque
|
||||||
|
.introspectionUri(this.introspectionUri)
|
||||||
|
.introspectionClientCredentials(this.clientId, this.clientSecret)
|
||||||
|
)
|
||||||
|
);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
|
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
@ -36,6 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
@WebMvcTest(OAuth2ResourceServerController.class)
|
@WebMvcTest(OAuth2ResourceServerController.class)
|
||||||
|
@Import(OAuth2ResourceServerSecurityConfiguration.class)
|
||||||
public class OAuth2ResourceServerControllerTests {
|
public class OAuth2ResourceServerControllerTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -37,4 +37,5 @@ dependencies {
|
||||||
|
|
||||||
tasks.withType(Test).configureEach {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
}
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
version=5.6.0-SNAPSHOT
|
version=5.6.0
|
||||||
spring-security.version=5.6.0-SNAPSHOT
|
spring-security.version=5.6.0
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue