I am configuring endpoint access in Spring Security. What I want to accomplish:
- Everyone has access to resources
- Everyone can login/register
- Only authenticated users can access logout and all other mapped endpoints
Here is my configuration, it fulfills firs two requirements and prevents access to /logout for non-logged users.
http.authorizeRequests()
.antMatchers("/register").permitAll()
.antMatchers("/register/*").permitAll()
.antMatchers("/favicon.ico").permitAll()
.antMatchers("**/*.html").permitAll()
.antMatchers("**/*.css").permitAll()
.antMatchers("**/*.js").permitAll()
.and()
.formLogin().loginPage("/login").failureUrl("/login-error").defaultSuccessUrl("/")
.usernameParameter("username").passwordParameter("password")
.and()
.logout().logoutSuccessUrl("/login").deleteCookies("JSESSIONID").logoutUrl("/logout");
/resources/**or/public/**for static CSS/JS resources. - chrylis -cautiouslyoptimistic-