I am having a issue where once a user is authenticated, the user is still able to access the login page by accessing the URL at localhost:8080/login. I would like it to be redirected automatically to the user's landing page if the authenticated user tries to access the login page again.
My SecurityConfig is set like this:
.csrf()
.and()
.authorizeRequests()
.antMatchers("/programme/**").hasRole("USER1")
.antMatchers("/programme1/**").hasRole("USER1")
.antMatchers("/project/**").hasRole("USER2")
.antMatchers("/").authenticated()
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login-error")
.successHandler(authenticationSuccessHandler)
.failureHandler(customAuthenticationFailureHandler() )
.permitAll()
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.deleteCookies("JSESSIONID").invalidateHttpSession(true)
.and()
.rememberMe().key("uniqueAndSecret").userDetailsService(userDetailsService);