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