public static String getPasswordProperty(final String propName, final String def, final Map<String, ?> props, String defaultMaskPassword, String defaultPasswordCodec) { if (props == null) { return def; } Object prop = props.get(propName); if (prop == null) { return def; } String value = prop.toString(); Object useMaskObject = props.get(defaultMaskPassword); Boolean useMask; if (useMaskObject instanceof String) { useMask = Boolean.parseBoolean((String)useMaskObject); } else { useMask = (Boolean) useMaskObject; } final String classImpl = (String) props.get(defaultPasswordCodec); try { return PasswordMaskingUtil.resolveMask(useMask, value, classImpl); } catch (Exception e) { throw ActiveMQClientMessageBundle.BUNDLE.errordecodingPassword(e); } }
return getDefaultCodec();
@Override public String hash(String plainText) throws Exception { return PasswordMaskingUtil.wrap(codec.encode(plainText)); }
/** * This method deals with password masking and returns the password in its plain text form. * @param maskPassword : explicit mask flag. If it's true, the password is interpreted as * masked. If it is false, the password is interpreted as plain text. * if it is null, the password will be interpreted as masked if the * password is wrapped in ENC(), or as plain text otherwise. * @param password : the original value of password string * @param codecClass : the codec used to decode the password. Only when the password is interpreted * as masked will this codec be used. Ignored otherwise. * @return */ public static String resolveMask(Boolean maskPassword, String password, String codecClass) throws Exception { String plainText = password; if (maskPassword == null) { if (isEncMasked(password)) { //masked String bareMaskedPassword = unwrap(password); plainText = getCodec(codecClass).decode(bareMaskedPassword); } } else if (maskPassword) { plainText = getCodec(codecClass).decode(password); } return plainText; }
@Test public void testGetCodecUsingServiceLoader() throws Exception { SensitiveDataCodec<String> codec = PasswordMaskingUtil.getCodec(PasswordMaskingUtil.getDefaultCodec().getClass().getCanonicalName()); assertTrue(codec instanceof DefaultSensitiveStringCodec); }
private static boolean isEncoded(String storedPassword) { return storedPassword == null || (isEncMasked(storedPassword)); }
public static HashProcessor getHashProcessor(String storedPassword) throws Exception { if (!isEncoded(storedPassword)) { return LazyPlainTextProcessorHolder.INSTANCE; } 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; }
@Test(expected = IllegalArgumentException.class) public void testGetCodecUsingInvalidCodec() throws Exception { PasswordMaskingUtil.getCodec("codec doesn't exist"); } }
/** * This method deals with password masking and returns the password in its plain text form. * @param maskPassword : explicit mask flag. If it's true, the password is interpreted as * masked. If it is false, the password is interpreted as plain text. * if it is null, the password will be interpreted as masked if the * password is wrapped in ENC(), or as plain text otherwise. * @param password : the original value of password string * @param codecClass : the codec used to decode the password. Only when the password is interpreted * as masked will this codec be used. Ignored otherwise. * @return */ public static String resolveMask(Boolean maskPassword, String password, String codecClass) throws Exception { String plainText = password; if (maskPassword == null) { if (isEncMasked(password)) { //masked String bareMaskedPassword = unwrap(password); plainText = getCodec(codecClass).decode(bareMaskedPassword); } } else if (maskPassword) { plainText = getCodec(codecClass).decode(password); } return plainText; }
private static boolean isEncoded(String storedPassword) { return storedPassword == null || (isEncMasked(storedPassword)); }
public static HashProcessor getHashProcessor(String storedPassword) throws Exception { if (!isEncoded(storedPassword)) { return LazyPlainTextProcessorHolder.INSTANCE; } 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; }
/** * This method deals with password masking and returns the password in its plain text form. * @param maskPassword : explicit mask flag. If it's true, the password is interpreted as * masked. If it is false, the password is interpreted as plain text. * if it is null, the password will be interpreted as masked if the * password is wrapped in ENC(), or as plain text otherwise. * @param password : the original value of password string * @param codecClass : the codec used to decode the password. Only when the password is interpreted * as masked will this codec be used. Ignored otherwise. * @return */ public static String resolveMask(Boolean maskPassword, String password, String codecClass) throws Exception { String plainText = password; if (maskPassword == null) { if (isEncMasked(password)) { //masked String bareMaskedPassword = unwrap(password); plainText = getCodec(codecClass).decode(bareMaskedPassword); } } else if (maskPassword) { plainText = getCodec(codecClass).decode(password); } return plainText; }
private String getPassword(String password) throws Exception { return PasswordMaskingUtil.resolveMask(null, password, this.passwordCodec); } }
@Override public Object execute(ActionContext context) throws Exception { Map<String, String> params = new HashMap<>(); if (hash) { params.put(DefaultSensitiveStringCodec.ALGORITHM, DefaultSensitiveStringCodec.ONE_WAY); } if (key != null) { if (hash) { context.out.println("Option --key ignored in case of hashing"); } else { params.put(DefaultSensitiveStringCodec.BLOWFISH_KEY, key); } } codec = PasswordMaskingUtil.getDefaultCodec(); codec.init(params); String masked = codec.encode(password); context.out.println("result: " + masked); return masked; }
@Override public String hash(String plainText) throws Exception { return PasswordMaskingUtil.wrap(codec.encode(plainText)); }
private static boolean isEncoded(String storedPassword) { return storedPassword == null || (isEncMasked(storedPassword)); }
public static HashProcessor getHashProcessor(String storedPassword) throws Exception { if (!isEncoded(storedPassword)) { return LazyPlainTextProcessorHolder.INSTANCE; } 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; }
/** * This method deals with password masking and returns the password in its plain text form. * @param maskPassword : explicit mask flag. If it's true, the password is interpreted as * masked. If it is false, the password is interpreted as plain text. * if it is null, the password will be interpreted as masked if the * password is wrapped in ENC(), or as plain text otherwise. * @param password : the original value of password string * @param codecClass : the codec used to decode the password. Only when the password is interpreted * as masked will this codec be used. Ignored otherwise. * @return */ public static String resolveMask(Boolean maskPassword, String password, String codecClass) throws Exception { String plainText = password; if (maskPassword == null) { if (isEncMasked(password)) { //masked String bareMaskedPassword = unwrap(password); plainText = getCodec(codecClass).decode(bareMaskedPassword); } } else if (maskPassword) { plainText = getCodec(codecClass).decode(password); } return plainText; }
private String getPassword(String password) throws Exception { return PasswordMaskingUtil.resolveMask(null, password, this.passwordCodec); }
@Override public Object execute(ActionContext context) throws Exception { Map<String, String> params = new HashMap<>(); if (hash) { params.put(DefaultSensitiveStringCodec.ALGORITHM, DefaultSensitiveStringCodec.ONE_WAY); } if (key != null) { if (hash) { context.out.println("Option --key ignored in case of hashing"); } else { params.put(DefaultSensitiveStringCodec.BLOWFISH_KEY, key); } } codec = PasswordMaskingUtil.getDefaultCodec(); codec.init(params); String masked = codec.encode(password); context.out.println("result: " + masked); return masked; }