Skip to content

Commit bc21e80

Browse files
committed
Refactoring
1 parent 6ce3e12 commit bc21e80

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
@RequestMapping(value = "/contacts")
3939
public class ContactController {
4040
private static final Logger log = LoggerFactory.getLogger(ContactController.class);
41-
private ContactService contactService;
41+
private final ContactService contactService;
4242

4343
public ContactController(ContactService contactService) {
4444
this.contactService = contactService;

access-control-spring-security/src/main/java/de/dominikschadow/javasecurity/services/ContactService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
@Service
3737
public class ContactService {
38-
private JdbcTemplate jdbcTemplate;
38+
private final JdbcTemplate jdbcTemplate;
3939

4040
public ContactService(JdbcTemplate jdbcTemplate) {
4141
this.jdbcTemplate = jdbcTemplate;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static void sign() {
5757
final char[] keyPassword = "asymmetric-sample-dsa".toCharArray();
5858

5959
try {
60-
KeyStore ks = loadKeystore(KEYSTORE_PATH, keystorePassword);
60+
KeyStore ks = loadKeystore(keystorePassword);
6161
PrivateKey privateKey = loadPrivateKey(ks, keyAlias, keyPassword);
6262
PublicKey publicKey = loadPublicKey(ks, keyAlias);
6363

@@ -71,9 +71,9 @@ private static void sign() {
7171
}
7272
}
7373

74-
private static KeyStore loadKeystore(String keystorePath, char[] keystorePassword) throws KeyStoreException,
74+
private static KeyStore loadKeystore(char[] keystorePassword) throws KeyStoreException,
7575
CertificateException, NoSuchAlgorithmException, IOException {
76-
try (InputStream keystoreStream = DSA.class.getResourceAsStream(keystorePath)) {
76+
try (InputStream keystoreStream = DSA.class.getResourceAsStream(KEYSTORE_PATH)) {
7777
KeyStore ks = KeyStore.getInstance("JCEKS");
7878
ks.load(keystoreStream, keystorePassword);
7979
return ks;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static void encrypt() {
6161
final char[] keyPassword = "asymmetric-sample-rsa".toCharArray();
6262

6363
try {
64-
KeyStore ks = loadKeystore(KEYSTORE_PATH, keystorePassword);
64+
KeyStore ks = loadKeystore(keystorePassword);
6565
PrivateKey privateKey = loadPrivateKey(ks, keyAlias, keyPassword);
6666
PublicKey publicKey = loadPublicKey(ks, keyAlias);
6767

@@ -76,9 +76,9 @@ private static void encrypt() {
7676
}
7777
}
7878

79-
private static KeyStore loadKeystore(String keystorePath, char[] keystorePassword) throws KeyStoreException,
79+
private static KeyStore loadKeystore(char[] keystorePassword) throws KeyStoreException,
8080
CertificateException, NoSuchAlgorithmException, IOException {
81-
try (InputStream keystoreStream = RSA.class.getResourceAsStream(keystorePath)) {
81+
try (InputStream keystoreStream = RSA.class.getResourceAsStream(KEYSTORE_PATH)) {
8282
KeyStore ks = KeyStore.getInstance("JCEKS");
8383
ks.load(keystoreStream, keystorePassword);
8484
return ks;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void encrypt() {
6464

6565
try {
6666
cipher = Cipher.getInstance(ALGORITHM);
67-
KeyStore ks = loadKeystore(KEYSTORE_PATH, keystorePassword);
67+
KeyStore ks = loadKeystore(keystorePassword);
6868
Key key = loadKey(ks, keyAlias, keyPassword);
6969
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getEncoded(), "AES");
7070
byte[] ciphertext = encrypt(secretKeySpec, initialText);
@@ -79,9 +79,9 @@ private void encrypt() {
7979
}
8080
}
8181

82-
private KeyStore loadKeystore(String keystorePath, char[] keystorePassword) throws KeyStoreException,
82+
private KeyStore loadKeystore(char[] keystorePassword) throws KeyStoreException,
8383
CertificateException, NoSuchAlgorithmException, IOException {
84-
try (InputStream keystoreStream = getClass().getResourceAsStream(keystorePath)) {
84+
try (InputStream keystoreStream = getClass().getResourceAsStream(KEYSTORE_PATH)) {
8585
KeyStore ks = KeyStore.getInstance("JCEKS");
8686
ks.load(keystoreStream, keystorePassword);
8787

@@ -98,15 +98,15 @@ private static Key loadKey(KeyStore ks, String keyAlias, char[] keyPassword) thr
9898
return ks.getKey(keyAlias, keyPassword);
9999
}
100100

101-
private byte[] encrypt(SecretKeySpec secretKeySpec, String initialText) throws NoSuchPaddingException,
102-
NoSuchAlgorithmException, UnsupportedEncodingException, BadPaddingException,
103-
IllegalBlockSizeException, InvalidAlgorithmParameterException, InvalidKeyException {
101+
private byte[] encrypt(SecretKeySpec secretKeySpec, String initialText) throws
102+
UnsupportedEncodingException, BadPaddingException,
103+
IllegalBlockSizeException, InvalidKeyException {
104104
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
105105
return cipher.doFinal(initialText.getBytes("UTF-8"));
106106
}
107107

108-
private byte[] decrypt(SecretKeySpec secretKeySpec, byte[] ciphertext) throws NoSuchPaddingException,
109-
NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException,
108+
private byte[] decrypt(SecretKeySpec secretKeySpec, byte[] ciphertext) throws
109+
BadPaddingException, IllegalBlockSizeException,
110110
InvalidAlgorithmParameterException, InvalidKeyException {
111111
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(cipher.getIV()));
112112
return cipher.doFinal(ciphertext);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void main(String[] args) {
5151
final char[] keyPassword = "symmetric-sample".toCharArray();
5252

5353
try {
54-
KeyStore ks = loadKeystore(KEYSTORE_PATH, keystorePassword);
54+
KeyStore ks = loadKeystore(keystorePassword);
5555
Key key = loadKey(ks, keyAlias, keyPassword);
5656
byte[] ciphertext = encrypt(key, CodecSupport.toBytes(initialText));
5757
byte[] plaintext = decrypt(key, ciphertext);
@@ -62,8 +62,8 @@ public static void main(String[] args) {
6262
}
6363
}
6464

65-
private static KeyStore loadKeystore(String keystorePath, char[] keystorePassword) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
66-
InputStream keystoreStream = AESEncryption.class.getResourceAsStream(keystorePath);
65+
private static KeyStore loadKeystore(char[] keystorePassword) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
66+
InputStream keystoreStream = AESEncryption.class.getResourceAsStream(KEYSTORE_PATH);
6767

6868
KeyStore ks = KeyStore.getInstance("JCEKS");
6969
ks.load(keystoreStream, keystorePassword);

0 commit comments

Comments
 (0)