0

I am facing an issue with my spring security ( version 4) at this moment.

org.springframework.security.authentication.InternalAuthenticationServiceException: Could not get JDBC Connection

Here is the AppConfig class:

 @EnableWebMvc
 @Configuration
  @ComponentScan({ "controller" })
 @Import({ SecurityConfig.class })
  public class AppConfig {

@Bean(name = "dataSource")
public DriverManagerDataSource dataSource() {

    System.out.println("-------- MySQL JDBC Connection Testing ------------");
    System.out.println("JDBC Driver Found");
    DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
       driverManagerDataSource.setDriverClassName("com.mysql.jdbc.Driver");
    driverManagerDataSource.setUrl("jdbc:mysql://localhost:3306/QSQL");
    driverManagerDataSource.setUsername("root");
    driverManagerDataSource.setPassword("password");
    return driverManagerDataSource;
}

 @Bean
  public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/Pages/");
    viewResolver.setSuffix(".jsp");
    return viewResolver;
  }

}

Here is my SecurityConfig class:

@Configuration
 @EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

 @Autowired
DataSource dataSource;

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
 System.out.println("begin Auth Process");
  auth.jdbcAuthentication().dataSource(dataSource)
    .usersByUsernameQuery(
        "select username,password, enabled from QSQL.users where username=?")
    .authoritiesByUsernameQuery(
        "select username, role from QSQL.user_roles where username=?");
}   

  @Override
 protected void configure(HttpSecurity http) throws Exception {

  http.authorizeRequests()
    .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
    .and()
      .formLogin().loginPage("/login").failureUrl("/login?error")
      .usernameParameter("username").passwordParameter("password")
    .and()
      .logout().logoutSuccessUrl("/login?logout")
    .and()
      .exceptionHandling().accessDeniedPage("/403")
    .and()
      .csrf();
 }
}

However I am getting the error mentioned above along with the following:

Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server.

Although I can connect to my database using the SQL explorer plugin.

Thanks for the help.

FuSsA
  • 4,223
  • 7
  • 39
  • 60
nader
  • 141
  • 2
  • 13

2 Answers2

1

The issue was in the mysql driver (mysql connector version 6.0.2) I was using once I used the latest GA'd version mysql java connector 5.1.39 the issue went away.

nader
  • 141
  • 2
  • 13
0

Please check your library version of spring and Spring security you are using. java.lang.NoClassDefFoundError: org/springframework/security/authentication/AuthenticationManager

Community
  • 1
  • 1
Manoj Kumar
  • 380
  • 5
  • 20
  • Hmm I am using 4.2.6 for spring and 4.1.0 for spring security... I will try updating my spring framework to 4.3.0. I will see if it fixes it. – nader Jun 26 '16 at 17:17
  • Actually I found the error it is related to a bug in mysql 6.0.2 ...... Here :The server time zone value 'EDT' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. – nader Jun 28 '16 at 23:51