File tree Expand file tree Collapse file tree 14 files changed +224
-144
lines changed
helloworld/src/main/java/org/springframework/security/samples/config
oauth2login/src/integration-test/java/org/springframework/security/samples
oauth2resourceserver/src/main/java/sample
oauth2resourceserver-jwe/src/main/java/sample
oauth2resourceserver-multitenancy/src/main/java/sample
oauth2resourceserver-opaque/src/main/java/sample
oauth2resourceserver-static/src/main/java/sample
oauth2webclient/src/main/java/sample/config
concurrency/src/main/java/org/springframework/security/samples/config
form/src/main/java/org/springframework/security/samples/config
openid/src/main/java/org/springframework/security/samples/config
preauth/src/main/java/org/springframework/security/samples/config
rememberme/src/main/java/org/springframework/security/samples/config
x509/src/main/java/org/springframework/security/samples/config Expand file tree Collapse file tree 14 files changed +224
-144
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -32,11 +32,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
32
32
@ Override
33
33
protected void configure (HttpSecurity http ) throws Exception {
34
34
http
35
- .authorizeRequests ()
36
- .antMatchers ("/css/**" , "/index" ).permitAll ()
37
- .antMatchers ("/user/**" ).hasRole ("USER" )
38
- .and ()
39
- .formLogin ().loginPage ("/login" ).failureUrl ("/login-error" );
35
+ .authorizeRequests (authorizeRequests ->
36
+ authorizeRequests
37
+ .antMatchers ("/css/**" , "/index" ).permitAll ()
38
+ .antMatchers ("/user/**" ).hasRole ("USER" )
39
+ )
40
+ .formLogin (formLogin ->
41
+ formLogin
42
+ .loginPage ("/login" )
43
+ .failureUrl ("/login-error" )
44
+ );
40
45
}
41
46
// @formatter:on
42
47
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -358,15 +358,21 @@ public static class SecurityTestConfig extends WebSecurityConfigurerAdapter {
358
358
@ Override
359
359
protected void configure (HttpSecurity http ) throws Exception {
360
360
http
361
- .authorizeRequests ()
362
- .anyRequest ().authenticated ()
363
- .and ()
364
- .oauth2Login ()
365
- .tokenEndpoint ()
366
- .accessTokenResponseClient (this .mockAccessTokenResponseClient ())
367
- .and ()
368
- .userInfoEndpoint ()
369
- .userService (this .mockUserService ());
361
+ .authorizeRequests (authorizeRequests ->
362
+ authorizeRequests
363
+ .anyRequest ().authenticated ()
364
+ )
365
+ .oauth2Login (oauth2Login ->
366
+ oauth2Login
367
+ .tokenEndpoint (tokenEndpoint ->
368
+ tokenEndpoint
369
+ .accessTokenResponseClient (this .mockAccessTokenResponseClient ())
370
+ )
371
+ .userInfoEndpoint (userInfoEndpoint ->
372
+ userInfoEndpoint
373
+ .userService (this .mockUserService ())
374
+ )
375
+ );
370
376
}
371
377
// @formatter:on
372
378
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
46
46
import org .springframework .security .oauth2 .jwt .JwtDecoder ;
47
47
import org .springframework .security .oauth2 .jwt .NimbusJwtDecoder ;
48
48
49
+ import static org .springframework .security .config .Customizer .withDefaults ;
50
+
49
51
/**
50
52
* @author Josh Cummings
51
53
*/
@@ -66,12 +68,15 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
66
68
protected void configure (HttpSecurity http ) throws Exception {
67
69
// @formatter:off
68
70
http
69
- .authorizeRequests ()
70
- .antMatchers ("/message/**" ).hasAuthority ("SCOPE_message:read" )
71
- .anyRequest ().authenticated ()
72
- .and ()
73
- .oauth2ResourceServer ()
74
- .jwt ();
71
+ .authorizeRequests (authorizeRequests ->
72
+ authorizeRequests
73
+ .antMatchers ("/message/**" ).hasAuthority ("SCOPE_message:read" )
74
+ .anyRequest ().authenticated ()
75
+ )
76
+ .oauth2ResourceServer (oauth2ResourceServer ->
77
+ oauth2ResourceServer
78
+ .jwt (withDefaults ())
79
+ );
75
80
// @formatter:on
76
81
}
77
82
Original file line number Diff line number Diff line change @@ -51,12 +51,15 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
51
51
protected void configure (HttpSecurity http ) throws Exception {
52
52
// @formatter:off
53
53
http
54
- .authorizeRequests ()
55
- .antMatchers ("/**/message/**" ).hasAuthority ("SCOPE_message:read" )
56
- .anyRequest ().authenticated ()
57
- .and ()
58
- .oauth2ResourceServer ()
59
- .authenticationManagerResolver (multitenantAuthenticationManager ());
54
+ .authorizeRequests (authorizeRequests ->
55
+ authorizeRequests
56
+ .antMatchers ("/**/message/**" ).hasAuthority ("SCOPE_message:read" )
57
+ .anyRequest ().authenticated ()
58
+ )
59
+ .oauth2ResourceServer (oauth2ResourceServer ->
60
+ oauth2ResourceServer
61
+ .authenticationManagerResolver (multitenantAuthenticationManager ())
62
+ );
60
63
// @formatter:on
61
64
}
62
65
Original file line number Diff line number Diff line change @@ -34,14 +34,19 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
34
34
protected void configure (HttpSecurity http ) throws Exception {
35
35
// @formatter:off
36
36
http
37
- .authorizeRequests ()
38
- .mvcMatchers ("/message/**" ).hasAuthority ("SCOPE_message:read" )
39
- .anyRequest ().authenticated ()
40
- .and ()
41
- .oauth2ResourceServer ()
42
- .opaqueToken ()
43
- .introspectionUri (this .introspectionUri )
44
- .introspectionClientCredentials (this .clientId , this .clientSecret );
37
+ .authorizeRequests (authorizeRequests ->
38
+ authorizeRequests
39
+ .mvcMatchers ("/message/**" ).hasAuthority ("SCOPE_message:read" )
40
+ .anyRequest ().authenticated ()
41
+ )
42
+ .oauth2ResourceServer (oauth2ResourceServer ->
43
+ oauth2ResourceServer
44
+ .opaqueToken (opaqueToken ->
45
+ opaqueToken
46
+ .introspectionUri (this .introspectionUri )
47
+ .introspectionClientCredentials (this .clientId , this .clientSecret )
48
+ )
49
+ );
45
50
// @formatter:on
46
51
}
47
52
}
Original file line number Diff line number Diff line change @@ -38,13 +38,17 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
38
38
protected void configure (HttpSecurity http ) throws Exception {
39
39
// @formatter:off
40
40
http
41
- .authorizeRequests ()
42
- .antMatchers ("/message/**" ).hasAuthority ("SCOPE_message:read" )
43
- .anyRequest ().authenticated ()
44
- .and ()
45
- .oauth2ResourceServer ()
46
- .jwt ()
47
- .decoder (jwtDecoder ());
41
+ .authorizeRequests (authorizeRequests ->
42
+ authorizeRequests
43
+ .antMatchers ("/message/**" ).hasAuthority ("SCOPE_message:read" )
44
+ .anyRequest ().authenticated ()
45
+ )
46
+ .oauth2ResourceServer (oauth2ResourceServer ->
47
+ oauth2ResourceServer
48
+ .jwt (jwt ->
49
+ jwt .decoder (jwtDecoder ())
50
+ )
51
+ );
48
52
// @formatter:on
49
53
}
50
54
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
19
19
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
20
20
import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
21
21
22
+ import static org .springframework .security .config .Customizer .withDefaults ;
23
+
22
24
/**
23
25
* @author Josh Cummings
24
26
*/
@@ -29,12 +31,15 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
29
31
protected void configure (HttpSecurity http ) throws Exception {
30
32
// @formatter:off
31
33
http
32
- .authorizeRequests ()
33
- .antMatchers ("/message/**" ).hasAuthority ("SCOPE_message:read" )
34
- .anyRequest ().authenticated ()
35
- .and ()
36
- .oauth2ResourceServer ()
37
- .jwt ();
34
+ .authorizeRequests (authorizeRequests ->
35
+ authorizeRequests
36
+ .antMatchers ("/message/**" ).hasAuthority ("SCOPE_message:read" )
37
+ .anyRequest ().authenticated ()
38
+ )
39
+ .oauth2ResourceServer (oauth2ResourceServer ->
40
+ oauth2ResourceServer
41
+ .jwt (withDefaults ())
42
+ );
38
43
// @formatter:on
39
44
}
40
45
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import org .springframework .security .core .userdetails .UserDetailsService ;
25
25
import org .springframework .security .provisioning .InMemoryUserDetailsManager ;
26
26
27
+ import static org .springframework .security .config .Customizer .withDefaults ;
28
+
27
29
/**
28
30
* @author Joe Grandja
29
31
*/
@@ -33,15 +35,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
33
35
@ Override
34
36
protected void configure (HttpSecurity http ) throws Exception {
35
37
http
36
- .authorizeRequests ()
37
- .mvcMatchers ("/" , "/public/**" ).permitAll ()
38
- .anyRequest ().authenticated ()
39
- .and ()
40
- .formLogin ()
41
- .and ()
42
- .oauth2Login ()
43
- .and ()
44
- .oauth2Client ();
38
+ .authorizeRequests (authorizeRequests ->
39
+ authorizeRequests
40
+ .mvcMatchers ("/" , "/public/**" ).permitAll ()
41
+ .anyRequest ().authenticated ()
42
+ )
43
+ .formLogin (withDefaults ())
44
+ .oauth2Login (withDefaults ())
45
+ .oauth2Client (withDefaults ());
45
46
}
46
47
47
48
@ Bean
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
22
22
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
23
23
import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
24
24
25
+ import static org .springframework .security .config .Customizer .withDefaults ;
26
+
25
27
@ EnableWebSecurity
26
28
@ EnableGlobalMethodSecurity (prePostEnabled = true )
27
29
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@@ -40,14 +42,19 @@ public void configureGlobal(
40
42
protected void configure (
41
43
HttpSecurity http ) throws Exception {
42
44
http
43
- .authorizeRequests ()
44
- .anyRequest ().authenticated ()
45
- .and ()
46
- .formLogin ()
47
- .and ()
48
- .sessionManagement ()
49
- .maximumSessions (1 )
50
- .expiredUrl ("/login?expired" );
45
+ .authorizeRequests (authorizeRequests ->
46
+ authorizeRequests
47
+ .anyRequest ().authenticated ()
48
+ )
49
+ .formLogin (withDefaults ())
50
+ .sessionManagement (sessionManagement ->
51
+ sessionManagement
52
+ .sessionConcurrency (sessionConcurrency ->
53
+ sessionConcurrency
54
+ .maximumSessions (1 )
55
+ .expiredUrl ("/login?expired" )
56
+ )
57
+ );
51
58
}
52
59
// @formatter:on
53
60
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -29,16 +29,20 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
29
29
@ Override
30
30
protected void configure (HttpSecurity http ) throws Exception {
31
31
http
32
- .authorizeRequests ()
33
- .antMatchers ("/resources/**" ).permitAll ()
34
- .anyRequest ().authenticated ()
35
- .and ()
36
- .formLogin ()
37
- .loginPage ("/login" )
38
- .permitAll ()
39
- .and ()
40
- .logout ()
41
- .permitAll ();
32
+ .authorizeRequests (authorizeRequests ->
33
+ authorizeRequests
34
+ .antMatchers ("/resources/**" ).permitAll ()
35
+ .anyRequest ().authenticated ()
36
+ )
37
+ .formLogin (formLogin ->
38
+ formLogin
39
+ .loginPage ("/login" )
40
+ .permitAll ()
41
+ )
42
+ .logout (logout ->
43
+ logout
44
+ .permitAll ()
45
+ );
42
46
}
43
47
// @formatter:on
44
48
You can’t perform that action at this time.
0 commit comments