Loucher
Loucher

Reputation: 316

Browser is redirected to service-worker.js

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.

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, "/");
}

Upvotes: 6

Views: 2663

Answers (3)

Slavus
Slavus

Reputation: 1238

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.

Upvotes: 5

Nguyen Tung
Nguyen Tung

Reputation: 115

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

Upvotes: 4

user11471825
user11471825

Reputation: 1

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()

Upvotes: -2

Related Questions