Skip to content

Commit 38c0a06

Browse files
rafapraxbrianchandotcom
authored andcommitted
LPD-43475 Throw exception if the PBKDF2EncryptionConfiguration#configure fail
1 parent f25bb95 commit 38c0a06

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

modules/apps/portal-security/portal-security-password-encryptor-impl/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ dependencies {
88
compileOnly group: "org.osgi", name: "osgi.core", version: "6.0.0"
99
compileOnly project(":core:osgi-service-tracker-collections")
1010
compileOnly project(":core:petra:petra-lang")
11+
compileOnly project(":core:petra:petra-reflect")
1112
compileOnly project(":core:petra:petra-string")
1213
}

modules/apps/portal-security/portal-security-password-encryptor-impl/src/main/java/com/liferay/portal/security/password/encryptor/internal/PBKDF2PasswordEncryptor.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
package com.liferay.portal.security.password.encryptor.internal;
77

8+
import com.liferay.petra.reflect.ReflectionUtil;
89
import com.liferay.petra.string.CharPool;
910
import com.liferay.petra.string.StringBundler;
1011
import com.liferay.petra.string.StringPool;
1112
import com.liferay.portal.kernel.exception.PwdEncryptorException;
1213
import com.liferay.portal.kernel.io.BigEndianCodec;
13-
import com.liferay.portal.kernel.log.Log;
14-
import com.liferay.portal.kernel.log.LogFactoryUtil;
1514
import com.liferay.portal.kernel.security.SecureRandomUtil;
1615
import com.liferay.portal.kernel.security.pwd.PasswordEncryptor;
1716
import com.liferay.portal.kernel.util.Base64;
@@ -97,26 +96,26 @@ public String encrypt(
9796
public String getEncryptionAlgorithmConfiguration(
9897
String encryptedPassword) {
9998

100-
PBKDF2EncryptionConfiguration pbkdf2EncryptionConfiguration =
101-
new PBKDF2EncryptionConfiguration();
99+
try {
100+
PBKDF2EncryptionConfiguration pbkdf2EncryptionConfiguration =
101+
new PBKDF2EncryptionConfiguration();
102102

103-
int index = encryptedPassword.indexOf(CharPool.CLOSE_CURLY_BRACE);
103+
int index = encryptedPassword.indexOf(CharPool.CLOSE_CURLY_BRACE);
104104

105-
try {
106105
pbkdf2EncryptionConfiguration.configure(
107106
StringPool.BLANK, encryptedPassword.substring(index + 1));
108-
}
109-
catch (Exception exception) {
110-
_log.error(exception);
111-
}
112107

113-
String algorithm = encryptedPassword.substring(1, index);
108+
String algorithm = encryptedPassword.substring(1, index);
114109

115-
return StringBundler.concat(
116-
algorithm, StringPool.FORWARD_SLASH,
117-
pbkdf2EncryptionConfiguration.getKeySize(),
118-
StringPool.FORWARD_SLASH,
119-
pbkdf2EncryptionConfiguration.getRounds());
110+
return StringBundler.concat(
111+
algorithm, StringPool.FORWARD_SLASH,
112+
pbkdf2EncryptionConfiguration.getKeySize(),
113+
StringPool.FORWARD_SLASH,
114+
pbkdf2EncryptionConfiguration.getRounds());
115+
}
116+
catch (PwdEncryptorException pwdEncryptorException) {
117+
return ReflectionUtil.throwException(pwdEncryptorException);
118+
}
120119
}
121120

122121
private static final int _KEY_SIZE = 160;
@@ -125,9 +124,6 @@ public String getEncryptionAlgorithmConfiguration(
125124

126125
private static final int _SALT_BYTES_LENGTH = 16;
127126

128-
private static final Log _log = LogFactoryUtil.getLog(
129-
PBKDF2PasswordEncryptor.class);
130-
131127
private static final Pattern _pattern = Pattern.compile(
132128
"^.*/?([0-9]+)?/([0-9]+)$");
133129

0 commit comments

Comments
 (0)