Skip to content

Commit

Permalink
Merge pull request #82 from realrolfje/feature/partial-character-anon…
Browse files Browse the repository at this point in the history
…ymizer-cleanup

Feature/partial character anonymizer cleanup
  • Loading branch information
realrolfje authored Feb 15, 2020
2 parents cd90fcd + 8849702 commit 9f6fcf1
Show file tree
Hide file tree
Showing 16 changed files with 455 additions and 186 deletions.
4 changes: 2 additions & 2 deletions create_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ git push --follow-tags
# Sign the zip file
gpg -ab --default-key 45E2A5E085182DC26EFEF6E796BB2760490D54DD target/anonimatron*.zip

echo "The file to upload for this release is:"
echo "The files to upload for this release are:"
echo
ls -l target/anonimatron*.zip
ls -l target/anonimatron*.zip*
echo
echo "When creating a release, github automatically adds src zip"
echo "files, you only need to upload the binary."
Expand Down
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exclude: [ruby, Gemfile, Gemfile.lock, serve_local_jekyll_site.sh]
github:
zip_url: https://github.com/realrolfje/anonimatron/releases/latest
repository_url: https://github.com/realrolfje/anonimatron/tree/master
documentation_url: /documentation

plugins:
- jekyll-mentions
Expand Down
7 changes: 5 additions & 2 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
<body>
<header class="page-header" role="banner">
<div class="logo">
<h1 class="project-name">{{ site.title | default: site.github.repository_name }}</h1>
<h1 class="project-name"><a href="/" style="color: inherit">{{ site.title | default: site.github.repository_name }}</a></h1>
<h2 class="project-tagline">{{ page.description | default: site.description | default: site.github.project_tagline }}</h2>
{% if site.github.is_project_page %}
{% if site.github.is_project_page %}
<a href="{{ site.github.repository_url }}" class="btn github">View on GitHub</a>
{% endif %}
{% if site.show_downloads %}
<a href="{{ site.github.zip_url }}" class="btn zip">Download .zip</a>
{% endif %}
{% if site.github.is_project_page %}
<a href="{{ site.github.documentation_url }}" class="btn documentation">Documentation</a>
{% endif %}
</div>
</header>

Expand Down
Binary file added docs/assets/css/book-flat-30.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
padding-left: 47px;
}

.btn.documentation {
background-image: url(book-flat-30.png);
background-repeat: no-repeat;
background-position: 10px;
padding-left: 47px;
}

