Skip to content

Commit

Permalink
update demo rest application to spring-boot 3
Browse files Browse the repository at this point in the history
  • Loading branch information
max402 committed Sep 19, 2023
1 parent 8bbb92a commit f1da386
Show file tree
Hide file tree
Showing 18 changed files with 1,053 additions and 359 deletions.
23 changes: 9 additions & 14 deletions datasafe-rest-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<spring-boot.version>3.1.2</spring-boot.version>
<springfox-swagger.version>2.9.2</springfox-swagger.version>
<jjwt.version>0.10.5</jjwt.version>
<spring-restdocs.version>2.0.3.RELEASE</spring-restdocs.version>
<asciidoctor-maven-plugin.version>1.5.3</asciidoctor-maven-plugin.version>
<spring-restdocs.version>3.0.0</spring-restdocs.version>
<asciidoctor-maven-plugin.version>2.2.4</asciidoctor-maven-plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<jakarta.validation-api.varsion>3.0.2</jakarta.validation-api.varsion>
</properties>
Expand Down Expand Up @@ -60,6 +60,11 @@
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
Expand All @@ -82,16 +87,6 @@
<artifactId>jakarta.validation-api</artifactId>
<version>${jakarta.validation-api.varsion}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>com.internetitem</groupId>
<artifactId>logback-elasticsearch-appender</artifactId>
Expand Down Expand Up @@ -149,8 +144,8 @@
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -25,23 +21,16 @@

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequiredArgsConstructor
@Api(description = "Initial authentication operations")
public class AuthenticateController {

private final SecurityProperties securityProperties;
private final AuthenticationManager authenticationManager;

@PostMapping(SecurityConstants.AUTH_LOGIN_URL)
@ApiOperation("Get token for given username and password")
@ApiResponses(value={
@ApiResponse(code=200, message="Successfully logged in"),
@ApiResponse(code=401, message="Bad credentials")
})
public void authenticate(@RequestBody UserDTO credentialsDTO, HttpServletResponse response) {
String username = credentialsDTO.getUserName();
String password = credentialsDTO.getPassword();
Expand All @@ -53,7 +42,7 @@ public void authenticate(@RequestBody UserDTO credentialsDTO, HttpServletRespons
List<String> roles = user.getAuthorities()
.stream()
.map(GrantedAuthority::getAuthority)
.collect(Collectors.toList());
.toList();

byte[] signingKey = securityProperties.getJwtSecret().getBytes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
import de.adorsys.datasafe.types.api.actions.WriteRequest;
import de.adorsys.datasafe.types.api.resource.PrivateResource;
import de.adorsys.datasafe.types.api.resource.StorageIdentifier;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
Expand All @@ -34,7 +29,6 @@
import java.io.OutputStream;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE;
Expand All @@ -46,7 +40,6 @@
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(description = "Operations with private documents")
public class DocumentController {

private final DefaultDatasafeServices datasafeService;
Expand All @@ -55,12 +48,7 @@ public class DocumentController {
* Reads user's private file.
*/
@SneakyThrows
@GetMapping(value = "/document/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE)
@ApiOperation("Read document from user's private space")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Document was successfully read"),
@ApiResponse(code = 401, message = "Document not found")
})
@GetMapping(value = "/document/{*path}", produces = APPLICATION_OCTET_STREAM_VALUE)
public void readDocument(@RequestHeader String user,
@RequestHeader String password,
@RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
Expand All @@ -83,11 +71,7 @@ public void readDocument(@RequestHeader String user,
* Writes file to user's private space.
*/
@SneakyThrows
@PutMapping(value = "/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE)
@ApiOperation("Write document to user's private space")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Document was successfully written")
})
@PutMapping(value = "/document/{*path}", consumes = MULTIPART_FORM_DATA_VALUE)
public void writeDocument(@RequestHeader String user,
@RequestHeader String password,
@RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
Expand All @@ -106,16 +90,10 @@ public void writeDocument(@RequestHeader String user,
/**
* lists files in user's private space.
*/
@GetMapping("/documents/{path:.*}")
@ApiOperation("List documents in user's private space")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "List command successfully completed"),
@ApiResponse(code = 401, message = "Unauthorised")
})
@GetMapping("/documents/{*path}")
public List<String> listDocuments(@RequestHeader String user,
@RequestHeader String password,
@RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
@ApiParam(defaultValue = ".")
@PathVariable(required = false) String path) {
UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password));
path = Optional.ofNullable(path)
Expand All @@ -125,7 +103,7 @@ public List<String> listDocuments(@RequestHeader String user,
List<String> documentList = datasafeService.privateService().list(
ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path))
.map(e -> e.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
.toList();
log.debug("List for path {} returned {} items", path, documentList.size());
return documentList;
} catch (AmazonS3Exception e) { // for list this exception most likely means that user credentials wrong
Expand All @@ -136,11 +114,7 @@ public List<String> listDocuments(@RequestHeader String user,
/**
* deletes files from user's private space.
*/
@DeleteMapping("/document/{path:.*}")
@ApiOperation("Delete document from user's private space")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Document successfully deleted")
})
@DeleteMapping("/document/{*path}")
public void removeDocument(@RequestHeader String user,
@RequestHeader String password,
@RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
Expand Down
Loading

0 comments on commit f1da386

Please sign in to comment.