I am writing a car rent web app using Spring-boot, Spring-security, Hibernate, MySQL, JSP, JSTL, AspectJ in Intellij. I use JDBC authentication to login users. The problem is: if I login for the first time, I got an error of status 999, type None, with message: Message not available, second logging passes normally.
I've read that it might be Spring Security not finding declared folders in WebSecurity configuration. I tried many ant matchers, finally I left only /css/** and /js/**, since both are being read properly on my page, but the result was the same- error status 999.
Is it the source of the problem? Could anyone point what I am doing wrong?
SecurityConfiguration.class
package com.doszke.CarRent.web;
import com.doszke.CarRent.reflect.annotations.AccessLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import javax.sql.DataSource;
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder;
@Value("${carrent.queries.users-query}")
private String usersQuery;
@Value("${carrent.queries.roles-query}")
private String rolesQuery;
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.
jdbcAuthentication()
.usersByUsernameQuery(usersQuery)
.authoritiesByUsernameQuery(rolesQuery)
.dataSource(dataSource)
.passwordEncoder(bCryptPasswordEncoder);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/resources/**").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/register").permitAll()
.antMatchers("/registerSuccess").permitAll()
.antMatchers("/home/**").hasAuthority(AccessLevel.USER).anyRequest().authenticated()
.antMatchers("/admin/**").hasAuthority(AccessLevel.ADMIN).anyRequest()
.authenticated()
.and()
.csrf()
.disable()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error=true")
.defaultSuccessUrl("/home")
.usernameParameter("login")
.passwordParameter("password")
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/")
.and()
.exceptionHandling()
.accessDeniedPage("/access-denied");
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/css/**", "/js/**");//, "/static/**", "/css/**", "/js/**", "/images/**");
}
}
my resource and webapp tree:
