[ 
https://issues.apache.org/jira/browse/ARTEMIS-1252?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16068745#comment-16068745
 ] 

ASF GitHub Bot commented on ARTEMIS-1252:
-----------------------------------------

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.


> Add service loading of password codec to obtain its implementation from the 
> application’s root context, rather than using a class loader
> ----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: ARTEMIS-1252
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-1252
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>    Affects Versions: 1.5.5, 2.1.0
>            Reporter: Armand Roelens
>
> The current implementation for retrieving a custom password codec forces 
> every OSGI bundle requiring the password codec (which can be every bundle 
> with its own client that attempts to connect to the broker) to import the 
> package containing the custom password codec.
> If the password codec is instead service loaded, none of the OSGI bundles 
> need to import the package containing the password codec. That password codec 
> package does need to advertise its implementation via a configuration file, 
> but that change is limited to just that package. 
> Add service loading of the custom password codec, and as a fallback, if no 
> service is found, maintain the current implementation of using normal class 
> loading.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to