You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/11/07 18:48:05 UTC
[1/2] activemq-artemis git commit: ARTEMIS-841 Hash Processors lock
free lazy singleton instantiation
Repository: activemq-artemis
Updated Branches:
refs/heads/master 6c664c1cb -> e83eb3829
ARTEMIS-841 Hash Processors lock free lazy singleton instantiation
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/3281698f
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/3281698f
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/3281698f
Branch: refs/heads/master
Commit: 3281698f9f15660922a8f835e2e6593088f533bf
Parents: 6c664c1
Author: Francesco Nigro <ni...@gmail.com>
Authored: Mon Nov 7 13:33:52 2016 +0100
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Nov 7 13:47:22 2016 -0500
----------------------------------------------------------------------
.../artemis/utils/PasswordMaskingUtil.java | 90 +++++++++++---------
1 file changed, 49 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3281698f/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java
index bee3861..6360fb2 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java
@@ -25,64 +25,73 @@ import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
import org.apache.activemq.artemis.logs.ActiveMQUtilBundle;
-public class PasswordMaskingUtil {
+public final class PasswordMaskingUtil {
- private static final String PLAINTEXT_PROCESSOR = "plaintext";
- private static final String SECURE_PROCESSOR = "secure";
+ private PasswordMaskingUtil() {
- private static final Map<String, HashProcessor> processors = new HashMap<>();
+ }
- //stored password takes 2 forms, ENC() or plain text
- public static HashProcessor getHashProcessor(String storedPassword) throws Exception {
+ private static final class LazyPlainTextProcessorHolder {
+
+ private LazyPlainTextProcessorHolder() {
- if (!isEncoded(storedPassword)) {
- return getPlaintextProcessor();
}
- return getSecureProcessor();
+
+ private static final HashProcessor INSTANCE = new NoHashProcessor();
+
}
- private static boolean isEncoded(String storedPassword) {
- if (storedPassword == null) {
- return true;
+ private static final class LazySecureProcessorHolder {
+
+ private LazySecureProcessorHolder() {
+
}
- if (storedPassword.startsWith("ENC(") && storedPassword.endsWith(")")) {
- return true;
+ private static final HashProcessor INSTANCE;
+ private static final Exception EXCEPTION;
+
+ static {
+ HashProcessor processor = null;
+ Exception exception = null;
+ final String codecDesc = "org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec;algorithm=one-way";
+ try {
+ final DefaultSensitiveStringCodec codec = (DefaultSensitiveStringCodec) PasswordMaskingUtil.getCodec(codecDesc);
+ processor = new SecureHashProcessor(codec);
+ } catch (Exception e) {
+ //THE STACK TRACE IS THE ORIGINAL ONE!
+ exception = e;
+ } finally {
+ EXCEPTION = exception;
+ INSTANCE = processor;
+ }
}
- return false;
}
- public static HashProcessor getHashProcessor() {
- HashProcessor processor = null;
- try {
- processor = getSecureProcessor();
- } catch (Exception e) {
- processor = getPlaintextProcessor();
+ //stored password takes 2 forms, ENC() or plain text
+ public static HashProcessor getHashProcessor(String storedPassword) throws Exception {
+
+ if (!isEncoded(storedPassword)) {
+ return LazyPlainTextProcessorHolder.INSTANCE;
}
- return processor;
+ final Exception secureProcessorException = LazySecureProcessorHolder.EXCEPTION;
+ if (secureProcessorException != null) {
+ //reuse old descriptions/messages of the exception but refill the stack trace
+ throw new RuntimeException(secureProcessorException);
+ }
+ return LazySecureProcessorHolder.INSTANCE;
}
- public static HashProcessor getPlaintextProcessor() {
- synchronized (processors) {
- HashProcessor plain = processors.get(PLAINTEXT_PROCESSOR);
- if (plain == null) {
- plain = new NoHashProcessor();
- processors.put(PLAINTEXT_PROCESSOR, plain);
- }
- return plain;
- }
+ private static boolean isEncoded(String storedPassword) {
+ return storedPassword == null || (storedPassword.startsWith("ENC(") && storedPassword.endsWith(")"));
}
- public static HashProcessor getSecureProcessor() throws Exception {
- synchronized (processors) {
- HashProcessor processor = processors.get(SECURE_PROCESSOR);
- if (processor == null) {
- DefaultSensitiveStringCodec codec = (DefaultSensitiveStringCodec) getCodec("org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec;algorithm=one-way");
- processor = new SecureHashProcessor(codec);
- processors.put(SECURE_PROCESSOR, processor);
- }
- return processor;
+ public static HashProcessor getHashProcessor() {
+ HashProcessor processor = LazySecureProcessorHolder.INSTANCE;
+ //it can be null due to a previous failed attempts to instantiate it!
+ if (processor == null) {
+ processor = LazyPlainTextProcessorHolder.INSTANCE;
}
+ return processor;
}
/*
@@ -142,5 +151,4 @@ public class PasswordMaskingUtil {
return new DefaultSensitiveStringCodec();
}
-
}
[2/2] activemq-artemis git commit: This closes #881
Posted by cl...@apache.org.
This closes #881
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/e83eb382
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/e83eb382
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/e83eb382
Branch: refs/heads/master
Commit: e83eb382975290f8ee8a9d66efe72ecf2fa5d960
Parents: 6c664c1 3281698
Author: Clebert Suconic <cl...@apache.org>
Authored: Mon Nov 7 13:47:23 2016 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Nov 7 13:47:23 2016 -0500
----------------------------------------------------------------------
.../artemis/utils/PasswordMaskingUtil.java | 90 +++++++++++---------
1 file changed, 49 insertions(+), 41 deletions(-)
----------------------------------------------------------------------