46
46
* "partition_attribute" for Strings and a sort (range) key named "sort_attribute" for numbers.
47
47
*/
48
48
public class EncryptionContextOverridesWithDynamoDBMapper {
49
- public static final String TABLE_NAME_TO_OVERRIDE = "ExampleTableForEncryptionContextOverrides" ;
49
+ public static final String ORIGINAL_TABLE_NAME_TO_OVERRIDE =
50
+ "ExampleTableForEncryptionContextOverrides" ;
50
51
public static final String PARTITION_ATTRIBUTE = "partition_attribute" ;
51
52
public static final String SORT_ATTRIBUTE = "sort_attribute" ;
52
53
@@ -78,7 +79,7 @@ public static void main(String[] args) throws GeneralSecurityException {
78
79
79
80
public static void encryptRecord (
80
81
final String cmkArn ,
81
- final String newEncryptionContextTableName ,
82
+ final String currentTableName ,
82
83
AmazonDynamoDB ddbClient ,
83
84
AWSKMS kmsClient )
84
85
throws GeneralSecurityException {
@@ -95,7 +96,7 @@ public static void encryptRecord(
95
96
final DynamoDBEncryptor encryptor = DynamoDBEncryptor .getInstance (cmp );
96
97
97
98
Map <String , String > tableNameEncryptionContextOverrides = new HashMap <>();
98
- tableNameEncryptionContextOverrides .put (TABLE_NAME_TO_OVERRIDE , newEncryptionContextTableName );
99
+ tableNameEncryptionContextOverrides .put (ORIGINAL_TABLE_NAME_TO_OVERRIDE , currentTableName );
99
100
tableNameEncryptionContextOverrides .put (
100
101
"AnotherExampleTableForEncryptionContextOverrides" , "this table doesn't exist" );
101
102
@@ -133,7 +134,7 @@ public static void encryptRecord(
133
134
final EnumSet <EncryptionFlags > encryptAndSign =
134
135
EnumSet .of (EncryptionFlags .ENCRYPT , EncryptionFlags .SIGN );
135
136
final Map <String , AttributeValue > encryptedItem =
136
- ddbClient .getItem (TABLE_NAME_TO_OVERRIDE , itemKey ).getItem ();
137
+ ddbClient .getItem (ORIGINAL_TABLE_NAME_TO_OVERRIDE , itemKey ).getItem ();
137
138
System .out .println ("Encrypted Record: " + encryptedItem );
138
139
139
140
Map <String , Set <EncryptionFlags >> encryptionFlags = new HashMap <>();
@@ -151,19 +152,19 @@ public static void encryptRecord(
151
152
new EncryptionContext .Builder ()
152
153
.withHashKeyName (PARTITION_ATTRIBUTE )
153
154
.withRangeKeyName (SORT_ATTRIBUTE )
154
- .withTableName (newEncryptionContextTableName )
155
+ .withTableName (currentTableName )
155
156
.build ());
156
157
System .out .printf (
157
158
"The example item was encrypted using the table name '%s' in the EncryptionContext%n" ,
158
- newEncryptionContextTableName );
159
+ currentTableName );
159
160
160
161
// The decrypted field matches the original field before encryption
161
162
assert record
162
163
.getExample ()
163
164
.equals (decrypted_without_override_record .get (STRING_FIELD_NAME ).getS ());
164
165
}
165
166
166
- @ DynamoDBTable (tableName = TABLE_NAME_TO_OVERRIDE )
167
+ @ DynamoDBTable (tableName = ORIGINAL_TABLE_NAME_TO_OVERRIDE )
167
168
public static final class ExampleItem {
168
169
private String partitionAttribute ;
169
170
private int sortAttribute ;
0 commit comments