.logo {
background-image: url(anonimatron-logo-a.png);
background-repeat: no-repeat;
Expand Down
26 changes: 26 additions & 0 deletions docs/documentation/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Anonimatron documentation

For more information on how Anonimatron works and runs, check our [GitHub readme.md](https://github.com/realrolfje/anonimatron/blob/master/README.md).

## Available Anonymizers

Anonimatron comes with the following default anonymizers. Please start Anonimatron with the `-configexample`
parameter to see how these are configured:

| Name | Type | Input | Output |
|:----------------------------------|:--------------------|:-----------------|:-------------------------------------------------------------------------|
| CharacterStringAnonymizer | RANDOMCHARACTERS | Any string | A-Z, same length |
| CharacterStringPrefetchAnonymizer | RANDOMCHARACTERS | Any string | Characters from all input data, same length |
| CountryCodeAnonymizer | COUNTRY_CODE | Any string | ISO 3166-1 alpha 2 or alpha 3 code |
| DateAnonymizer | DATE | Valid date | Date between 31 days before and 32 days after the input date |
| DigitStringAnonymizer | RANDOMDIGITS | Any string | 0-9, same length, optional mask |
| DutchBankAccountAnononymizer | DUTCHBANKACCOUNT | Any string | 11 proof number, minimal 9 digits |
| DutchBSNAnononymizer | BURGERSERVICENUMMER | Number or string | Valid Dutch "Burger Service Nummer" or "SOFI Nummer" as number or string |
| DutchZipCodeAnonymizer | DUTCH_ZIP_CODE | Any string | Valid Dutch zip/postal code |
| ElvenNameGenerator | ELVEN_NAME | Any string | Pronounceable elven name, 2 to 5 syllables |
| EmailAddressAnonymizer | EMAIL_ADDRESS | Any string | Valid email address in the domain "@example.com" |
| IbanAnonymizer | IBAN | Any string | Valid International Bank Account Number |
| RomanNameGenerator | ROMAN_NAME | Any string | Pronounceable Roman name, 2 to 5 syllables |
| StringAnonymizer | STRING | Any string | Random hexadecimal string |
| UkPostCodeAnonymizer | UK_POST_CODE | Any string | Valid Uk Post code |
| UUIDAnonymizer | UUID | Any string | A random UUID |
11 changes: 11 additions & 0 deletions resources/documentation/VERSION_INFO.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
*** Version 1.12
- Added mask parameter to DigitStringAnonymizer
(fixes issue #74, thanks to Balogh Tamás and Bartlomiej Komendarczuk)
- Added UK Postalcode Anonymizer
- Optimized Random number generators (less instantiations)
- Fixed override problem with password, userid and jdbcurl
(pull request #69, thanks to Stephan Schrader)
- Security, performance and readability fixes, as suggested by SonarCube,
see https://sonarcloud.io/dashboard?id=realrolfje_anonimatron)
- Integrated documentation in the main development branch

*** Version 1.11
- Add numeric BSN support, closes issue #31
- Ability to provide database connection parameters through
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ protected int[] generate11ProofNumber(int numberOfDigits) {
}

protected int[] getRandomDigits(int numberOfDigits) {
int[] elevenProof = new int[numberOfDigits];
for (int i = 0; i < elevenProof.length; i++) {
elevenProof[i] = (int) Math.floor(Math.random() * 10);
int[] randomDigits = new int[numberOfDigits];
for (int i = 0; i < randomDigits.length; i++) {
randomDigits[i] = (int) Math.floor(Math.random() * 10);
}
return elevenProof;
return randomDigits;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,100 @@
import com.rolfje.anonimatron.synonyms.StringSynonym;
import com.rolfje.anonimatron.synonyms.Synonym;

import java.util.Map;

public class DigitStringAnonymizer extends AbstractElevenProofAnonymizer {

@Override
public String getType() {
return "RANDOMDIGITS";
}
final static String PARAMETER = "mask";

@Override
public String getType() {
return "RANDOMDIGITS";
}

@Override
public Synonym anonymize(Object from, int size, boolean shortlived, Map<String, String> parameters) {
if (parameters == null || !parameters.containsKey(PARAMETER)) {
throw new UnsupportedOperationException("Please provide '" + PARAMETER + "' with a digit mask in the form 111******, where only stars are replaced with random characters.");
}
return anonymizeMasked(from, size, shortlived, parameters.get(PARAMETER));
}

@Override
public Synonym anonymize(Object from, int size, boolean shortlived) {
if (from == null) {
return new StringSynonym(
getType(),
null,
null,
shortlived
);
}

int length = from.toString().length();

int[] digits = getRandomDigits(length);
String to = digitsAsString(digits);

StringSynonym stringSynonym = new StringSynonym(
getType(),
(String) from,
to,
shortlived
);

@Override
public Synonym anonymize(Object from, int size, boolean shortlived) {
int length = from.toString().length();
return stringSynonym;
}

int[] digits = getRandomDigits(length);
String to = digitsAsString(digits);
/**
* Anonymizes a string with digits into a new string of digits where only a part
* of the original digits are changed. You can use this to mask out a certain part
* of the original string, like an area code of a phone number, or the bank number
* of a credit card number.
* <p>
* A mask looks like "111***", where digits remain original, and stars (or other
* characters) are replaced with random digits. An example:
* <p>
* Original number: 555-1234
* Mask: 1111**** (note that the '-' is also untouched by placing a digit there)
* New number : 555-9876
* <p>
* Note that if the mask is shorter than the input string, the output string will
* have random digits where there is no mask. In short: only the locations where
* there is a digit in the mask are left untouched and will be in the output.
*
* @param from
* @param size
* @param shortlived
* @param mask
* @return
*/
private Synonym anonymizeMasked(Object from, int size, boolean shortlived, String mask) {
if (from == null) {
return new StringSynonym(
getType(),
null,
null,
shortlived
);
}

StringSynonym stringSynonym = new StringSynonym(
getType(),
(String) from,
to,
shortlived
);
char[] fromChars = from.toString().toCharArray();
char[] toChars = new char[fromChars.length];

return stringSynonym;
}
for (int i = 0; i < fromChars.length; i++) {
if (i < mask.length() && Character.isDigit(mask.charAt(i))) {
toChars[i] = fromChars[i];
} else {
toChars[i] = Character.forDigit((int) Math.floor(Math.random() * 10), 10);
}
}

return new StringSynonym(
getType(),
String.valueOf(fromChars),
String.valueOf(toChars),
shortlived
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.math.BigInteger;

/**
* Generates valid Dutch "Burger Service Nummer" or "SOFI Nummer",a social
* Generates valid Dutch "Burger Service Nummer" or "SOFI Nummer", a social
* security number uniquely identifying civilians to the governement.
* <p>
* A BSN Number is 9 digits long, can not start with 3 zeroes, the first digit
Expand Down

This file was deleted.

Loading

0 comments on commit 9f6fcf1

Please sign in to comment.