Skip to content

Conversation

@Artur-
Copy link
Member

@Artur- Artur- commented Sep 23, 2021

This ensures that the security context is the expected (the one from the UI you run access() on) if you run UI.access from a request to another VaadinSession.

Practical use case is e.g. sending a global 'refresh' event and the receipient updating the UI as a result.

Fixes #906

…ble.

This ensures that the security context is the expected (the one from the UI you run access() on) if you run UI.access from a request to another VaadinSession.

Practical use case is e.g. sending a global 'refresh' event and the receipient updating the UI as a result.

Fixes #906
@Artur- Artur- force-pushed the use-security-context-from-access branch from c966948 to b0cb13a Compare September 23, 2021 13:05
@mshabarov mshabarov self-requested a review September 27, 2021 05:36

import static java.util.Objects.requireNonNull;

public final class VaadinAwareSecurityContextHolderStrategy
Copy link
Contributor

Choose a reason for hiding this comment

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

Javadoc is needed. Although this is internally used class, a couple of sentences describing that this implementation looks for the VaadinSession for security context and it provides the security context for UI.access() calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added javadoc

balanceSpan.setId("balanceText");
add(balanceSpan);
add(new Button("Apply for a loan", this::applyForLoan));
add(new Button("Apply for a huge loan",
Copy link
Contributor

Choose a reason for hiding this comment

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

Apply for a huge loan button is not used in a tests. Is it for demo only?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it is for manual testing only. At least for now

Copy link
Contributor

@mshabarov mshabarov left a comment

Choose a reason for hiding this comment

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

I would add the javadoc and some missed headers, but otherwise it look good to me: VaadinSession is used to lookup the security context and this security context is available within UI::access calls, even if the same thread is used for broadcast UI updates, so the developer doesn't need to execute the update in a separate thread (if I understood this enhancement correctly).

@mshabarov mshabarov changed the title Always use the security context from VaadinSession when one is available feat: Always use the security context from VaadinSession when one is available Sep 28, 2021
Artur- and others added 2 commits September 28, 2021 12:12
Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
@Artur- Artur- force-pushed the use-security-context-from-access branch from a0f1184 to 8bf6e8a Compare September 28, 2021 09:17
@vaadin-bot
Copy link
Collaborator

SonarQube analysis reported 1 issue

  1. MINOR VaadinAwareSecurityContextHolderStrategy.java#L57: Replace this lambda with a method reference. rule

@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with platform 22.0.0.alpha5 and is also targeting the upcoming stable 22.0.0 version.

manolo pushed a commit to vaadin/flow that referenced this pull request Feb 8, 2022
…available

vaadin/spring#907

This ensures that the security context is the expected (the one from the UI you run access() on) if you run UI.access from a request to another VaadinSession.

Practical use case is e.g. sending a global 'refresh' event and the recipient updating the UI as a result.

Fixes: vaadin/spring#906
manolo pushed a commit to vaadin/flow that referenced this pull request Feb 8, 2022
…available

vaadin/spring#907

This ensures that the security context is the expected (the one from the UI you run access() on) if you run UI.access from a request to another VaadinSession.

Practical use case is e.g. sending a global 'refresh' event and the recipient updating the UI as a result.

Fixes: vaadin/spring#906
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected security context used when using UI.access across VaadinSessions

3 participants