generated from pagopa/template-payments-java-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[P4ADEV-2047] Authorization on download API
- Loading branch information
Showing
11 changed files
with
95 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/it/gov/pagopa/pu/fileshare/connector/processexecutions/ExportFileService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package it.gov.pagopa.pu.fileshare.connector.processexecutions; | ||
|
||
import it.gov.pagopa.pu.p4paauth.dto.generated.UserInfo; | ||
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.ExportFile; | ||
|
||
public interface ExportFileService { | ||
ExportFile getExportFile(Long exportFileId, Long organizationId, UserInfo loggedUser, String accessToken); | ||
} |
37 changes: 37 additions & 0 deletions
37
...in/java/it/gov/pagopa/pu/fileshare/connector/processexecutions/ExportFileServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package it.gov.pagopa.pu.fileshare.connector.processexecutions; | ||
|
||
import it.gov.pagopa.pu.fileshare.connector.processexecutions.client.ExportFileClient; | ||
import it.gov.pagopa.pu.fileshare.exception.custom.UnauthorizedFileDownloadException; | ||
import it.gov.pagopa.pu.fileshare.service.AuthorizationService; | ||
import it.gov.pagopa.pu.p4paauth.dto.generated.UserInfo; | ||
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.ExportFile; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ExportFileServiceImpl implements ExportFileService { | ||
|
||
private final ExportFileClient client; | ||
|
||
public ExportFileServiceImpl(ExportFileClient client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public ExportFile getExportFile(Long exportFileId, Long organizationId, UserInfo loggedUser, String accessToken) { | ||
boolean isLoggedUserAdmin = AuthorizationService.isAdminRole( | ||
organizationId, loggedUser); | ||
String operatorExternalUserId = null; | ||
|
||
if(!isLoggedUserAdmin){ | ||
operatorExternalUserId = loggedUser.getMappedExternalUserId(); | ||
} | ||
|
||
ExportFile exportFile = client.getExportFile(exportFileId, accessToken); | ||
|
||
if (!isLoggedUserAdmin && !operatorExternalUserId.equals(exportFile.getOperatorExternalId())) { | ||
throw new UnauthorizedFileDownloadException("User is not authorized to download export file with ID " + exportFileId); | ||
} | ||
|
||
return exportFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...n/java/it/gov/pagopa/pu/fileshare/exception/custom/UnauthorizedFileDownloadException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package it.gov.pagopa.pu.fileshare.exception.custom; | ||
|
||
public class UnauthorizedFileDownloadException extends RuntimeException { | ||
public UnauthorizedFileDownloadException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters