Browser is redirected to service-worker.js
Asked Answered
P

3

6

I'm developing two separate projects: one is Polymer app with Service worker(scaffolded with Polymer CLI) and second app is Spring Boot with Vaadin and its itegration library Vaadin Spring. Both applications are running on localhost:8080.

On SpringBoot app, non-authenticated user is redirected to /login. After successful authentication user should be redirected back to /, but instead is redirected to url http://localhost:8080/service-worker.js, where is displayed default spring 404 page. When I manually change url back to /, SpringBoot app is working again.

  • this behavior occured after I was working on Polymer app and switched to SpringBoot
  • tested on Chrome and Firefox
  • clearing browser cache helps
  • Vaadin is also using hashbang

I can't find source of the problem (if is it Polymer or SpringBoot+Vaadin) and clearing cache or manually changing URL every time is frustrating.

EDIT:

I'm using default handler SavedRequestAwareVaadinAuthenticationSuccessHandler provided by Vaadin Spring. It should redirect back to previous URL or to fallback URL /.

@Bean(name = VaadinSharedSecurityConfiguration.VAADIN_AUTHENTICATION_SUCCESS_HANDLER_BEAN)
VaadinAuthenticationSuccessHandler vaadinAuthenticationSuccessHandler(@SuppressWarnings("SpringJavaAutowiringInspection") HttpService httpService, VaadinRedirectStrategy vaadinRedirectStrategy) {
    return new SavedRequestAwareVaadinAuthenticationSuccessHandler(httpService, vaadinRedirectStrategy, "/");
}
Parkway answered 20/6, 2016 at 9:31 Comment(1)
Please post your code that redirects after login.Colonnade
D
4

I had the same problem. This is a browser thing, and you can't do noting from your application or on server side.

I solved ti by deleting service worker for localhost adress in chrome manually.

You can do it by opening developer tools in chrome -> Tab Resources -> Service Workers
Find your service worker on specific url, for example http://localhost:8080/login and delete it.

Another alternative is to use different localhost (localhost, 127.0.0.1, 127.0.0.2) IP addresses for developing polymer application and Vaadin application.

Decoction answered 2/8, 2016 at 13:38 Comment(0)
P
4

I Soleved it. Go to locahost:8080/login -> Inspect (ctr+shift+I) -> Application tab -> choose Service Worker and unregister sw.js Good luck!

Presbyopia answered 9/7, 2019 at 8:15 Comment(0)
O
-2

The problem is that to access the "service-worker.js" authentication is needed, and since this "service-worker.js" is accessed automatically in each change and replaces the session attribute SPRING_SECURITY_SAVED_REQUEST, a simple solution is to give public access to it:

 http.authorizeRequests()
        .antMatchers("/service-worker.js").permitAll()
        .antMatchers("/**").fullyAuthenticated().and()
Okubo answered 8/5, 2019 at 18:42 Comment(1)
I am sorry, but for this scenario your answer is incorrect. You've probably missed first crucial part - " I'm developing two separate projects ... ".Parkway

© 2022 - 2024 — McMap. All rights reserved.