|
17 | 17 | */ |
18 | 18 | package de.dominikschadow.javasecurity.sessionhandling.spring; |
19 | 19 |
|
20 | | -import org.apache.commons.dbcp.BasicDataSource; |
21 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
22 | | -import org.springframework.beans.factory.annotation.Value; |
23 | 21 | import org.springframework.context.annotation.Bean; |
24 | 22 | import org.springframework.context.annotation.ComponentScan; |
25 | 23 | import org.springframework.context.annotation.Configuration; |
26 | | -import org.springframework.core.io.Resource; |
27 | | -import org.springframework.jdbc.datasource.init.DataSourceInitializer; |
28 | | -import org.springframework.jdbc.datasource.init.DatabasePopulator; |
29 | | -import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; |
| 24 | +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
30 | 25 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; |
31 | 26 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; |
32 | 27 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
|
37 | 32 |
|
38 | 33 | import javax.sql.DataSource; |
39 | 34 |
|
| 35 | +import static org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType.H2; |
| 36 | + |
40 | 37 | /** |
41 | 38 | * Spring Security configuration for the session handling sample project. |
42 | 39 | * |
|
47 | 44 | @EnableGlobalMethodSecurity(prePostEnabled = true) |
48 | 45 | @ComponentScan("de.dominikschadow.javasecurity.sessionhandling.greetings") |
49 | 46 | public class SecurityConfig extends WebSecurityConfigurerAdapter { |
50 | | - @Value("classpath:database.sql") |
51 | | - private Resource dataScript; |
52 | | - |
53 | 47 | @Autowired |
54 | 48 | public void configAuthentication(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception { |
55 | 49 | auth.jdbcAuthentication().dataSource(dataSource) |
@@ -88,22 +82,6 @@ public PasswordEncoder passwordEncoder() { |
88 | 82 |
|
89 | 83 | @Bean |
90 | 84 | public DataSource dataSource() { |
91 | | - BasicDataSource dataSource = new BasicDataSource(); |
92 | | - dataSource.setUrl("jdbc:h2:mem:sessionHandlingSpringSecurity"); |
93 | | - dataSource.setUsername("hashing"); |
94 | | - dataSource.setPassword("hashing"); |
95 | | - return dataSource; |
96 | | - } |
97 | | - |
98 | | - @Bean |
99 | | - public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) { |
100 | | - final DataSourceInitializer initializer = new DataSourceInitializer(); |
101 | | - initializer.setDataSource(dataSource); |
102 | | - initializer.setDatabasePopulator(databasePopulator()); |
103 | | - return initializer; |
104 | | - } |
105 | | - |
106 | | - private DatabasePopulator databasePopulator() { |
107 | | - return new ResourceDatabasePopulator(dataScript); |
| 85 | + return new EmbeddedDatabaseBuilder().setType(H2).addScript("schema.sql").addScripts("data.sql").build(); |
108 | 86 | } |
109 | 87 | } |
0 commit comments