I am trying to add Spring Security Custom Login (Java Config) to my application, but a strange error continues to appear.
I looked at Creating a custom training module for logging in , and it works fine. I am not sure what the problem is with my application.
Error
Called: java.lang.IllegalArgumentException: 'login? error 'is not a valid redirect URL
Security configuration
@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user").password("password").roles("USER"); } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/", "/about").permitAll(); http .authorizeRequests() .antMatchers("/admin","/admin/**").hasRole("ADMIN") .anyRequest().authenticated() .and() .formLogin() .loginPage("login") .permitAll(); } }
LoginController
@Controller public class LoginController { @RequestMapping(value = "login", method = RequestMethod.GET) public String loginView() { return "login"; } @RequestMapping(value = "login", method = RequestMethod.POST) public String login(@ModelAttribute Login login) { return "home"; } }
Just commenting on the configure(HttpSecurity http) method configure(HttpSecurity http) removes the exception. I tried adding RequestMapping with a login?error RequestMapping value, but that did not help. What am I missing here?
Link to full stack trace
source share