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 3 commits into
base: latest
Choose a base branch
from
Open
Changes from 1 commit
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to inject the strategy as the interface SecurityContextHolderStrategy, in case the user provides their own strategy bean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter needs VaadinSecurityContextHolderStrategy to work properly with Vaadin. A different strategy (e.g. ThreadLocal) will potentially fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note suggesting to add @Import(VaadinAwareSecurityContextHolderStrategyConfiguration.class) if application is not using VaadinWebSecurity as a base configuration class.


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

Expand Down
Loading