Skip to content
Snippets Groups Projects
Commit 81540292 authored by Martin Weise's avatar Martin Weise
Browse files

Secure the endpoints

Former-commit-id: 4352b1c2
parent 8ff897c5
No related branches found
No related tags found
1 merge request!42Fixed the query service tests
...@@ -12,7 +12,7 @@ import lombok.extern.log4j.Log4j2; ...@@ -12,7 +12,7 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -37,7 +37,6 @@ public class ContainerEndpoint { ...@@ -37,7 +37,6 @@ public class ContainerEndpoint {
this.containerService = containerService; this.containerService = containerService;
} }
@Transactional
@GetMapping @GetMapping
@ApiOperation(value = "List all containers", notes = "Lists the containers in the metadata database.") @ApiOperation(value = "List all containers", notes = "Lists the containers in the metadata database.")
@ApiResponses({ @ApiResponses({
...@@ -52,7 +51,6 @@ public class ContainerEndpoint { ...@@ -52,7 +51,6 @@ public class ContainerEndpoint {
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
@Transactional
@PostMapping @PostMapping
@ApiOperation(value = "Creates a new container", notes = "Creates a new container whose image is registered in the metadata database too.") @ApiOperation(value = "Creates a new container", notes = "Creates a new container whose image is registered in the metadata database too.")
@ApiResponses({ @ApiResponses({
...@@ -69,9 +67,8 @@ public class ContainerEndpoint { ...@@ -69,9 +67,8 @@ public class ContainerEndpoint {
.body(response); .body(response);
} }
@Transactional
@GetMapping("/{id}") @GetMapping("/{id}")
@ApiOperation(value = "Get all informations about a container", notes = "Since we follow the REST-principle, this method provides more information than the findAll method.") @ApiOperation(value = "Get all information about a container", notes = "Since we follow the REST-principle, this method provides more information than the findAll method.")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "Get information about container."), @ApiResponse(code = 200, message = "Get information about container."),
@ApiResponse(code = 401, message = "Not authorized to get information about a container."), @ApiResponse(code = 401, message = "Not authorized to get information about a container."),
...@@ -84,7 +81,6 @@ public class ContainerEndpoint { ...@@ -84,7 +81,6 @@ public class ContainerEndpoint {
.body(containerMapper.containerToContainerDto(container)); .body(containerMapper.containerToContainerDto(container));
} }
@Transactional
@PutMapping("/{id}") @PutMapping("/{id}")
@ApiOperation(value = "Change the state of a container", notes = "The new state can only be one of START/STOP.") @ApiOperation(value = "Change the state of a container", notes = "The new state can only be one of START/STOP.")
@ApiResponses({ @ApiResponses({
...@@ -93,7 +89,8 @@ public class ContainerEndpoint { ...@@ -93,7 +89,8 @@ public class ContainerEndpoint {
@ApiResponse(code = 401, message = "Not authorized to modify a container."), @ApiResponse(code = 401, message = "Not authorized to modify a container."),
@ApiResponse(code = 404, message = "No container found with this id in metadata database."), @ApiResponse(code = 404, message = "No container found with this id in metadata database."),
}) })
public ResponseEntity<ContainerBriefDto> modify(@NotNull @PathVariable Long id, @Valid @RequestBody ContainerChangeDto changeDto) public ResponseEntity<ContainerBriefDto> modify(@NotNull @PathVariable Long id,
@Valid @RequestBody ContainerChangeDto changeDto)
throws ContainerNotFoundException, DockerClientException { throws ContainerNotFoundException, DockerClientException {
final Container container; final Container container;
if (changeDto.getAction().equals(ContainerActionTypeDto.START)) { if (changeDto.getAction().equals(ContainerActionTypeDto.START)) {
...@@ -107,6 +104,7 @@ public class ContainerEndpoint { ...@@ -107,6 +104,7 @@ public class ContainerEndpoint {
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@ApiOperation(value = "Delete a container") @ApiOperation(value = "Delete a container")
@PreAuthorize("hasRole('ROLE_DATA_STEWARD')")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "Deleted the container."), @ApiResponse(code = 200, message = "Deleted the container."),
@ApiResponse(code = 401, message = "Not authorized to delete a container."), @ApiResponse(code = 401, message = "Not authorized to delete a container."),
......
...@@ -18,7 +18,7 @@ import lombok.extern.log4j.Log4j2; ...@@ -18,7 +18,7 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -42,7 +42,6 @@ public class ImageEndpoint { ...@@ -42,7 +42,6 @@ public class ImageEndpoint {
this.imageMapper = imageMapper; this.imageMapper = imageMapper;
} }
@Transactional
@GetMapping @GetMapping
@ApiOperation(value = "List all images", notes = "Lists the images in the metadata database.") @ApiOperation(value = "List all images", notes = "Lists the images in the metadata database.")
@ApiResponses({ @ApiResponses({
...@@ -57,8 +56,8 @@ public class ImageEndpoint { ...@@ -57,8 +56,8 @@ public class ImageEndpoint {
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
@Transactional
@PostMapping @PostMapping
@PreAuthorize("hasRole('DEVELOPER')")
@ApiOperation(value = "Creates a new image", notes = "Creates a new image in the metadata database.") @ApiOperation(value = "Creates a new image", notes = "Creates a new image in the metadata database.")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 201, message = "Successfully created a new image."), @ApiResponse(code = 201, message = "Successfully created a new image."),
...@@ -73,7 +72,6 @@ public class ImageEndpoint { ...@@ -73,7 +72,6 @@ public class ImageEndpoint {
.body(imageMapper.containerImageToImageDto(image)); .body(imageMapper.containerImageToImageDto(image));
} }
@Transactional
@GetMapping("/{id}") @GetMapping("/{id}")
@ApiOperation(value = "Get all informations about a image", notes = "Since we follow the REST-principle, this method provides more information than the findAll method.") @ApiOperation(value = "Get all informations about a image", notes = "Since we follow the REST-principle, this method provides more information than the findAll method.")
@ApiResponses({ @ApiResponses({
...@@ -87,8 +85,8 @@ public class ImageEndpoint { ...@@ -87,8 +85,8 @@ public class ImageEndpoint {
.body(imageMapper.containerImageToImageDto(image)); .body(imageMapper.containerImageToImageDto(image));
} }
@Transactional
@PutMapping("/{id}") @PutMapping("/{id}")
@PreAuthorize("hasRole('DEVELOPER')")
@ApiOperation(value = "Update image information", notes = "Polls new information about an image") @ApiOperation(value = "Update image information", notes = "Polls new information about an image")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 202, message = "Updated the information of a image."), @ApiResponse(code = 202, message = "Updated the information of a image."),
...@@ -102,6 +100,7 @@ public class ImageEndpoint { ...@@ -102,6 +100,7 @@ public class ImageEndpoint {
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@PreAuthorize("hasRole('DEVELOPER')")
@ApiOperation(value = "Delete a image") @ApiOperation(value = "Delete a image")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "Deleted the image."), @ApiResponse(code = 200, message = "Deleted the image."),
......
...@@ -14,7 +14,7 @@ import lombok.extern.log4j.Log4j2; ...@@ -14,7 +14,7 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -37,7 +37,6 @@ public class ContainerDatabaseEndpoint { ...@@ -37,7 +37,6 @@ public class ContainerDatabaseEndpoint {
this.databaseService = databaseService; this.databaseService = databaseService;
} }
@Transactional
@GetMapping @GetMapping
@ApiOperation(value = "List all databases", notes = "Currently a container supports only databases of the same image, e.g. there is one PostgreSQL engine running with multiple databases inside a container.") @ApiOperation(value = "List all databases", notes = "Currently a container supports only databases of the same image, e.g. there is one PostgreSQL engine running with multiple databases inside a container.")
@ApiResponses({ @ApiResponses({
...@@ -52,7 +51,6 @@ public class ContainerDatabaseEndpoint { ...@@ -52,7 +51,6 @@ public class ContainerDatabaseEndpoint {
return ResponseEntity.ok(databases); return ResponseEntity.ok(databases);
} }
@Transactional
@PostMapping @PostMapping
@ApiOperation(value = "Creates a new database in a container", notes = "Creates a new database in a container. Note that the backend distincts between numerical (req: categories), nominal (req: max_length) and categorical (req: max_length, siUnit, min, max, mean, median, standard_deviation, histogram) column types.") @ApiOperation(value = "Creates a new database in a container", notes = "Creates a new database in a container. Note that the backend distincts between numerical (req: categories), nominal (req: max_length) and categorical (req: max_length, siUnit, min, max, mean, median, standard_deviation, histogram) column types.")
@ApiResponses({ @ApiResponses({
...@@ -71,9 +69,8 @@ public class ContainerDatabaseEndpoint { ...@@ -71,9 +69,8 @@ public class ContainerDatabaseEndpoint {
.body(databaseMapper.databaseToDatabaseDto(database)); .body(databaseMapper.databaseToDatabaseDto(database));
} }
@Transactional
@GetMapping("/{databaseId}") @GetMapping("/{databaseId}")
@ApiOperation(value = "Get all informations about a database") @ApiOperation(value = "Get all information about a database")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "The database information is displayed."), @ApiResponse(code = 200, message = "The database information is displayed."),
@ApiResponse(code = 400, message = "The payload contains invalid data."), @ApiResponse(code = 400, message = "The payload contains invalid data."),
...@@ -84,7 +81,8 @@ public class ContainerDatabaseEndpoint { ...@@ -84,7 +81,8 @@ public class ContainerDatabaseEndpoint {
return ResponseEntity.ok(databaseMapper.databaseToDatabaseDto(databaseService.findById(id, databaseId))); return ResponseEntity.ok(databaseMapper.databaseToDatabaseDto(databaseService.findById(id, databaseId)));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{databaseId}")
@PreAuthorize("hasRole('ROLE_DEVELOPER') or hasRole('ROLE_DATA_STEWARD')")
@ApiOperation(value = "Delete a database") @ApiOperation(value = "Delete a database")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 202, message = "The database was successfully deleted."), @ApiResponse(code = 202, message = "The database was successfully deleted."),
......
...@@ -57,8 +57,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -57,8 +57,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
/* set permissions on endpoints */ /* set permissions on endpoints */
http.authorizeRequests() http.authorizeRequests()
/* our public endpoints */ /* our public endpoints */
.antMatchers(HttpMethod.GET, "/api/container/**").permitAll() .antMatchers(HttpMethod.GET, "container/**/database/**").permitAll()
.antMatchers(HttpMethod.GET, "/api/image/**").permitAll()
/* our private endpoints */ /* our private endpoints */
.anyRequest().authenticated(); .anyRequest().authenticated();
/* add JWT token filter */ /* add JWT token filter */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment