Skip to content

docs: refactor impersonation example #4294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions articles/flow/security/enabling-security.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ To add impersonation for a Vaadin application, create the [classname]`SwitchUser
[source,java]
----
@Bean
@DependsOn("VaadinSecurityContextHolderStrategy")
public SwitchUserFilter switchUserFilter() {
public SwitchUserFilter switchUserFilter(VaadinAwareSecurityContextHolderStrategy strategy) {
SwitchUserFilter filter = new SwitchUserFilter();
filter.setSecurityContextHolderStrategy(strategy);
filter.setUserDetailsService(userDetailsService());
filter.setSwitchUserMatcher(antMatcher(HttpMethod.GET, "/impersonate"));
filter.setExitUserMatcher(antMatcher(HttpMethod.GET, "/impersonate/exit"));
Expand All @@ -587,7 +587,7 @@ To add impersonation for a Vaadin application, create the [classname]`SwitchUser
----

[NOTE]
The bean should depend on `VaadinSecurityContextHolderStrategy` bean. If the [classname]`SwitchUserFilter` is initialized first, the wrong security holder is used and the feature won't work.
The bean should use `VaadinSecurityContextHolderStrategy` bean to work properly. If the [classname]`SwitchUserFilter` is initialized differently, the wrong security holder is used and the feature won't work. If your are not using `VaadinWebSecurity` as base class for your security configuration, you might need to add `@Import(VaadinAwareSecurityContextHolderStrategyConfiguration.class)` on top of your class.

To secure the impersonation endpoints, add to the [classname]`VaadinWebSecurity` implementation [methodname]`configure(HttpSecurity http)` the matchers like so:

Expand Down