-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #351 from pagopa/develop
fix: Promotion to master: mask pan and other fixes
- Loading branch information
Showing
34 changed files
with
333 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* @GiovanniMancini @and-mora @TommasoLencioni @petretiandrea | ||
* @GiovanniMancini @and-mora @TommasoLencioni @petretiandrea @lucaconsalvi |
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
16 changes: 16 additions & 0 deletions
16
api/batch/src/main/java/it/gov/pagopa/rtd/transaction_filter/batch/config/AppConfig.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,16 @@ | ||
package it.gov.pagopa.rtd.transaction_filter.batch.config; | ||
|
||
import it.gov.pagopa.rtd.transaction_filter.batch.utils.TransactionMaskPolicy; | ||
import it.gov.pagopa.rtd.transaction_filter.batch.utils.TransactionMaskPolicyImpl; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class AppConfig { | ||
|
||
@Bean | ||
public TransactionMaskPolicy getTransactionMaskPolicy() { | ||
return new TransactionMaskPolicyImpl(); | ||
} | ||
|
||
} |
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
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
23 changes: 23 additions & 0 deletions
23
...src/main/java/it/gov/pagopa/rtd/transaction_filter/batch/utils/TransactionMaskPolicy.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,23 @@ | ||
package it.gov.pagopa.rtd.transaction_filter.batch.utils; | ||
|
||
import it.gov.pagopa.rtd.transaction_filter.batch.model.InboundTransaction; | ||
|
||
public interface TransactionMaskPolicy { | ||
|
||
/** | ||
* Apply the masking policy to a InboundTransaction object. The object is modified via side effect. | ||
* | ||
* @param transaction object to mask | ||
*/ | ||
void apply(InboundTransaction transaction); | ||
|
||
/** | ||
* Apply the masking policy to a transaction represented in csv format. | ||
* This method is used when it's not possible to parse the string into a InboundTransaction object. | ||
* | ||
* @param transactionContentAsCsv transaction in csv format with ";" as separator | ||
* @return the string masked | ||
*/ | ||
String apply(String transactionContentAsCsv); | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...main/java/it/gov/pagopa/rtd/transaction_filter/batch/utils/TransactionMaskPolicyImpl.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.rtd.transaction_filter.batch.utils; | ||
|
||
import it.gov.pagopa.rtd.transaction_filter.batch.model.InboundTransaction; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.lang.NonNull; | ||
|
||
@Slf4j | ||
public class TransactionMaskPolicyImpl implements TransactionMaskPolicy { | ||
|
||
private static final int PAN_INDEX = 3; | ||
|
||
@Override | ||
public void apply(InboundTransaction inboundTransaction) { | ||
|
||
String maskedPan = maskPan(inboundTransaction.getPan()); | ||
inboundTransaction.setPan(maskedPan); | ||
} | ||
|
||
@Override | ||
public String apply(@NonNull String transactionContentAsCsv) { | ||
|
||
// preliminary check to see if Pan field is found | ||
String[] transactionSplitted = transactionContentAsCsv.split(";", -1); | ||
if (transactionSplitted.length < PAN_INDEX) { | ||
log.debug("It's not possible to apply mask to this string: cannot find the pan field!"); | ||
return transactionContentAsCsv; | ||
} | ||
|
||
transactionSplitted[PAN_INDEX] = maskPan(transactionSplitted[PAN_INDEX]); | ||
|
||
return String.join(";", transactionSplitted); | ||
} | ||
|
||
private String maskPan(String pan) { | ||
return pan.replaceAll("(?<=.{6}).(?=.{4})", "*"); | ||
} | ||
} |
Oops, something went wrong.