working hasGlobalAdminRole and prepare for Micrometer metrics with Spring Security #127

Merged
hsh-michaelhoennig merged 13 commits from feature/fix-hasGlobalAdminRole into master 2024-12-03 12:39:23 +01:00
2 changed files with 16 additions and 3 deletions
Showing only changes of commit 593a3545d0 - Show all commits

View File

@ -16,6 +16,7 @@ public class WebSecurityConfig {
public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/api/**").permitAll() // TODO.impl: implement authentication
.requestMatchers("/actuator/**").permitAll()
.anyRequest().authenticated()
)

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng;
package net.hostsharing.hsadminng.config;
import java.util.Map;
@ -14,8 +14,12 @@ import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {"management.port=0"})
class HsadminNgApplicationIntegrationTest {
@TestPropertySource(properties = {"management.port=0", "server.port=0"})
// IMPORTANT: To test prod config, do not use test profile!
class WebSecurityConfigIntegrationTest {
@Value("${local.server.port}")
private int serverPort;
@Value("${local.management.port}")
private int managementPort;
@ -23,6 +27,14 @@ class HsadminNgApplicationIntegrationTest {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void shouldSupportPingEndpoint() {
final var result = this.restTemplate.getForEntity(
"http://localhost:" + this.serverPort + "/api/ping", String.class);
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody()).startsWith("pong");
}
@Test
public void shouldSupportActuatorEndpoint() {
final var result = this.restTemplate.getForEntity(