File tree Expand file tree Collapse file tree 4 files changed +22
-9
lines changed
main/java/com/baeldung/spring/session
test/java/com/baeldung/spring/session Expand file tree Collapse file tree 4 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 1010
1111 <parent >
1212 <groupId >com.baeldung</groupId >
13- <artifactId >parent-boot-1 </artifactId >
13+ <artifactId >parent-boot-2 </artifactId >
1414 <version >0.0.1-SNAPSHOT</version >
15- <relativePath >../parent-boot-1 </relativePath >
15+ <relativePath >../parent-boot-2 </relativePath >
1616 </parent >
1717
1818 <modules >
Original file line number Diff line number Diff line change 99
1010 <parent >
1111 <groupId >com.baeldung</groupId >
12- <artifactId >parent-boot-1 </artifactId >
12+ <artifactId >parent-boot-2 </artifactId >
1313 <version >0.0.1-SNAPSHOT</version >
14- <relativePath >../../parent-boot-1 </relativePath >
14+ <relativePath >../../parent-boot-2 </relativePath >
1515 </parent >
1616
1717 <dependencies >
2525 </dependency >
2626 <dependency >
2727 <groupId >org.springframework.session</groupId >
28- <artifactId >spring-session</artifactId >
28+ <artifactId >spring-session-data-redis </artifactId >
2929 </dependency >
3030 <dependency >
3131 <groupId >org.springframework.boot</groupId >
3636 <artifactId >embedded-redis</artifactId >
3737 <version >${embedded-redis.version} </version >
3838 </dependency >
39+ <dependency >
40+ <groupId >redis.clients</groupId >
41+ <artifactId >jedis</artifactId >
42+ <type >jar</type >
43+ </dependency >
3944 </dependencies >
4045
4146 <properties >
Original file line number Diff line number Diff line change 11package com .baeldung .spring .session ;
22
33import org .springframework .beans .factory .annotation .Autowired ;
4+ import org .springframework .context .annotation .Bean ;
45import org .springframework .context .annotation .Configuration ;
56import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
67import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
78import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
89import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
10+ import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
11+ import org .springframework .security .crypto .password .PasswordEncoder ;
912
1013@ Configuration
1114@ EnableWebSecurity
1215public class SecurityConfig extends WebSecurityConfigurerAdapter {
13-
16+
1417 @ Autowired
1518 public void configureGlobal (AuthenticationManagerBuilder auth ) throws Exception {
16- auth .inMemoryAuthentication ().withUser ("admin" ).password ("password" ).roles ("ADMIN" );
19+ auth .inMemoryAuthentication ().withUser ("admin" ).password (passwordEncoder (). encode ( "password" ) ).roles ("ADMIN" );
1720 }
18-
21+
1922 @ Override
2023 protected void configure (HttpSecurity http ) throws Exception {
2124 http .httpBasic ().and ().authorizeRequests ().antMatchers ("/" ).hasRole ("ADMIN" ).anyRequest ().authenticated ();
2225 }
26+
27+ @ Bean
28+ public PasswordEncoder passwordEncoder () {
29+ return new BCryptPasswordEncoder ();
30+ }
2331}
Original file line number Diff line number Diff line change 55import org .junit .BeforeClass ;
66import org .junit .Test ;
77import org .junit .runner .RunWith ;
8- import org .springframework .boot .context . embedded .LocalServerPort ;
8+ import org .springframework .boot .web . server .LocalServerPort ;
99import org .springframework .boot .test .context .SpringBootTest ;
1010import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
1111import org .springframework .boot .test .web .client .TestRestTemplate ;
You can’t perform that action at this time.
0 commit comments