You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by roelens8 <gi...@git.apache.org> on 2017/06/26 16:34:52 UTC
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
GitHub user roelens8 opened a pull request:
https://github.com/apache/activemq-artemis/pull/1366
ARTEMIS-1252 Add service loading of password codec to obtain its implementation from the app's root context
Adds service loading to obtain implementation of password codec. If no service is found, the fallback is to use a class loader like before.
Refer to here for more information: https://issues.apache.org/jira/browse/ARTEMIS-1252
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/roelens8/activemq-artemis ARTEMIS-1252
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/activemq-artemis/pull/1366.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1366
----
commit 9dcd7f36acc3e88c8831051ecb9df55f2ac29c02
Author: Armand Roelens <ar...@connexta.com>
Date: 2017-06-26T16:30:04Z
ARTEMIS-1252 Add service loading of password codec to obtain its implementation from the app's root context
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis issue #1366: ARTEMIS-1252 Add service loading of password c...
Posted by clebertsuconic <gi...@git.apache.org>.
Github user clebertsuconic commented on the issue:
https://github.com/apache/activemq-artemis/pull/1366
Thanks!!!!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by jbertram <gi...@git.apache.org>.
Github user jbertram commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1366#discussion_r124572986
--- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java ---
@@ -108,22 +110,29 @@ public static HashProcessor getHashProcessor() {
// semi colons
String[] parts = codecDesc.split(";");
-
if (parts.length < 1)
throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc);
final String codecClassName = parts[0];
// load class
- codecInstance = AccessController.doPrivileged(new PrivilegedAction<SensitiveDataCodec<String>>() {
- @Override
- public SensitiveDataCodec<String> run() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> {
+ ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader());
--- End diff --
@howardgao did the original implementation here, although I've looked through the code a handful of times. The PR looks good to me.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by roelens8 <gi...@git.apache.org>.
Github user roelens8 commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1366#discussion_r124571031
--- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java ---
@@ -108,22 +110,29 @@ public static HashProcessor getHashProcessor() {
// semi colons
String[] parts = codecDesc.split(";");
-
if (parts.length < 1)
throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc);
final String codecClassName = parts[0];
// load class
- codecInstance = AccessController.doPrivileged(new PrivilegedAction<SensitiveDataCodec<String>>() {
- @Override
- public SensitiveDataCodec<String> run() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> {
+ ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader());
--- End diff --
Sure, that's no problem!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by clebertsuconic <gi...@git.apache.org>.
Github user clebertsuconic commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1366#discussion_r124090489
--- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java ---
@@ -108,22 +110,29 @@ public static HashProcessor getHashProcessor() {
// semi colons
String[] parts = codecDesc.split(";");
-
if (parts.length < 1)
throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc);
final String codecClassName = parts[0];
// load class
- codecInstance = AccessController.doPrivileged(new PrivilegedAction<SensitiveDataCodec<String>>() {
- @Override
- public SensitiveDataCodec<String> run() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> {
+ ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader());
--- End diff --
Looks like a nice feature.. but no tests?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by clebertsuconic <gi...@git.apache.org>.
Github user clebertsuconic commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1366#discussion_r124569686
--- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java ---
@@ -108,22 +110,29 @@ public static HashProcessor getHashProcessor() {
// semi colons
String[] parts = codecDesc.split(";");
-
if (parts.length < 1)
throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc);
final String codecClassName = parts[0];
// load class
- codecInstance = AccessController.doPrivileged(new PrivilegedAction<SensitiveDataCodec<String>>() {
- @Override
- public SensitiveDataCodec<String> run() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> {
+ ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader());
--- End diff --
I think so...
This is an area where @jbertram has done more work than me.. I was going to wait on him..
I work with him and I believe he's out of the office today.
is that ok?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by roelens8 <gi...@git.apache.org>.
Github user roelens8 commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1366#discussion_r124877640
--- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java ---
@@ -108,22 +109,34 @@ public static HashProcessor getHashProcessor() {
// semi colons
String[] parts = codecDesc.split(";");
-
if (parts.length < 1)
throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc);
final String codecClassName = parts[0];
// load class
- codecInstance = AccessController.doPrivileged(new PrivilegedAction<SensitiveDataCodec<String>>() {
- @Override
- public SensitiveDataCodec<String> run() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> {
+ ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader());
+ try {
+ // Service load the codec, if a service is available
+ for (SensitiveDataCodec<String> codec : serviceLoader) {
+ if ((codec.getClass().getCanonicalName()).equals(codecClassName)) {
+ return codec.getClass().newInstance();
+ }
+ }
+ // If a service is not available, load the codec class using this class's class loader
+ return (SensitiveDataCodec<String>) PasswordMaskingUtil.class.getClassLoader().loadClass(codecClassName).newInstance();
+ } catch (Exception e) {
try {
- Class<?> clazz = loader.loadClass(codecClassName);
- return (SensitiveDataCodec<String>) clazz.newInstance();
- } catch (Exception e) {
- throw ActiveMQUtilBundle.BUNDLE.errorCreatingCodec(e, codecClassName);
+ // If service loading failed, load the codec class using this class's class loader
+ return (SensitiveDataCodec<String>) PasswordMaskingUtil.class.getClassLoader().loadClass(codecClassName).newInstance();
--- End diff --
I have cleaned up the code here. It should not attempt to load the codec twice using this class's class loader, if it fail had the first time.
I also updated the documentation to mention that the custom password codec can be service loaded.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by gaohoward <gi...@git.apache.org>.
Github user gaohoward commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1366#discussion_r124948436
--- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java ---
@@ -108,22 +110,29 @@ public static HashProcessor getHashProcessor() {
// semi colons
String[] parts = codecDesc.split(";");
-
if (parts.length < 1)
throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc);
final String codecClassName = parts[0];
// load class
- codecInstance = AccessController.doPrivileged(new PrivilegedAction<SensitiveDataCodec<String>>() {
- @Override
- public SensitiveDataCodec<String> run() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> {
+ ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader());
--- End diff --
+1 :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by roelens8 <gi...@git.apache.org>.
Github user roelens8 commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1366#discussion_r124116668
--- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java ---
@@ -108,22 +110,29 @@ public static HashProcessor getHashProcessor() {
// semi colons
String[] parts = codecDesc.split(";");
-
if (parts.length < 1)
throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc);
final String codecClassName = parts[0];
// load class
- codecInstance = AccessController.doPrivileged(new PrivilegedAction<SensitiveDataCodec<String>>() {
- @Override
- public SensitiveDataCodec<String> run() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> {
+ ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader());
--- End diff --
Added a couple unit tests. Are they sufficient enough?
Also, should the documentation be updated to mention this new feature?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/activemq-artemis/pull/1366
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis pull request #1366: ARTEMIS-1252 Add service loading of pas...
Posted by clebertsuconic <gi...@git.apache.org>.
Github user clebertsuconic commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1366#discussion_r124801911
--- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/PasswordMaskingUtil.java ---
@@ -108,22 +109,34 @@ public static HashProcessor getHashProcessor() {
// semi colons
String[] parts = codecDesc.split(";");
-
if (parts.length < 1)
throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc);
final String codecClassName = parts[0];
// load class
- codecInstance = AccessController.doPrivileged(new PrivilegedAction<SensitiveDataCodec<String>>() {
- @Override
- public SensitiveDataCodec<String> run() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> {
+ ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader());
+ try {
+ // Service load the codec, if a service is available
+ for (SensitiveDataCodec<String> codec : serviceLoader) {
+ if ((codec.getClass().getCanonicalName()).equals(codecClassName)) {
+ return codec.getClass().newInstance();
+ }
+ }
+ // If a service is not available, load the codec class using this class's class loader
+ return (SensitiveDataCodec<String>) PasswordMaskingUtil.class.getClassLoader().loadClass(codecClassName).newInstance();
+ } catch (Exception e) {
try {
- Class<?> clazz = loader.loadClass(codecClassName);
- return (SensitiveDataCodec<String>) clazz.newInstance();
- } catch (Exception e) {
- throw ActiveMQUtilBundle.BUNDLE.errorCreatingCodec(e, codecClassName);
+ // If service loading failed, load the codec class using this class's class loader
+ return (SensitiveDataCodec<String>) PasswordMaskingUtil.class.getClassLoader().loadClass(codecClassName).newInstance();
--- End diff --
I was just about to hit enter on merging when I realized something...
isn't this a mistake? Shouldn't this be using Thread.currentThread().classLoader()?
The previous call (inside the try... catch) was using this class classLoader.. if you catch an exception and try, I would expect to do somethng different.. like using the classLoader, not doing the same operation.
it seems a typo to me... can you check?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] activemq-artemis issue #1366: ARTEMIS-1252 Add service loading of password c...
Posted by roelens8 <gi...@git.apache.org>.
Github user roelens8 commented on the issue:
https://github.com/apache/activemq-artemis/pull/1366
@clebertsuconic is my PR good enough to be merged?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---