PasswordMaskingUtil { public static SensitiveDataCodec<String> getCodec(String codecDesc) throws ActiveMQException { SensitiveDataCodec<String> codecInstance; if (codecDesc == null) { return getDefaultCodec(); } String[] parts = codecDesc.split(";"); if (parts.length < 1) throw new ActiveMQException(ActiveMQExceptionType.ILLEGAL_STATE, "Invalid PasswordCodec value: " + codecDesc); final String codecClassName = parts[0]; codecInstance = AccessController.doPrivileged((PrivilegedAction<SensitiveDataCodec<String>>) () -> { ServiceLoader<SensitiveDataCodec> serviceLoader = ServiceLoader.load(SensitiveDataCodec.class, PasswordMaskingUtil.class.getClassLoader()); try { for (SensitiveDataCodec<String> codec : serviceLoader) { if (codec.getClass().getCanonicalName().equals(codecClassName)) { return codec.getClass().newInstance(); } } } catch (Exception e) { } try { return (SensitiveDataCodec<String>) PasswordMaskingUtil.class.getClassLoader().loadClass(codecClassName).newInstance(); } catch (Exception e) { try { return (SensitiveDataCodec<String>) Thread.currentThread().getContextClassLoader().loadClass(codecClassName).newInstance(); } catch (Exception e2) { throw ActiveMQUtilBundle.BUNDLE.errorCreatingCodec(e2, codecClassName); } } }); if (parts.length > 1) { Map<String, String> props = new HashMap<>(); for (int i = 1; i < parts.length; i++) { String[] keyVal = parts[i].split("="); if (keyVal.length != 2) throw ActiveMQUtilBundle.BUNDLE.invalidProperty(parts[i]); props.put(keyVal[0], keyVal[1]); } try { codecInstance.init(props); } catch (Exception e) { throw new ActiveMQException("Fail to init codec", e, ActiveMQExceptionType.SECURITY_EXCEPTION); } } return codecInstance; } private  PasswordMaskingUtil(); static String resolveMask(Boolean maskPassword, String password, String codecClass); static boolean isEncMasked(String password); static String unwrap(String password); static String wrap(String password); static HashProcessor getHashProcessor(String storedPassword); static HashProcessor getHashProcessor(); static SensitiveDataCodec<String> getCodec(String codecDesc); static DefaultSensitiveStringCodec getDefaultCodec(); static final String BEGIN_ENC; static final String END_ENC; }
@Test(expected = IllegalArgumentException.class) public void testGetCodecUsingInvalidCodec() throws Exception { PasswordMaskingUtil.getCodec("codec doesn't exist"); }