Handling login with a Vaadin Flow webapp, across all layouts globally and across “route” URLs
up vote
1
down vote
favorite
Vaadin 8
In Vaadin 8, in my UI subclass I handled login by examining if a user’s session carried an attribute noting whether they had successfully logged in or not. If not, my UI subclass displayed a login layout rather than other content with navigation options such as menu bar and buttons that switch layout within that UI.
Vaadin 10+
In Vaadin 10 and later, Vaadin Flow, the UI class is apparently handled automatically by Vaadin in a manner transparent to me the app developer. Now the @Route and Router class approach is suggested as the way to navigate between forms, driven by different URLs attached to each layout. One benefit is the user being able to bookmark a location within the app, in friendly web style.
Global check
➥ In Vaadin Flow, how does one handle a global check that the user is logged-in before displaying any other content?
Subclass UI, as in Vaadin 8
Should I follow the Vaadin 8 approach, writing a subclass of UI? If so, how to install my subclass of UI in place of the UI apparently apparently placed automatically by Vaadin Flow?
Do I follow the example shown in the manual with a Servlet definition, and as discussed in this other Question?
BeforeEnterEvent
Or should I be doing something with the BeforeEnterEvent discussed in routing lifecycle tutorial? While the top of that page has a brief mention of listeners firing on the UI instance, the examples across the rest of the page involve code on the layout rather than UI. So I do not understand how to handle global check across all my current and future layouts defined in my app.
My question has nothing to do with storing passwords, credentials, hash & salt, etc. I am asking about a way to gracefully check for login being completed to block/grant access to the content of a Vaadin web app.
session login vaadin vaadin-flow
add a comment |
up vote
1
down vote
favorite
Vaadin 8
In Vaadin 8, in my UI subclass I handled login by examining if a user’s session carried an attribute noting whether they had successfully logged in or not. If not, my UI subclass displayed a login layout rather than other content with navigation options such as menu bar and buttons that switch layout within that UI.
Vaadin 10+
In Vaadin 10 and later, Vaadin Flow, the UI class is apparently handled automatically by Vaadin in a manner transparent to me the app developer. Now the @Route and Router class approach is suggested as the way to navigate between forms, driven by different URLs attached to each layout. One benefit is the user being able to bookmark a location within the app, in friendly web style.
Global check
➥ In Vaadin Flow, how does one handle a global check that the user is logged-in before displaying any other content?
Subclass UI, as in Vaadin 8
Should I follow the Vaadin 8 approach, writing a subclass of UI? If so, how to install my subclass of UI in place of the UI apparently apparently placed automatically by Vaadin Flow?
Do I follow the example shown in the manual with a Servlet definition, and as discussed in this other Question?
BeforeEnterEvent
Or should I be doing something with the BeforeEnterEvent discussed in routing lifecycle tutorial? While the top of that page has a brief mention of listeners firing on the UI instance, the examples across the rest of the page involve code on the layout rather than UI. So I do not understand how to handle global check across all my current and future layouts defined in my app.
My question has nothing to do with storing passwords, credentials, hash & salt, etc. I am asking about a way to gracefully check for login being completed to block/grant access to the content of a Vaadin web app.
session login vaadin vaadin-flow
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Vaadin 8
In Vaadin 8, in my UI subclass I handled login by examining if a user’s session carried an attribute noting whether they had successfully logged in or not. If not, my UI subclass displayed a login layout rather than other content with navigation options such as menu bar and buttons that switch layout within that UI.
Vaadin 10+
In Vaadin 10 and later, Vaadin Flow, the UI class is apparently handled automatically by Vaadin in a manner transparent to me the app developer. Now the @Route and Router class approach is suggested as the way to navigate between forms, driven by different URLs attached to each layout. One benefit is the user being able to bookmark a location within the app, in friendly web style.
Global check
➥ In Vaadin Flow, how does one handle a global check that the user is logged-in before displaying any other content?
Subclass UI, as in Vaadin 8
Should I follow the Vaadin 8 approach, writing a subclass of UI? If so, how to install my subclass of UI in place of the UI apparently apparently placed automatically by Vaadin Flow?
Do I follow the example shown in the manual with a Servlet definition, and as discussed in this other Question?
BeforeEnterEvent
Or should I be doing something with the BeforeEnterEvent discussed in routing lifecycle tutorial? While the top of that page has a brief mention of listeners firing on the UI instance, the examples across the rest of the page involve code on the layout rather than UI. So I do not understand how to handle global check across all my current and future layouts defined in my app.
My question has nothing to do with storing passwords, credentials, hash & salt, etc. I am asking about a way to gracefully check for login being completed to block/grant access to the content of a Vaadin web app.
session login vaadin vaadin-flow
Vaadin 8
In Vaadin 8, in my UI subclass I handled login by examining if a user’s session carried an attribute noting whether they had successfully logged in or not. If not, my UI subclass displayed a login layout rather than other content with navigation options such as menu bar and buttons that switch layout within that UI.
Vaadin 10+
In Vaadin 10 and later, Vaadin Flow, the UI class is apparently handled automatically by Vaadin in a manner transparent to me the app developer. Now the @Route and Router class approach is suggested as the way to navigate between forms, driven by different URLs attached to each layout. One benefit is the user being able to bookmark a location within the app, in friendly web style.
Global check
➥ In Vaadin Flow, how does one handle a global check that the user is logged-in before displaying any other content?
Subclass UI, as in Vaadin 8
Should I follow the Vaadin 8 approach, writing a subclass of UI? If so, how to install my subclass of UI in place of the UI apparently apparently placed automatically by Vaadin Flow?
Do I follow the example shown in the manual with a Servlet definition, and as discussed in this other Question?
BeforeEnterEvent
Or should I be doing something with the BeforeEnterEvent discussed in routing lifecycle tutorial? While the top of that page has a brief mention of listeners firing on the UI instance, the examples across the rest of the page involve code on the layout rather than UI. So I do not understand how to handle global check across all my current and future layouts defined in my app.
My question has nothing to do with storing passwords, credentials, hash & salt, etc. I am asking about a way to gracefully check for login being completed to block/grant access to the content of a Vaadin web app.
session login vaadin vaadin-flow
session login vaadin vaadin-flow
edited Nov 12 at 23:57
asked Nov 11 at 23:09
Basil Bourque
105k25359520
105k25359520
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
There are a couple of different alternatives that might be useful for you, slightly depending on how you've structured you application.
- Make your main layout class implement
BeforeEnterObserver. This is a really simple approach as long as you only have one main layout for the entire application. One drawback is that there would be no checks for any@Routeclass that you don't configure to directly or indirectly use your main layout. - Implement
RouterLayout.showRouterLayoutContentin your main layout (instead of relying on the default implementation), and do the checks there. This again only works when the main layout is actually used for all views, but might be challenging if having intermediate layouts in between. - Define your own
AbstractViewclass that does access control on its own for each instance. This again requires that you remember to always useAbstractViewfor all your routes. - Register a UI-wide
BeforeEnterListenerthat performs access checks. This is a little more complex to set up since you'd need aVaadinServiceInitListenerthat adds aUIInitListenerthat adds the actual listener. On the other hand, this approach is able to intercept any navigation event regardless of layout nesting and without requiring a special view class.
I cannot find anAbstractViewinterface or abstract class (from # 3 above) in the JavaDoc
– Basil Bourque
Nov 12 at 23:52
My intention was that you'd create your ownAbstractViewclass specifically for your application. I made a small edit to my answer to hopefully make that a little bit clearer.
– Leif Åstrand
Nov 13 at 14:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254167%2fhandling-login-with-a-vaadin-flow-webapp-across-all-layouts-globally-and-across%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
There are a couple of different alternatives that might be useful for you, slightly depending on how you've structured you application.
- Make your main layout class implement
BeforeEnterObserver. This is a really simple approach as long as you only have one main layout for the entire application. One drawback is that there would be no checks for any@Routeclass that you don't configure to directly or indirectly use your main layout. - Implement
RouterLayout.showRouterLayoutContentin your main layout (instead of relying on the default implementation), and do the checks there. This again only works when the main layout is actually used for all views, but might be challenging if having intermediate layouts in between. - Define your own
AbstractViewclass that does access control on its own for each instance. This again requires that you remember to always useAbstractViewfor all your routes. - Register a UI-wide
BeforeEnterListenerthat performs access checks. This is a little more complex to set up since you'd need aVaadinServiceInitListenerthat adds aUIInitListenerthat adds the actual listener. On the other hand, this approach is able to intercept any navigation event regardless of layout nesting and without requiring a special view class.
I cannot find anAbstractViewinterface or abstract class (from # 3 above) in the JavaDoc
– Basil Bourque
Nov 12 at 23:52
My intention was that you'd create your ownAbstractViewclass specifically for your application. I made a small edit to my answer to hopefully make that a little bit clearer.
– Leif Åstrand
Nov 13 at 14:14
add a comment |
up vote
2
down vote
accepted
There are a couple of different alternatives that might be useful for you, slightly depending on how you've structured you application.
- Make your main layout class implement
BeforeEnterObserver. This is a really simple approach as long as you only have one main layout for the entire application. One drawback is that there would be no checks for any@Routeclass that you don't configure to directly or indirectly use your main layout. - Implement
RouterLayout.showRouterLayoutContentin your main layout (instead of relying on the default implementation), and do the checks there. This again only works when the main layout is actually used for all views, but might be challenging if having intermediate layouts in between. - Define your own
AbstractViewclass that does access control on its own for each instance. This again requires that you remember to always useAbstractViewfor all your routes. - Register a UI-wide
BeforeEnterListenerthat performs access checks. This is a little more complex to set up since you'd need aVaadinServiceInitListenerthat adds aUIInitListenerthat adds the actual listener. On the other hand, this approach is able to intercept any navigation event regardless of layout nesting and without requiring a special view class.
I cannot find anAbstractViewinterface or abstract class (from # 3 above) in the JavaDoc
– Basil Bourque
Nov 12 at 23:52
My intention was that you'd create your ownAbstractViewclass specifically for your application. I made a small edit to my answer to hopefully make that a little bit clearer.
– Leif Åstrand
Nov 13 at 14:14
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
There are a couple of different alternatives that might be useful for you, slightly depending on how you've structured you application.
- Make your main layout class implement
BeforeEnterObserver. This is a really simple approach as long as you only have one main layout for the entire application. One drawback is that there would be no checks for any@Routeclass that you don't configure to directly or indirectly use your main layout. - Implement
RouterLayout.showRouterLayoutContentin your main layout (instead of relying on the default implementation), and do the checks there. This again only works when the main layout is actually used for all views, but might be challenging if having intermediate layouts in between. - Define your own
AbstractViewclass that does access control on its own for each instance. This again requires that you remember to always useAbstractViewfor all your routes. - Register a UI-wide
BeforeEnterListenerthat performs access checks. This is a little more complex to set up since you'd need aVaadinServiceInitListenerthat adds aUIInitListenerthat adds the actual listener. On the other hand, this approach is able to intercept any navigation event regardless of layout nesting and without requiring a special view class.
There are a couple of different alternatives that might be useful for you, slightly depending on how you've structured you application.
- Make your main layout class implement
BeforeEnterObserver. This is a really simple approach as long as you only have one main layout for the entire application. One drawback is that there would be no checks for any@Routeclass that you don't configure to directly or indirectly use your main layout. - Implement
RouterLayout.showRouterLayoutContentin your main layout (instead of relying on the default implementation), and do the checks there. This again only works when the main layout is actually used for all views, but might be challenging if having intermediate layouts in between. - Define your own
AbstractViewclass that does access control on its own for each instance. This again requires that you remember to always useAbstractViewfor all your routes. - Register a UI-wide
BeforeEnterListenerthat performs access checks. This is a little more complex to set up since you'd need aVaadinServiceInitListenerthat adds aUIInitListenerthat adds the actual listener. On the other hand, this approach is able to intercept any navigation event regardless of layout nesting and without requiring a special view class.
edited Nov 13 at 14:13
answered Nov 12 at 9:34
Leif Åstrand
1,43059
1,43059
I cannot find anAbstractViewinterface or abstract class (from # 3 above) in the JavaDoc
– Basil Bourque
Nov 12 at 23:52
My intention was that you'd create your ownAbstractViewclass specifically for your application. I made a small edit to my answer to hopefully make that a little bit clearer.
– Leif Åstrand
Nov 13 at 14:14
add a comment |
I cannot find anAbstractViewinterface or abstract class (from # 3 above) in the JavaDoc
– Basil Bourque
Nov 12 at 23:52
My intention was that you'd create your ownAbstractViewclass specifically for your application. I made a small edit to my answer to hopefully make that a little bit clearer.
– Leif Åstrand
Nov 13 at 14:14
I cannot find an
AbstractView interface or abstract class (from # 3 above) in the JavaDoc– Basil Bourque
Nov 12 at 23:52
I cannot find an
AbstractView interface or abstract class (from # 3 above) in the JavaDoc– Basil Bourque
Nov 12 at 23:52
My intention was that you'd create your own
AbstractView class specifically for your application. I made a small edit to my answer to hopefully make that a little bit clearer.– Leif Åstrand
Nov 13 at 14:14
My intention was that you'd create your own
AbstractView class specifically for your application. I made a small edit to my answer to hopefully make that a little bit clearer.– Leif Åstrand
Nov 13 at 14:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254167%2fhandling-login-with-a-vaadin-flow-webapp-across-all-layouts-globally-and-across%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown