/** * @return encoded flags */ protected static String encodeBooleans(boolean[] flags) { byte[] bytes = new byte[flags.length]; for (int i = 0; i < flags.length; i++) { if (flags[i]) bytes[i] = 1; else bytes[i] = 0; } return Base64.encodeBase64String(bytes); }
public static byte[] decodeBase64FileName(String node) { while (node.length() % 4 != 0) node += "="; /* decode transparently handles URLSafe encodings */ return Base64.decodeBase64(node.getBytes(UTF_8)); }
ByteArrayContainer(byte[] ba) { asUtf8 = new String(ba, StandardCharsets.UTF_8); asBase64 = Base64.encodeBase64URLSafeString(ba); } }
return new SystemToken(Base64.encodeBase64(bytes.toByteArray()));
static void runTest(Connector c, MiniAccumuloClusterImpl cluster) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MutationsRejectedException, IOException, InterruptedException, NoSuchAlgorithmException { c.tableOperations().create(tablename); BatchWriter bw = c.createBatchWriter(tablename, new BatchWriterConfig()); for (int i = 0; i < 10; i++) { Mutation m = new Mutation("" + i); m.put(input_cf, input_cq, "row" + i); bw.addMutation(m); } bw.close(); Process hash = cluster.exec(RowHash.class, Collections.singletonList(hadoopTmpDirArg), "-i", c.getInstance().getInstanceName(), "-z", c.getInstance().getZooKeepers(), "-u", "root", "-p", ROOT_PASSWORD, "-t", tablename, "--column", input_cfcq); assertEquals(0, hash.waitFor()); Scanner s = c.createScanner(tablename, Authorizations.EMPTY); s.fetchColumn(new Text(input_cf), new Text(output_cq)); int i = 0; for (Entry<Key,Value> entry : s) { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] check = Base64.encodeBase64(md.digest(("row" + i).getBytes())); assertEquals(entry.getValue().toString(), new String(check)); i++; } } }
/** * @return encoded columns */ protected static String encodeColumns(Text[] columns) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < columns.length; i++) { sb.append(Base64.encodeBase64String(TextUtil.getBytes(columns[i]))); sb.append('\n'); } return sb.toString(); }
protected static Text[] decodeColumns(String columns) { String[] columnStrings = columns.split("\n"); Text[] columnTexts = new Text[columnStrings.length]; for (int i = 0; i < columnStrings.length; i++) { columnTexts[i] = new Text(Base64.decodeBase64(columnStrings[i].getBytes(UTF_8))); } return columnTexts; }
public static String encodeAsBase64FileName(Text data) { String encodedRow = Base64.encodeBase64URLSafeString(TextUtil.getBytes(data)); int index = encodedRow.length() - 1; while (index >= 0 && encodedRow.charAt(index) == '=') index--; encodedRow = encodedRow.substring(0, index + 1); return encodedRow; }
@Override public boolean hasCachedTablePermission(String user, String table, TablePermission permission) throws AccumuloSecurityException, TableNotFoundException { return zkPermissionHandler.hasCachedTablePermission( Base64.encodeBase64String(user.getBytes(UTF_8)), table, permission); }
/** * @return decoded flags */ protected static boolean[] decodeBooleans(String flags) { // return null of there were no flags if (flags == null) return null; byte[] bytes = Base64.decodeBase64(flags.getBytes(UTF_8)); boolean[] bFlags = new boolean[bytes.length]; for (int i = 0; i < bytes.length; i++) { if (bytes[i] == 1) bFlags[i] = true; else bFlags[i] = false; } return bFlags; }
private static String toBase64(Writable writable) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { writable.write(dos); dos.close(); } catch (IOException e) { throw new RuntimeException(e); } return Base64.encodeBase64String(baos.toByteArray()); }
@Override public Set<String> listUsers() throws AccumuloSecurityException { Set<String> base64Users = zkAuthenticator.listUsers(); Set<String> readableUsers = new HashSet<>(); for (String base64User : base64Users) { readableUsers.add(new String(Base64.decodeBase64(base64User), UTF_8)); } return readableUsers; }
/** * Returns a serialized form of these authorizations. Convert the returned string to UTF-8 bytes * to deserialize with {@link #Authorizations(byte[])}. * * @return serialized form of authorizations */ public String serialize() { StringBuilder sb = new StringBuilder(HEADER); String sep = ""; for (byte[] auth : authsList) { sb.append(sep); sep = ","; sb.append(Base64.encodeBase64String(auth)); } return sb.toString(); } }
public static Set<Pair<Text,Text>> deserializeFetchedColumns(Collection<String> serialized) { Set<Pair<Text,Text>> columns = new HashSet<>(); if (null == serialized) { return columns; } for (String col : serialized) { int idx = col.indexOf(":"); Text cf = new Text(idx < 0 ? Base64.decodeBase64(col.getBytes(UTF_8)) : Base64.decodeBase64(col.substring(0, idx).getBytes(UTF_8))); Text cq = idx < 0 ? null : new Text(Base64.decodeBase64(col.substring(idx + 1).getBytes(UTF_8))); columns.add(new Pair<>(cf, cq)); } return columns; }
@Override public void initializeSecurity(TCredentials credentials, String rootuser) throws AccumuloSecurityException, ThriftSecurityException { zkPermissionHandler.initializeSecurity(credentials, Base64.encodeBase64String(rootuser.getBytes(UTF_8))); }
private static <T extends Writable> T fromBase64(T writable, String enc) { ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(enc)); DataInputStream dis = new DataInputStream(bais); try { writable.readFields(dis); } catch (IOException e) { throw new RuntimeException(e); } return writable; }
@Override public boolean hasTablePermission(String user, String table, TablePermission permission) throws AccumuloSecurityException, TableNotFoundException { return zkPermissionHandler.hasTablePermission(Base64.encodeBase64String(user.getBytes(UTF_8)), table, permission); }
/** * Converts the serialized form to an instance of {@link Credentials}. The original serialized * form will not be affected. * * @param serializedForm * serialized form of credentials * @return deserialized credentials */ public static final Credentials deserialize(String serializedForm) { String[] split = serializedForm.split(":", 3); String principal = split[0].equals("-") ? null : new String(Base64.decodeBase64(split[0]), UTF_8); String tokenType = split[1].equals("-") ? null : new String(Base64.decodeBase64(split[1]), UTF_8); AuthenticationToken token = null; if (!split[2].equals("-")) { byte[] tokenBytes = Base64.decodeBase64(split[2]); token = AuthenticationTokenSerializer.deserialize(tokenType, tokenBytes); } return new Credentials(principal, token); }
@Override public void revokeSystemPermission(String user, SystemPermission permission) throws AccumuloSecurityException { zkPermissionHandler.revokeSystemPermission(Base64.encodeBase64String(user.getBytes(UTF_8)), permission); }
line = file.nextLine(); if (!line.isEmpty()) { result.add(decode ? new Text(Base64.decodeBase64(line.getBytes(UTF_8))) : new Text(line));