Skip to content

Commit b6a2b5e

Browse files
committed
Use method injection & Update docs
1 parent 43146b8 commit b6a2b5e

File tree

3 files changed

+34
-55
lines changed

3 files changed

+34
-55
lines changed

demo/webapp-vaadin/src/main/java/software/xdev/sse/demo/security/MainWebSecurity.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
7-
import org.springframework.beans.factory.annotation.Autowired;
87
import org.springframework.context.annotation.Bean;
98
import org.springframework.context.annotation.Configuration;
109
import org.springframework.security.config.Customizer;
@@ -31,23 +30,14 @@ public class MainWebSecurity
3130
{
3231
private static final Logger LOG = LoggerFactory.getLogger(MainWebSecurity.class);
3332

34-
@Autowired
35-
protected OAuth2CookieRememberMeServices cookieRememberMeServices;
36-
37-
@Autowired
38-
protected OAuth2RefreshFilter oAuth2RefreshFilter;
39-
40-
@Autowired
41-
protected CSPGenerator cspGenerator;
42-
43-
@Autowired
44-
protected CookieBasedRememberRedirectOAuth2LoginProvider rememberLoginProvider;
45-
46-
@Autowired
47-
protected OAuth2LoginUrlStoreAdapter oAuth2LoginUrlStoreAdapter;
48-
4933
@Bean
50-
protected SecurityFilterChain httpSecurityFilterChain(final HttpSecurity http) throws Exception
34+
protected SecurityFilterChain httpSecurityFilterChain(
35+
final HttpSecurity http,
36+
final OAuth2CookieRememberMeServices cookieRememberMeServices,
37+
final OAuth2RefreshFilter oAuth2RefreshFilter,
38+
final CSPGenerator cspGenerator,
39+
final CookieBasedRememberRedirectOAuth2LoginProvider rememberLoginProvider,
40+
final OAuth2LoginUrlStoreAdapter oAuth2LoginUrlStoreAdapter) throws Exception
5141
{
5242
http
5343
.with(new AdvancedLoginPageAdapter<>(http), c -> c
@@ -60,19 +50,19 @@ protected SecurityFilterChain httpSecurityFilterChain(final HttpSecurity http) t
6050
// Permission-Policy removed as it's not supported by browsers (besides Chrome)
6151
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy#browser_compatibility
6252
.headers(c -> c
63-
.contentSecurityPolicy(p -> p.policyDirectives(this.cspGenerator.buildCSP()))
53+
.contentSecurityPolicy(p -> p.policyDirectives(cspGenerator.buildCSP()))
6454
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
6555
.contentTypeOptions(Customizer.withDefaults())
6656
.referrerPolicy(p -> p.policy(ReferrerPolicyHeaderWriter.ReferrerPolicy.SAME_ORIGIN)))
6757
.oauth2Login(c -> {
6858
c.defaultSuccessUrl("/" + MainView.NAV);
69-
this.rememberLoginProvider.configureOAuth2Login(c);
70-
this.oAuth2LoginUrlStoreAdapter.postProcess(c);
59+
rememberLoginProvider.configureOAuth2Login(c);
60+
oAuth2LoginUrlStoreAdapter.postProcess(c);
7161
})
72-
.logout(this.rememberLoginProvider::configureOAuth2Logout)
73-
.addFilterBefore(this.oAuth2RefreshFilter, AnonymousAuthenticationFilter.class);
62+
.logout(rememberLoginProvider::configureOAuth2Logout)
63+
.addFilterBefore(oAuth2RefreshFilter, AnonymousAuthenticationFilter.class);
7464

75-
this.cookieRememberMeServices.install(http);
65+
cookieRememberMeServices.install(http);
7666

7767
final DefaultSecurityFilterChain build = http
7868
.with(new TotalVaadinFlowSecurityConfigurer(), Customizer.withDefaults())

oauth2-oidc-remember-me/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ For more detailed docs have a look at [the javadoc of ``OAuth2CookieRememberMeSe
6666
* **You need to implement [``OAuth2RememberMeUserEnricher``](./src/main/java/software/xdev/sse/oauth2/rememberme/userenrichment/OAuth2RememberMeUserEnricher.java) and [``AuthRememberMeSecretService``](./src/main/java/software/xdev/sse/oauth2/rememberme/secrets/AuthRememberMeSecretService.java)**
6767
* Inside your main ``WebSecurity#configure`` add:
6868
```java
69-
this.cookieRememberMeServices.install(http);
69+
cookieRememberMeServices.install(http);
7070
```
7171

7272
## Example configuration

vaadin/README.md

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,46 @@ Secures [Vaadin (Flow)](https://github.com/vaadin/platform).
77
The overall goal is to
88
* give Spring Security full access control before any requests are processed by Vaadin
99
* only create Vaadin Sessions when they are really needed - as these are rather heavy (Vaadin stores the state of the UI in these)
10-
* make Vaadin's ``VaadinWebSecurity`` better customizable
10+
* make Vaadin's ``VaadinWebSecurity``/``VaadinSecurityConfigurer`` better customizable
1111

1212
## Requirements
1313

1414
* ``com.vaadin:vaadin-spring`` must be provided manually (only included with scope ``provided`` by default to prevent versioning conflicts)
1515

1616
## Usage
1717

18-
Create a ``Configuration``-class that extends from ``TotalVaadinFlowWebSecurity`` and extend it accordingly.
19-
20-
Here is an example:
2118
```java
2219
@EnableWebSecurity
2320
@Configuration
24-
public class MainWebSecurity extends TotalVaadinFlowWebSecurity
21+
public class MainWebSecurity
2522
{
26-
@Autowired
27-
protected OAuth2CookieRememberMeServices cookieRememberMeServices;
28-
29-
@Autowired
30-
protected OAuth2RefreshFilter oAuth2RefreshFilter;
31-
32-
@Autowired
33-
protected CSPGenerator cspGenerator;
34-
35-
@Autowired
36-
protected CookieBasedRememberRedirectOAuth2LoginProvider rememberLoginProvider;
37-
38-
@Autowired
39-
protected OAuth2LoginUrlStoreAdapter oAuth2LoginUrlStoreAdapter;
40-
41-
@Override
42-
protected void configure(final HttpSecurity http) throws Exception
23+
@Bean
24+
protected SecurityFilterChain httpSecurityFilterChain(
25+
final HttpSecurity http,
26+
final OAuth2CookieRememberMeServices cookieRememberMeServices,
27+
final OAuth2RefreshFilter oAuth2RefreshFilter,
28+
final CSPGenerator cspGenerator,
29+
final CookieBasedRememberRedirectOAuth2LoginProvider rememberLoginProvider,
30+
final OAuth2LoginUrlStoreAdapter oAuth2LoginUrlStoreAdapter) throws Exception
4331
{
4432
http
4533
.headers(c -> c
46-
.contentSecurityPolicy(p -> p.policyDirectives(this.cspGenerator.buildCSP()))
47-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
34+
.contentSecurityPolicy(p -> p.policyDirectives(cspGenerator.buildCSP()))
4835
.contentTypeOptions(Customizer.withDefaults())
4936
.referrerPolicy(p -> p.policy(ReferrerPolicyHeaderWriter.ReferrerPolicy.SAME_ORIGIN)))
5037
.oauth2Login(c -> {
51-
c.defaultSuccessUrl("/" + WorkdayView.NAV);
52-
this.rememberLoginProvider.configureOAuth2Login(c);
53-
this.oAuth2LoginUrlStoreAdapter.postProcess(c);
38+
c.defaultSuccessUrl("/" + MainView.NAV);
39+
rememberLoginProvider.configureOAuth2Login(c);
40+
oAuth2LoginUrlStoreAdapter.postProcess(c);
5441
})
55-
.logout(this.rememberLoginProvider::configureOAuth2Logout)
56-
.addFilterBefore(this.oAuth2RefreshFilter, AnonymousAuthenticationFilter.class);
42+
.logout(rememberLoginProvider::configureOAuth2Logout)
43+
.addFilterBefore(oAuth2RefreshFilter, AnonymousAuthenticationFilter.class);
5744

58-
this.cookieRememberMeServices.install(http);
45+
cookieRememberMeServices.install(http);
5946

60-
super.configure(http);
47+
return http
48+
.with(new TotalVaadinFlowSecurityConfigurer(), Customizer.withDefaults())
49+
.build();
6150
}
6251
}
6352
```

0 commit comments

Comments
 (0)