0

When I try to navigate a user asynchronously from the server-side via @Push like:

ListenableFuture<JobApplicationMatrix> listenableFuture = // some Async method invocation

var ui = UI.getCurrent();
listenableFuture.addCallback(jobApplicationMatrix -> {
     ui.access(() -> {
              
          ui.navigate(CandidateComplianceApplicationView.class, new RouteParameters(CandidateComplianceApplicationView.APPLICATION_UUID_PARAMETER, candidateApplicationUuid));
              
     });
}

it is not working as expected. CandidateComplianceApplicationView is a secured View. When I execute ui.navigate from ui.access the system moves me to the Keycloak login page. Looks like the system doesn't understand that the user is logged in. So, is this possible to navigate to the secure view from ui.access and if so, what am I doing wrong here?

I also tried to change @PermitAll to @AnonymousAllowed on CandidateComplianceApplicationView. In such case the system moves me to the correct page but the actual content of the CandidateComplianceApplicationView is not rendered at all.

UPDATED

I use

@Push(transport = Transport.LONG_POLLING)
alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • I don't think that this is possible because the SecurityContext is bound to the thread – Simon Martinelli Nov 04 '22 at 13:56
  • Thanks! The biggest concern here also, that the `CandidateComplianceApplicationView` is not rendered even in case I configure it with `@AnonymousAllowed` – alexanoid Nov 04 '22 at 14:13
  • I've never tried to navigate with a Push and I could imagine that this doesn't work. Instead of navigate you could try to use UI.getCurrent().getPage().setLocation – Simon Martinelli Nov 04 '22 at 14:28
  • I think this is a valid question, but I wonder, if this is good UX - has the user "ordered" this "surprise navigation" at some point and is just twiddling thumbs till it happens? – cfrick Nov 04 '22 at 16:24
  • `ui.getPage().setLocation` works fine, I already use it instead of `navigate` but from time to ime users claim that they are with no reasons move to the home page when clicking something… so I think I have a conceptual issue somewhere in the code with @Push and user session.. The biggest issue is - that I don't see any issues at log.. – alexanoid Nov 04 '22 at 16:41
  • Also, one more question - should I use `UI.setCurrent(ui)` in `ui.access(() -> {}` code block? Does this make any sense? – alexanoid Nov 04 '22 at 16:45

0 Answers0