* BAEL-4825

* BAEL-4825 added integration tests

* BAEL-4825 Fix line continuation indents

* BAEL-4825 Fix line continuation indents
This commit is contained in:
Amy DeGregorio 2021-04-01 11:14:25 -04:00 committed by GitHub
parent 9706d7b6fd
commit 86575c861b
2 changed files with 14 additions and 14 deletions

View File

@ -17,20 +17,20 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
protected void configure(AuthenticationManagerBuilder auth) throws Exception { protected void configure(AuthenticationManagerBuilder auth) throws Exception {
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
auth.inMemoryAuthentication() auth.inMemoryAuthentication()
.withUser("user") .withUser("user")
.password(encoder.encode("password")) .password(encoder.encode("password"))
.roles("USER") .roles("USER")
.and() .and()
.withUser("admin") .withUser("admin")
.password(encoder.encode("admin")) .password(encoder.encode("admin"))
.roles("USER", "ADMIN"); .roles("USER", "ADMIN");
} }
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(EndpointRequest.toAnyEndpoint()) http.requestMatcher(EndpointRequest.toAnyEndpoint())
.authorizeRequests((requests) -> requests.anyRequest() .authorizeRequests((requests) -> requests.anyRequest()
.hasRole("ADMIN")); .hasRole("ADMIN"));
http.httpBasic(); http.httpBasic();
} }
} }

View File

@ -21,16 +21,16 @@ public class EndpointEnablingIntegrationTest {
@WithMockUser(username = "user", password = "password", roles = "USER") @WithMockUser(username = "user", password = "password", roles = "USER")
public void givenWrongAuthentication_whenCallingActuator_thenReturns401() throws Exception { public void givenWrongAuthentication_whenCallingActuator_thenReturns401() throws Exception {
mockMvc.perform(get("/actuator")) mockMvc.perform(get("/actuator"))
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
} }
@Test @Test
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN") @WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
public void givenProperAuthentication_whenCallingActuator_thenReturnsExpectedEndpoints() throws Exception { public void givenProperAuthentication_whenCallingActuator_thenReturnsExpectedEndpoints() throws Exception {
mockMvc.perform(get("/actuator")) mockMvc.perform(get("/actuator"))
.andExpect(jsonPath("$._links").exists()) .andExpect(jsonPath("$._links").exists())
.andExpect(jsonPath("$._links.beans").exists()) .andExpect(jsonPath("$._links.beans").exists())
.andExpect(jsonPath("$._links.env").exists()) .andExpect(jsonPath("$._links.env").exists())
.andExpect(jsonPath("$._links.shutdown").exists()); .andExpect(jsonPath("$._links.shutdown").exists());
} }
} }