Remove unused AzureMapsController, clean up commented decode logic, and introduce @PreAuthorize annotations in controllers to enforce role-based access controls.

This commit is contained in:
Jan 2025-12-13 10:22:02 +01:00
parent 3aa86b4eea
commit c0e0c377ce
5 changed files with 9 additions and 51 deletions

View file

@ -3,6 +3,7 @@ package de.avatic.lcc.controller.calculation;
import de.avatic.lcc.dto.calculation.execution.CalculationProcessingOverviewDTO; import de.avatic.lcc.dto.calculation.execution.CalculationProcessingOverviewDTO;
import de.avatic.lcc.service.calculation.execution.CalculationJobProcessorManagementService; import de.avatic.lcc.service.calculation.execution.CalculationJobProcessorManagementService;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -18,6 +19,7 @@ public class DashboardController {
} }
@GetMapping({"/", ""}) @GetMapping({"/", ""})
@PreAuthorize("hasAnyRole('SUPER', 'CALCULATION')")
public ResponseEntity<CalculationProcessingOverviewDTO> getDashboardData() { public ResponseEntity<CalculationProcessingOverviewDTO> getDashboardData() {
return ResponseEntity.ok(calculationJobProcessorManagementService.getCalculationOverview()); return ResponseEntity.ok(calculationJobProcessorManagementService.getCalculationOverview());
} }

View file

@ -83,7 +83,6 @@ public class PremiseController {
public ResponseEntity<PremiseSearchResultDTO> findMaterialsAndSuppliers(@RequestParam String search) { public ResponseEntity<PremiseSearchResultDTO> findMaterialsAndSuppliers(@RequestParam String search) {
try { try {
// String decodedValue = URLDecoder.decode(search, StandardCharsets.UTF_8);
return ResponseEntity.ok(premiseSearchStringAnalyzerService.findMaterialAndSuppliers(search)); return ResponseEntity.ok(premiseSearchStringAnalyzerService.findMaterialAndSuppliers(search));
} catch (Exception e) { } catch (Exception e) {
throw new BadRequestException("Bad string encoding", "Unable to decode request", e); throw new BadRequestException("Bad string encoding", "Unable to decode request", e);
@ -217,5 +216,4 @@ public class PremiseController {
} }
} }

View file

@ -4,6 +4,7 @@ import com.azure.core.annotation.BodyParam;
import de.avatic.lcc.dto.configuration.apps.AppDTO; import de.avatic.lcc.dto.configuration.apps.AppDTO;
import de.avatic.lcc.service.apps.AppsService; import de.avatic.lcc.service.apps.AppsService;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@ -16,21 +17,23 @@ public class AppsController {
private final AppsService appsService; private final AppsService appsService;
public AppsController(AppsService appsService) { public AppsController(AppsService appsService) {
this.appsService = appsService; this.appsService = appsService;
} }
@GetMapping({"", "/"}) @GetMapping({"", "/"})
@PreAuthorize("hasRole('SERVICE')")
public ResponseEntity<List<AppDTO>> listApps() { public ResponseEntity<List<AppDTO>> listApps() {
return ResponseEntity.ok(appsService.listApps()); return ResponseEntity.ok(appsService.listApps());
} }
@PostMapping({"", "/"}) @PostMapping({"", "/"})
@PreAuthorize("hasRole('SERVICE')")
public ResponseEntity<AppDTO> updateApp(@RequestBody AppDTO dto) { public ResponseEntity<AppDTO> updateApp(@RequestBody AppDTO dto) {
return ResponseEntity.ok(appsService.updateApp(dto)); return ResponseEntity.ok(appsService.updateApp(dto));
} }
@DeleteMapping({"/{id}", "/{id}/"}) @DeleteMapping({"/{id}", "/{id}/"})
@PreAuthorize("hasRole('SERVICE')")
public ResponseEntity<Void> deleteApp(@PathVariable Integer id) { public ResponseEntity<Void> deleteApp(@PathVariable Integer id) {
appsService.deleteApp(id); appsService.deleteApp(id);
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();

View file

@ -5,6 +5,7 @@ import de.avatic.lcc.repositories.error.DumpRepository;
import de.avatic.lcc.repositories.pagination.SearchQueryPagination; import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Min;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@ -20,11 +21,13 @@ public class CalculationDumpController {
} }
@GetMapping({"/dump/{id}", "/dump/{id}/"}) @GetMapping({"/dump/{id}", "/dump/{id}/"})
@PreAuthorize("hasRole('SERVICE')")
public ResponseEntity<CalculationJobDumpDTO> getDump(@PathVariable Integer id) { public ResponseEntity<CalculationJobDumpDTO> getDump(@PathVariable Integer id) {
return ResponseEntity.ok(dumpRepository.getDump(id)); return ResponseEntity.ok(dumpRepository.getDump(id));
} }
@GetMapping({"/dump/", "/dump"}) @GetMapping({"/dump/", "/dump"})
@PreAuthorize("hasRole('SERVICE')")
public ResponseEntity<List<CalculationJobDumpDTO>> listDumps( public ResponseEntity<List<CalculationJobDumpDTO>> listDumps(
@RequestParam(defaultValue = "20") @Min(1) int limit, @RequestParam(defaultValue = "20") @Min(1) int limit,
@RequestParam(defaultValue = "1") @Min(1) int page) { @RequestParam(defaultValue = "1") @Min(1) int page) {

View file

@ -1,48 +0,0 @@
package de.avatic.lcc.controller.maps;
import com.azure.core.credential.AccessToken;
import com.azure.identity.DefaultAzureCredentialBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/api/maps")
public class AzureMapsController {
@Value("${azure.maps.client.id}")
private String mapsClientId;
@Value("${azure.maps.subscription.key}")
private String mapsSubscriptionKey;
@GetMapping("/token")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<Map<String, Object>> getAzureMapsToken() {
try {
// Verwende die DefaultAzureCredential für die Authentifizierung
var credential = new DefaultAzureCredentialBuilder().build();
// Fordere ein Token für Azure Maps an
AccessToken token = credential.getToken(
new com.azure.core.credential.TokenRequestContext()
.addScopes("https://atlas.microsoft.com/.default")
).block();
Map<String, Object> response = new HashMap<>();
response.put("token", token.getToken());
response.put("expiresOn", token.getExpiresAt().toEpochSecond());
return ResponseEntity.ok(response);
} catch (Exception e) {
return ResponseEntity.internalServerError().build();
}
}
}