Skip to content
Snippets Groups Projects
Commit 5fe0e1e5 authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

OZG-7609 use unsecured accesws to aggregation mappings for spring cloud config

parent 6afbb591
No related branches found
No related tags found
1 merge request!11OZG-7609 provide aggregation manager config endpoint without auhtantication
...@@ -30,10 +30,13 @@ import org.springframework.data.mongodb.repository.Query; ...@@ -30,10 +30,13 @@ import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.annotation.Secured;
@Secured("ROLE_DATENBEAUFTRAGUNG")
@RepositoryRestResource @RepositoryRestResource
interface AggregationMappingRepository extends MongoRepository<AggregationMapping, String> { interface AggregationMappingRepository extends MongoRepository<AggregationMapping, String> {
@Override @Override
@Query("{'_class': 'AggregationMapping'}") @Secured("ROLE_DATENBEAUFTRAGUNG")
List<AggregationMapping> findAll(); List<AggregationMapping> findAll();
@Query("{}")
List<AggregationMapping> findAllUnsecured();
} }
...@@ -40,7 +40,7 @@ class ReportingAggregationManagerSettingDtoService implements SettingDtoService ...@@ -40,7 +40,7 @@ class ReportingAggregationManagerSettingDtoService implements SettingDtoService
@Override @Override
public ReportingAggregationManagerSettingDto getDataTransferObject() { public ReportingAggregationManagerSettingDto getDataTransferObject() {
return mapToDto(repository.findAll()); return mapToDto(repository.findAllUnsecured());
} }
ReportingAggregationManagerSettingDto mapToDto(List<AggregationMapping> aggregationMappings) { ReportingAggregationManagerSettingDto mapToDto(List<AggregationMapping> aggregationMappings) {
......
...@@ -33,18 +33,15 @@ import org.junit.jupiter.api.Test; ...@@ -33,18 +33,15 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultActions;
import de.ozgcloud.admin.common.user.UserRole;
import de.ozgcloud.admin.setting.YamlTestFactory; import de.ozgcloud.admin.setting.YamlTestFactory;
import de.ozgcloud.common.test.DataITCase; import de.ozgcloud.common.test.DataITCase;
import lombok.SneakyThrows; import lombok.SneakyThrows;
@DataITCase @DataITCase
@AutoConfigureMockMvc @AutoConfigureMockMvc
@WithMockUser(roles = UserRole.DATENBEAUFTRAGUNG)
public class AggregationMappingEnvironmentSettingITCase { public class AggregationMappingEnvironmentSettingITCase {
@Autowired @Autowired
......
...@@ -61,6 +61,15 @@ class AggregationMappingRepositoryITCase { ...@@ -61,6 +61,15 @@ class AggregationMappingRepositoryITCase {
assertThat(result).hasSize(1); assertThat(result).hasSize(1);
} }
@Test
void shouldLoadWithoutRole() {
operations.save(AggregationMappingTestFactory.create());
var result = repository.findAllUnsecured();
assertThat(result).hasSize(1);
}
@Test @Test
@WithMockUser @WithMockUser
void shouldThrowExceptionOnMissingRole() { void shouldThrowExceptionOnMissingRole() {
......
...@@ -88,13 +88,13 @@ class ReportingAggregationManagerSettingDtoServiceTest { ...@@ -88,13 +88,13 @@ class ReportingAggregationManagerSettingDtoServiceTest {
void shouldCallRepository() { void shouldCallRepository() {
service.getDataTransferObject(); service.getDataTransferObject();
verify(repository).findAll(); verify(repository).findAllUnsecured();
} }
@Test @Test
void shouldCallMapToDto() { void shouldCallMapToDto() {
AggregationMapping mapping = AggregationMappingTestFactory.create(); AggregationMapping mapping = AggregationMappingTestFactory.create();
when(repository.findAll()).thenReturn(List.of(mapping)); when(repository.findAllUnsecured()).thenReturn(List.of(mapping));
service.getDataTransferObject(); service.getDataTransferObject();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment