java.lang.Object
com.irurueta.authserver.resourceserver.api.web.documents.DocumentController
All Implemented Interfaces:
DocumentsApi

@RestController public class DocumentController extends Object implements DocumentsApi
Documents API, as the contract apis/resource-server/rest-server/resource-server-api-v1.yaml describes it through the generated DocumentsApi. Reading needs the documents.read scope (enforced by the filter chain) and deleting the documents.delete scope (enforced by method security).
  • Field Details

    • PATH

      public static final String PATH
      Base path of the API, as declared by the contract.
      See Also:
    • listDocumentsUseCase

      private final ListDocumentsUseCase listDocumentsUseCase
      Use case that lists documents.
    • deleteDocumentUseCase

      private final DeleteDocumentUseCase deleteDocumentUseCase
      Use case that deletes a document.
    • documentDtoMapper

      private final DocumentDtoMapper documentDtoMapper
      Maps the documents onto the generated DTO.
  • Constructor Details

    • DocumentController

      public DocumentController()
  • Method Details

    • listDocuments

      public org.springframework.http.ResponseEntity<List<DocumentResponse>> listDocuments()
      Lists the documents of the caller; an administrator (ROLE_ADMIN) sees every document.
      Specified by:
      listDocuments in interface DocumentsApi
      Returns:
      the documents.
    • deleteDocument

      @PreAuthorize("hasAuthority(\'SCOPE_documents.delete\')") public org.springframework.http.ResponseEntity<Void> deleteDocument(String id)
      Deletes a document of the caller; an administrator (ROLE_ADMIN) may delete any document. Someone else's document is answered like a missing one, so the answer never reveals that it exists.
      Specified by:
      deleteDocument in interface DocumentsApi
      Parameters:
      id - identifier of the document.
      Returns:
      204 when the document was deleted, 404 when it does not exist or belongs to someone else.
    • caller

      private static org.springframework.security.core.Authentication caller()
      Returns the authenticated caller. The generated interface carries only the contract's parameters, so the bearer token's authentication is taken from the security context, which the filter chain has filled.
      Returns:
      the authenticated caller.
      Throws:
      org.springframework.security.authentication.AuthenticationCredentialsNotFoundException - if nobody is authenticated, answered 401 by the filter chain.