@Override public char[] transform(final char[] passwordData) { byte[] passwordBytes = Strings.decodeBase64(new String(passwordData)); char[] password = new char[passwordBytes.length]; for (int i = 0; i < passwordBytes.length; i++) { password[i] = (char) passwordBytes[i]; } return password; } };
public static final String join(String sep, Object[] items) { return join(sep, Arrays.asList(items)); }
public static final String expand(String input) { return expand(input, SYSTEM_RESOLVER); }
m.appendReplacement(result, Matcher.quoteReplacement(resolve(var, resolver, stack, failOnUnresolved)));
public final void messageTransfer(String destination, MessageAcceptMode acceptMode, MessageAcquireMode acquireMode, Header header, String body, Option ... _options) { messageTransfer(destination, acceptMode, acquireMode, header, toUTF8(body), _options); }
public static final String expand(String input, Resolver resolver) { return expand(input, resolver, new Stack<String>(),true); } public static final String expand(String input, boolean failOnUnresolved, Resolver... resolvers)
@Override public char[] transform(final char[] passwordData) { byte[] passwordBytes = Strings.decodeBase64(new String(passwordData)); char[] password = new char[passwordBytes.length * 2]; for (int i = 0; i < passwordBytes.length; i++) { password[2 * i] = HEX_CHARACTERS[(((int) passwordBytes[i]) & 0xf0) >> 4]; password[(2 * i) + 1] = HEX_CHARACTERS[(((int) passwordBytes[i]) & 0x0f)]; } return password; } };
static String interpolate(Model model, String value) { return Strings.expand(value, false, JSON_SUBSTITUTION_RESOLVER, Strings.JAVA_SYS_PROPS_RESOLVER, Strings.ENV_VARS_RESOLVER, model.getTypeRegistry().getDefaultContextResolver()); }
public String getPath(final ConfiguredObject<?> object) { final List<String> pathAsList = getPathAsList(object); ListIterator<String> iter = pathAsList.listIterator(); while(iter.hasNext()) { String element = iter.next(); iter.set(element.replaceAll("([\\\\/])", "\\\\$1")); } return Strings.join("/", pathAsList); }
@Override byte[] convert(final Object value, final ConfiguredObject object) { if(value instanceof byte[]) { return (byte[]) value; } else if(value == null) { return null; } else if(value instanceof String) { String interpolated = AbstractConfiguredObject.interpolate(object, (String) value); return Strings.decodeBase64(interpolated); } else { throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a byte[]"); } } };
private URI getUriForAddressSpace(URI uri, final NamedAddressSpace addressSpace) { try { String vhostName = URLEncoder.encode(addressSpace == null ? "" : addressSpace.getName(), UTF_8.name()); final Strings.MapResolver virtualhostResolver = new Strings.MapResolver(Collections.singletonMap("virtualhost", vhostName)); String substitutedURI = Strings.expand(uri.toString(), false, virtualhostResolver); uri = new URI(substitutedURI); } catch (UnsupportedEncodingException | URISyntaxException e) { LOGGER.error("Error when attempting to build URI from address space: ", e); } return uri; }
private void decodeCertificate() { byte[] certificateEncoded = Strings.decodeBase64((String) getActualAttributes().get(CERTIFICATE)); try(ByteArrayInputStream input = new ByteArrayInputStream(certificateEncoded)) { CertificateFactory cf = CertificateFactory.getInstance("X.509"); _x509Certificate = (X509Certificate) cf.generateCertificate(input); } catch (CertificateException | IOException e) { throw new IllegalConfigurationException("Could not decode certificate", e); } }
try return expand(result, resolver, stack, failOnUnresolved);
if(_base64) _content = Strings.decodeBase64(parts[1]);
private void reportStatisticsForObject(final ConfiguredObject<?> object) { final String statisticsReportPatternContextKey = String.format("qpid.%s.statisticsReportPattern", object.getCategoryClass().getSimpleName().toLowerCase()); if (object.getContextKeys(false).contains(statisticsReportPatternContextKey)) { String reportPattern = object.getContextValue(String.class, statisticsReportPatternContextKey); String formattedStatistics = Strings.expand(reportPattern, false, new FormattingStatisticsResolver(object)); String loggerName = String.format("qpid.statistics.%s", object.getCategoryClass().getSimpleName()); Logger logger = LoggerFactory.getLogger(loggerName); logger.info("Statistics: {}", formattedStatistics); } } }
HashedUser(String[] data, AuthenticationProvider<?> authenticationProvider) { if (data.length != 2) { throw new IllegalArgumentException("User Data should be length 2, username, password"); } _name = data[0]; byte[] encoded_password; try { encoded_password = data[1].getBytes(Base64MD5PasswordFilePrincipalDatabase.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { throw new ServerScopedRuntimeException("MD5 encoding not supported, even though the Java standard requires it",e); } _encodedPassword = encoded_password; byte[] decoded = Strings.decodeBase64(data[1]); _password = new char[decoded.length]; int index = 0; for (byte c : decoded) { _password[index++] = (char) c; } _authenticationProvider = authenticationProvider; }
static String interpolate(ConfiguredObject<?> object, String value) { if(object == null) { return value; } else { Map<String, String> inheritedContext = new HashMap<String, String>(); generateInheritedContext(object.getModel(), object, inheritedContext); return Strings.expand(value, false, JSON_SUBSTITUTION_RESOLVER, getOwnAttributeResolver(object), getAncestorAttributeResolver(object), new Strings.MapResolver(inheritedContext), Strings.JAVA_SYS_PROPS_RESOLVER, Strings.ENV_VARS_RESOLVER, object.getModel().getTypeRegistry().getDefaultContextResolver()); } }
public static PrivateKey readPrivateKey(InputStream input) throws IOException, GeneralSecurityException { byte[] content = toByteArray(input); String contentAsString = new String(content, StandardCharsets.US_ASCII); if(contentAsString.contains("-----BEGIN ") && contentAsString.contains(" PRIVATE KEY-----")) { BufferedReader lineReader = new BufferedReader(new StringReader(contentAsString)); String line; do { line = lineReader.readLine(); } while(line != null && !(line.startsWith("-----BEGIN ") && line.endsWith(" PRIVATE KEY-----"))); if(line != null) { StringBuilder keyBuilder = new StringBuilder(); while((line = lineReader.readLine()) != null) { if(line.startsWith("-----END ") && line.endsWith(" PRIVATE KEY-----")) { break; } keyBuilder.append(line); } content = Strings.decodeBase64(keyBuilder.toString()); } } return readPrivateKey(content, "RSA"); }
@Override public String decrypt(final String encrypted) { if(!isValidBase64(encrypted)) { throw new IllegalArgumentException("Encrypted value is not valid Base 64 data: '" + encrypted + "'"); } byte[] encryptedBytes = Strings.decodeBase64(encrypted); try { Cipher cipher = Cipher.getInstance(CIPHER_NAME); IvParameterSpec ivParameterSpec = new IvParameterSpec(encryptedBytes, 0, AES_INITIALIZATION_VECTOR_LENGTH); cipher.init(Cipher.DECRYPT_MODE, _secretKey, ivParameterSpec); return new String(readFromCipherStream(encryptedBytes, AES_INITIALIZATION_VECTOR_LENGTH, encryptedBytes.length - AES_INITIALIZATION_VECTOR_LENGTH, cipher), StandardCharsets.UTF_8); } catch (IOException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) { throw new IllegalArgumentException("Unable to decrypt secret", e); } }