Skip to content

Commit 1d7a964

Browse files
committed
Make classes and methods package-private
Signed-off-by: Josh Cummings <[email protected]>
1 parent c00ed9b commit 1d7a964

File tree

6 files changed

+23
-32
lines changed

6 files changed

+23
-32
lines changed

complete/src/main/java/com/example/securingweb/MvcConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
66

77
@Configuration
8-
public class MvcConfig implements WebMvcConfigurer {
8+
class MvcConfig implements WebMvcConfigurer {
99

1010
@Override
1111
public void addViewControllers(ViewControllerRegistry registry) {

complete/src/main/java/com/example/securingweb/SecuringWebApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

66
@SpringBootApplication
7-
public class SecuringWebApplication {
7+
class SecuringWebApplication {
88

99
public static void main(String[] args) {
1010
SpringApplication.run(SecuringWebApplication.class, args);

complete/src/main/java/com/example/securingweb/WebSecurityConfig.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
@Configuration
1717
@EnableWebSecurity
18-
public class WebSecurityConfig {
18+
class WebSecurityConfig {
1919

2020
@Bean
21-
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
21+
SecurityFilterChain securityFilterChain(HttpSecurity http) {
2222
// @formatter:off
2323
http
2424
.authorizeHttpRequests((requests) -> requests
@@ -36,14 +36,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) {
3636
}
3737

3838
@Bean
39-
public PasswordEncoder passwordEncoder() {
39+
PasswordEncoder passwordEncoder() {
4040
return new BCryptPasswordEncoder();
4141
}
4242

4343
@Bean
44-
public UserDetailsService userDetailsService(PasswordEncoder encoder) {
44+
UserDetailsService userDetailsService(PasswordEncoder encoder) {
4545
String password = encoder.encode("password");
4646
UserDetails user = User.withUsername("user").password(password).roles("USER").build();
4747
return new InMemoryUserDetailsManager(user);
4848
}
49+
4950
}

complete/src/test/java/com/example/securingweb/SecuringWebApplicationTests.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,41 @@
2020

2121
@SpringBootTest
2222
@AutoConfigureMockMvc
23-
public class SecuringWebApplicationTests {
23+
class SecuringWebApplicationTests {
2424

2525
@Autowired
2626
private MockMvc mockMvc;
2727

2828
@Test
29-
public void loginWithValidUserThenAuthenticated() throws Exception {
30-
FormLoginRequestBuilder login = formLogin()
31-
.user("user")
32-
.password("password");
29+
void loginWithValidUserThenAuthenticated() throws Exception {
30+
FormLoginRequestBuilder login = formLogin().user("user").password("password");
3331

34-
mockMvc.perform(login)
35-
.andExpect(authenticated().withUsername("user"));
32+
mockMvc.perform(login).andExpect(authenticated().withUsername("user"));
3633
}
3734

3835
@Test
39-
public void loginWithInvalidUserThenUnauthenticated() throws Exception {
40-
FormLoginRequestBuilder login = formLogin()
41-
.user("invalid")
42-
.password("invalidpassword");
36+
void loginWithInvalidUserThenUnauthenticated() throws Exception {
37+
FormLoginRequestBuilder login = formLogin().user("invalid").password("invalidpassword");
4338

44-
mockMvc.perform(login)
45-
.andExpect(unauthenticated());
39+
mockMvc.perform(login).andExpect(unauthenticated());
4640
}
4741

4842
@Test
49-
public void accessUnsecuredResourceThenOk() throws Exception {
50-
mockMvc.perform(get("/"))
51-
.andExpect(status().isOk());
43+
void accessUnsecuredResourceThenOk() throws Exception {
44+
mockMvc.perform(get("/")).andExpect(status().isOk());
5245
}
5346

5447
@Test
55-
public void accessSecuredResourceUnauthenticatedThenRedirectsToLogin() throws Exception {
56-
mockMvc.perform(get("/hello"))
57-
.andExpect(status().is3xxRedirection())
58-
.andExpect(redirectedUrl("/login"));
48+
void accessSecuredResourceUnauthenticatedThenRedirectsToLogin() throws Exception {
49+
mockMvc.perform(get("/hello")).andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/login"));
5950
}
6051

6152
@Test
6253
@WithMockUser
63-
public void accessSecuredResourceAuthenticatedThenOk() throws Exception {
64-
MvcResult mvcResult = mockMvc.perform(get("/hello"))
65-
.andExpect(status().isOk())
66-
.andReturn();
54+
void accessSecuredResourceAuthenticatedThenOk() throws Exception {
55+
MvcResult mvcResult = mockMvc.perform(get("/hello")).andExpect(status().isOk()).andReturn();
6756

6857
assertThat(mvcResult.getResponse().getContentAsString()).contains("Hello user!");
6958
}
59+
7060
}

initial/src/main/java/com/example/securingweb/MvcConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
66

77
@Configuration
8-
public class MvcConfig implements WebMvcConfigurer {
8+
class MvcConfig implements WebMvcConfigurer {
99

1010
@Override
1111
public void addViewControllers(ViewControllerRegistry registry) {

initial/src/main/java/com/example/securingweb/SecuringWebApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

66
@SpringBootApplication
7-
public class SecuringWebApplication {
7+
class SecuringWebApplication {
88

99
public static void main(String[] args) {
1010
SpringApplication.run(SecuringWebApplication.class, args);

0 commit comments

Comments
 (0)