I am trying to complete a login system but when I log in, I get the following error
- "HTTP Error 404 CANNOT FIND "http://localhost:8181/user_login"
I know this obviously means cannot find it, but I'm confused on why it can't find it. Here is my security config
@EnableWebSecurity
@Configuration
@Order(2)
public class UserSecurityConfig extends WebSecurityConfigurerAdapter {
protected void user(HttpSecurity http) throws Exception {
http.authorizeRequests()
.and()
.formLogin()
.loginPage("/user_login")
.defaultSuccessUrl("/success")
.failureUrl("/login?error==true")
.permitAll()
.and()
.csrf()
.disable()
;
}
@Bean
public UserDetailsService userDetailsService() {
return new CustomUserDetailsService();
}
@Autowired
public void configurationGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
And the login form
<form:form name='user' action="/user_login" method='POST'>
<form:errors path="username" />
<label for="username">Email address</label>
<input type='text' class="form-control" name='username' value='' placeholder="Enter Email address"></td>
<label for="password">Password: </label>
<input type='password' class="form-control" name='password' /></td>
<input name="submit" class="btn btn-primary" type="submit" value="submit" /></td>
</form:form>
Here is my other security for Admin that works
@EnableWebSecurity
@Configuration
@Order(1)
public class AdminSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password("12345").roles("ADMIN")
.and()
.withUser("tester").password("56789").roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/login")
.permitAll()
.antMatchers("/newUser")
.permitAll()
.antMatchers("/admin")
.hasAnyRole("ADMIN")
.and()
.formLogin()
.loginPage("/login1")
.defaultSuccessUrl("/admin")
.failureUrl("/login?error=true")
.permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.and()
.csrf()
.disable()
;
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
If anyone has any idea or tips to solve this issue I would be very grateful. Thank you Jim