Skip to content

Commit 4ed3d2c

Browse files
committed
Refactoring
1 parent 8457e75 commit 4ed3d2c

File tree

39 files changed

+147
-147
lines changed

39 files changed

+147
-147
lines changed

access-control-spring-security/src/main/java/de/dominikschadow/javasecurity/controller/ContactController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
@Controller
3838
@RequestMapping(value = "/contacts")
3939
public class ContactController {
40-
private static final Logger LOGGER = LoggerFactory.getLogger(ContactController.class);
40+
private static final Logger log = LoggerFactory.getLogger(ContactController.class);
4141
private ContactService contactService;
4242

4343
public ContactController(ContactService contactService) {
@@ -48,7 +48,7 @@ public ContactController(ContactService contactService) {
4848
public String list(Model model) {
4949
List<Contact> contacts = contactService.getContacts();
5050

51-
LOGGER.info("Found {} contacts for user", contacts.size());
51+
log.info("Found {} contacts for user", contacts.size());
5252

5353
model.addAttribute("contacts", contacts);
5454

@@ -57,7 +57,7 @@ public String list(Model model) {
5757

5858
@GetMapping("{contactId}")
5959
public String details(@PathVariable int contactId, Model model) {
60-
LOGGER.info("Loading contact with ID {} for user", contactId);
60+
log.info("Loading contact with ID {} for user", contactId);
6161

6262
Contact contact = contactService.getContact(contactId);
6363

crypto-hash/src/main/java/de/dominikschadow/javasecurity/hash/MD5.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @author Dominik Schadow
3535
*/
3636
public class MD5 {
37-
private static final Logger LOGGER = LoggerFactory.getLogger(MD5.class);
37+
private static final Logger log = LoggerFactory.getLogger(MD5.class);
3838
private static final String ALGORITHM = "MD5";
3939

4040
/**
@@ -50,9 +50,9 @@ public static void main(String[] args) {
5050
byte[] hash = calculateHash(password);
5151
boolean correct = verifyPassword(hash, password);
5252

53-
LOGGER.info("Entered password is correct: {}", correct);
53+
log.info("Entered password is correct: {}", correct);
5454
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
55-
LOGGER.error(ex.getMessage(), ex);
55+
log.error(ex.getMessage(), ex);
5656
}
5757
}
5858

@@ -68,8 +68,8 @@ private static boolean verifyPassword(byte[] originalHash, String password) thro
6868
NoSuchAlgorithmException, UnsupportedEncodingException {
6969
byte[] comparisonHash = calculateHash(password);
7070

71-
LOGGER.info("hash 1: {}", BaseEncoding.base16().encode(originalHash));
72-
LOGGER.info("hash 2: {}", BaseEncoding.base16().encode(comparisonHash));
71+
log.info("hash 1: {}", BaseEncoding.base16().encode(originalHash));
72+
log.info("hash 2: {}", BaseEncoding.base16().encode(comparisonHash));
7373

7474
return comparePasswords(originalHash, comparisonHash);
7575
}

crypto-hash/src/main/java/de/dominikschadow/javasecurity/hash/PBKDF2.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @author Dominik Schadow
3737
*/
3838
public class PBKDF2 {
39-
private static final Logger LOGGER = LoggerFactory.getLogger(PBKDF2.class);
39+
private static final Logger log = LoggerFactory.getLogger(PBKDF2.class);
4040
private static final String ALGORITHM = "PBKDF2WithHmacSHA1";
4141
private static final int ITERATIONS = 10000;
4242
// salt size at least 32 byte
@@ -60,15 +60,15 @@ private static void hash() {
6060
SecretKeyFactory skf = SecretKeyFactory.getInstance(ALGORITHM);
6161
byte[] salt = generateSalt();
6262

63-
LOGGER.info("Hashing password {} with hash algorithm {}, hash size {}, # of iterations {} and salt {}",
63+
log.info("Hashing password {} with hash algorithm {}, hash size {}, # of iterations {} and salt {}",
6464
String.valueOf(password), ALGORITHM, HASH_SIZE, ITERATIONS, BaseEncoding.base16().encode(salt));
6565

6666
byte[] hash = calculateHash(skf, password, salt);
6767
boolean correct = verifyPassword(skf, hash, password, salt);
6868

69-
LOGGER.info("Entered password is correct: {}", correct);
69+
log.info("Entered password is correct: {}", correct);
7070
} catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
71-
LOGGER.error(ex.getMessage(), ex);
71+
log.error(ex.getMessage(), ex);
7272
}
7373
}
7474

@@ -90,8 +90,8 @@ private static boolean verifyPassword(SecretKeyFactory skf, byte[] originalHash,
9090
InvalidKeySpecException {
9191
byte[] comparisonHash = calculateHash(skf, password, salt);
9292

93-
LOGGER.info("hash 1: {}", BaseEncoding.base16().encode(originalHash));
94-
LOGGER.info("hash 2: {}", BaseEncoding.base16().encode(comparisonHash));
93+
log.info("hash 1: {}", BaseEncoding.base16().encode(originalHash));
94+
log.info("hash 2: {}", BaseEncoding.base16().encode(comparisonHash));
9595

9696
return comparePasswords(originalHash, comparisonHash);
9797
}

crypto-hash/src/main/java/de/dominikschadow/javasecurity/hash/SHA512.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @author Dominik Schadow
3737
*/
3838
public class SHA512 {
39-
private static final Logger LOGGER = LoggerFactory.getLogger(SHA512.class);
39+
private static final Logger log = LoggerFactory.getLogger(SHA512.class);
4040
private static final String ALGORITHM = "SHA-512";
4141
private static final int ITERATIONS = 1000000;
4242
private static final int SALT_SIZE = 64;
@@ -53,15 +53,15 @@ public static void main(String[] args) {
5353
try {
5454
byte[] salt = generateSalt();
5555

56-
LOGGER.info("Password {}. hash algorithm {}, iterations {}, salt {}", password, ALGORITHM, ITERATIONS,
56+
log.info("Password {}. hash algorithm {}, iterations {}, salt {}", password, ALGORITHM, ITERATIONS,
5757
BaseEncoding.base16().encode(salt));
5858

5959
byte[] hash = calculateHash(password, salt);
6060
boolean correct = verifyPassword(hash, password, salt);
6161

62-
LOGGER.info("Entered password is correct: {}", correct);
62+
log.info("Entered password is correct: {}", correct);
6363
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
64-
LOGGER.error(ex.getMessage(), ex);
64+
log.error(ex.getMessage(), ex);
6565
}
6666
}
6767

@@ -92,8 +92,8 @@ private static boolean verifyPassword(byte[] originalHash, String password, byte
9292
NoSuchAlgorithmException, UnsupportedEncodingException {
9393
byte[] comparisonHash = calculateHash(password, salt);
9494

95-
LOGGER.info("hash 1: {}", BaseEncoding.base16().encode(originalHash));
96-
LOGGER.info("hash 2: {}", BaseEncoding.base16().encode(comparisonHash));
95+
log.info("hash 1: {}", BaseEncoding.base16().encode(originalHash));
96+
log.info("hash 2: {}", BaseEncoding.base16().encode(comparisonHash));
9797

9898
return comparePasswords(originalHash, comparisonHash);
9999
}

crypto-java/src/main/java/de/dominikschadow/javasecurity/asymmetric/DSA.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @author Dominik Schadow
3737
*/
3838
public class DSA {
39-
private static final Logger LOGGER = LoggerFactory.getLogger(DSA.class);
39+
private static final Logger log = LoggerFactory.getLogger(DSA.class);
4040
private static final String ALGORITHM = "SHA1withDSA";
4141
private static final String KEYSTORE_PATH = "/samples.ks";
4242

@@ -67,7 +67,7 @@ private static void sign() {
6767
printReadableMessages(initialText, signature, valid);
6868
} catch (NoSuchAlgorithmException | SignatureException | KeyStoreException | CertificateException |
6969
UnrecoverableKeyException | InvalidKeyException | IOException ex) {
70-
LOGGER.error(ex.getMessage(), ex);
70+
log.error(ex.getMessage(), ex);
7171
}
7272
}
7373

@@ -114,8 +114,8 @@ private static boolean verify(PublicKey publicKey, byte[] signature, String init
114114
}
115115

116116
private static void printReadableMessages(String initialText, byte[] signature, boolean valid) {
117-
LOGGER.info("initial text: {}", initialText);
118-
LOGGER.info("signature: {}", BaseEncoding.base16().encode(signature));
119-
LOGGER.info("signature valid: {}", valid);
117+
log.info("initial text: {}", initialText);
118+
log.info("signature: {}", BaseEncoding.base16().encode(signature));
119+
log.info("signature valid: {}", valid);
120120
}
121121
}

crypto-java/src/main/java/de/dominikschadow/javasecurity/asymmetric/RSA.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* @author Dominik Schadow
4141
*/
4242
public class RSA {
43-
private static final Logger LOGGER = LoggerFactory.getLogger(RSA.class);
43+
private static final Logger log = LoggerFactory.getLogger(RSA.class);
4444
private static final String ALGORITHM = "RSA";
4545
private static final String KEYSTORE_PATH = "/samples.ks";
4646

@@ -72,7 +72,7 @@ private static void encrypt() {
7272
} catch (NoSuchPaddingException | NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException |
7373
KeyStoreException | CertificateException | UnrecoverableKeyException | InvalidKeyException |
7474
IOException ex) {
75-
LOGGER.error(ex.getMessage(), ex);
75+
log.error(ex.getMessage(), ex);
7676
}
7777
}
7878

@@ -119,8 +119,8 @@ private static byte[] decrypt(PrivateKey privateKey, byte[] ciphertext) throws N
119119
}
120120

121121
private static void printReadableMessages(String initialText, byte[] ciphertext, byte[] plaintext) {
122-
LOGGER.info("initial text: {}", initialText);
123-
LOGGER.info("cipher text: {}", BaseEncoding.base16().encode(ciphertext));
124-
LOGGER.info("plain text: {}", new String(plaintext));
122+
log.info("initial text: {}", initialText);
123+
log.info("cipher text: {}", BaseEncoding.base16().encode(ciphertext));
124+
log.info("plain text: {}", new String(plaintext));
125125
}
126126
}

crypto-java/src/main/java/de/dominikschadow/javasecurity/symmetric/AES.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @author Dominik Schadow
4747
*/
4848
public class AES {
49-
private static final Logger LOGGER = LoggerFactory.getLogger(AES.class);
49+
private static final Logger log = LoggerFactory.getLogger(AES.class);
5050
private static final String ALGORITHM = "AES/CBC/PKCS5Padding";
5151
private static final String KEYSTORE_PATH = "/samples.ks";
5252
private Cipher cipher;
@@ -75,7 +75,7 @@ private void encrypt() {
7575
KeyStoreException | CertificateException | UnrecoverableKeyException |
7676
InvalidAlgorithmParameterException |
7777
InvalidKeyException | IOException ex) {
78-
LOGGER.error(ex.getMessage(), ex);
78+
log.error(ex.getMessage(), ex);
7979
}
8080
}
8181

@@ -113,8 +113,8 @@ private byte[] decrypt(SecretKeySpec secretKeySpec, byte[] ciphertext) throws No
113113
}
114114

115115
private static void printReadableMessages(String initialText, byte[] ciphertext, byte[] plaintext) {
116-
LOGGER.info("initial text: {}", initialText);
117-
LOGGER.info("cipher text: {}", BaseEncoding.base16().encode(ciphertext));
118-
LOGGER.info("plain text: {}", new String(plaintext));
116+
log.info("initial text: {}", initialText);
117+
log.info("cipher text: {}", BaseEncoding.base16().encode(ciphertext));
118+
log.info("plain text: {}", new String(plaintext));
119119
}
120120
}

crypto-keyczar/src/main/java/de/dominikschadow/javasecurity/asymmetric/DSASignature.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @author Dominik Schadow
3030
*/
3131
public class DSASignature {
32-
private static final Logger LOGGER = LoggerFactory.getLogger(DSASignature.class);
32+
private static final Logger log = LoggerFactory.getLogger(DSASignature.class);
3333
private static final String KEYSET_PATH = "crypto-keyczar/src/main/resources/key-sets/sign";
3434

3535
/**
@@ -46,7 +46,7 @@ public static void main(String[] args) {
4646

4747
printReadableMessages(initialText, signature, valid);
4848
} catch (KeyczarException ex) {
49-
LOGGER.error(ex.getMessage(), ex);
49+
log.error(ex.getMessage(), ex);
5050
}
5151
}
5252

@@ -61,8 +61,8 @@ private static boolean verify(String initialText, String signature) throws Keycz
6161
}
6262

6363
private static void printReadableMessages(String initialText, String signature, boolean valid) {
64-
LOGGER.info("initialText: {}", initialText);
65-
LOGGER.info("signature: {}", signature);
66-
LOGGER.info("signature valid: {}", valid);
64+
log.info("initialText: {}", initialText);
65+
log.info("signature: {}", signature);
66+
log.info("signature valid: {}", valid);
6767
}
6868
}

crypto-keyczar/src/main/java/de/dominikschadow/javasecurity/asymmetric/RSAEncryption.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @author Dominik Schadow
2929
*/
3030
public class RSAEncryption {
31-
private static final Logger LOGGER = LoggerFactory.getLogger(RSAEncryption.class);
31+
private static final Logger log = LoggerFactory.getLogger(RSAEncryption.class);
3232
private static final String KEYSET_PATH = "crypto-keyczar/src/main/resources/key-sets/encrypt/asymmetric";
3333

3434
/**
@@ -45,7 +45,7 @@ public static void main(String[] args) {
4545

4646
printReadableMessages(initialText, ciphertext, plaintext);
4747
} catch (KeyczarException ex) {
48-
LOGGER.error(ex.getMessage(), ex);
48+
log.error(ex.getMessage(), ex);
4949
}
5050
}
5151

@@ -67,8 +67,8 @@ private static String decrypt(String ciphertext) throws KeyczarException {
6767
}
6868

6969
private static void printReadableMessages(String initialText, String ciphertext, String plaintext) {
70-
LOGGER.info("initialText: {}", initialText);
71-
LOGGER.info("cipherText: {}", ciphertext);
72-
LOGGER.info("plaintext: {}", plaintext);
70+
log.info("initialText: {}", initialText);
71+
log.info("cipherText: {}", ciphertext);
72+
log.info("plaintext: {}", plaintext);
7373
}
7474
}

crypto-keyczar/src/main/java/de/dominikschadow/javasecurity/symmetric/AESEncryption.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @author Dominik Schadow
3030
*/
3131
public class AESEncryption {
32-
private static final Logger LOGGER = LoggerFactory.getLogger(AESEncryption.class);
32+
private static final Logger log = LoggerFactory.getLogger(AESEncryption.class);
3333
private static final String KEYSET_PATH = "crypto-keyczar/src/main/resources/key-sets/encrypt/symmetric";
3434

3535
/**
@@ -46,7 +46,7 @@ public static void main(String[] args) {
4646

4747
printReadableMessages(initialText, ciphertext, plaintext);
4848
} catch (KeyczarException ex) {
49-
LOGGER.error(ex.getMessage(), ex);
49+
log.error(ex.getMessage(), ex);
5050
}
5151
}
5252

@@ -68,8 +68,8 @@ private static String decrypt(String ciphertext) throws KeyczarException {
6868
}
6969

7070
private static void printReadableMessages(String initialText, String ciphertext, String plaintext) {
71-
LOGGER.info("initialText: {}", initialText);
72-
LOGGER.info("cipherText as Base64: {}", ciphertext);
73-
LOGGER.info("plaintext: {}", plaintext);
71+
log.info("initialText: {}", initialText);
72+
log.info("cipherText as Base64: {}", ciphertext);
73+
log.info("plaintext: {}", plaintext);
7474
}
7575
}

0 commit comments

Comments
 (0)