/** * Convert a protocol buffer Authorizations to a client Authorizations * * @param proto * @return the converted client Authorizations */ public static Authorizations toAuthorizations(ClientProtos.Authorizations proto) { if (proto == null) return null; return new Authorizations(proto.getLabelList()); }
@Override public List<String> getLabels(User user, Authorizations authorizations) { if (authorizations != null) { return authorizations.getLabels(); } return null; } }
.setReplicaId(3) .setACL("test_user", new Permission(Permission.Action.READ)) .setAuthorizations(new Authorizations("test_label")) .setPriority(3); assertEquals(get.getReplicaId(), scan.getReplicaId()); assertEquals(get.getACL(), scan.getACL()); assertEquals(get.getAuthorizations().getLabels(), scan.getAuthorizations().getLabels()); assertEquals(get.getPriority(), scan.getPriority());
Get get = new Get(ROW); get.setFilter(null); get.setAuthorizations(new Authorizations("foo")); get.setACL("u", new Permission(Permission.Action.READ)); get.setConsistency(Consistency.TIMELINE); assertTrue(get.getAuthorizations().toString().equals(copyGet.getAuthorizations().toString())); assertTrue(Bytes.equals(get.getACL(), copyGet.getACL())); assertEquals(get.getConsistency(), copyGet.getConsistency());
.setAsyncPrefetch(false) .setAttribute("test_key", Bytes.toBytes("test_value")) .setAuthorizations(new Authorizations("test_label")) .setBatch(10) .setCacheBlocks(false) assertEquals(scan.getAttributeSize(), scanCopy.getAttributeSize()); assertEquals(scan.getAttributesMap(), scanCopy.getAttributesMap()); assertEquals(scan.getAuthorizations().getLabels(), scanCopy.getAuthorizations().getLabels()); assertEquals(scan.getBatch(), scanCopy.getBatch()); assertEquals(scan.getCacheBlocks(), scanCopy.getCacheBlocks());
Get get = new Get(ROW); get.setFilter(null); get.setAuthorizations(new Authorizations("foo")); get.setACL("u", new Permission(Permission.Action.READ)); get.setConsistency(Consistency.TIMELINE); assertTrue(get.getAuthorizations().toString().equals(copyGet.getAuthorizations().toString())); assertTrue(Bytes.equals(get.getACL(), copyGet.getACL())); assertEquals(get.getConsistency(), copyGet.getConsistency());
@Override public Get beforeGet(long rowkeyBase, Get get) { get.setAuthorizations(new Authorizations( authorizations[(int) (rowkeyBase % authorizations.length)])); return get; } }
.setReplicaId(3) .setACL("test_user", new Permission(Permission.Action.READ)) .setAuthorizations(new Authorizations("test_label")) .setPriority(3); assertEquals(get.getReplicaId(), scan.getReplicaId()); assertEquals(get.getACL(), scan.getACL()); assertEquals(get.getAuthorizations().getLabels(), scan.getAuthorizations().getLabels()); assertEquals(get.getPriority(), scan.getPriority());
@Override public List<String> getLabels(User user, Authorizations authorizations) { if (authorizations == null || authorizations.getLabels() == null || authorizations.getLabels().isEmpty()) { String userName = user.getShortName(); Set<String> auths = new HashSet<>(); auths.addAll(this.labelsCache.getUserAuths(userName)); auths.addAll(this.labelsCache.getGroupAuths(user.getGroupNames())); return new ArrayList<>(auths); } return authorizations.getLabels(); }
@Test public void testSetAuthorizations() { Scan scan = new Scan(); try { scan.setAuthorizations(new Authorizations("\u002b|\u0029")); scan.setAuthorizations(new Authorizations("A", "B", "0123", "A0", "1A1", "_a")); scan.setAuthorizations(new Authorizations("A|B")); scan.setAuthorizations(new Authorizations("A&B")); scan.setAuthorizations(new Authorizations("!B")); scan.setAuthorizations(new Authorizations("A", "(A)")); scan.setAuthorizations(new Authorizations("A", "{A")); scan.setAuthorizations(new Authorizations(" ")); scan.setAuthorizations(new Authorizations(":B")); scan.setAuthorizations(new Authorizations("-B")); scan.setAuthorizations(new Authorizations(".B")); scan.setAuthorizations(new Authorizations("/B")); } catch (IllegalArgumentException e) { fail("should not throw exception"); } }
.setAsyncPrefetch(false) .setAttribute("test_key", Bytes.toBytes("test_value")) .setAuthorizations(new Authorizations("test_label")) .setBatch(10) .setCacheBlocks(false) assertEquals(scan.getAttributeSize(), scanCopy.getAttributeSize()); assertEquals(scan.getAttributesMap(), scanCopy.getAttributesMap()); assertEquals(scan.getAuthorizations().getLabels(), scanCopy.getAuthorizations().getLabels()); assertEquals(scan.getBatch(), scanCopy.getBatch()); assertEquals(scan.getCacheBlocks(), scanCopy.getCacheBlocks());
@Override public List<String> getLabels(User user, Authorizations authorizations) { if (authorizations != null) { if (labelToFilter == null) return authorizations.getLabels(); List<String> newAuths = new ArrayList<>(); for (String auth : authorizations.getLabels()) { if (!labelToFilter.equals(auth)) newAuths.add(auth); } return newAuths; } return null; } }
new Authorizations(SYSTEM_LABEL)); s.setFilter(filter); ArrayList<String> auths = new ArrayList<>();
@Override public List<String> getLabels(User user, Authorizations authorizations) { if (authorizations != null) { List<String> labels = authorizations.getLabels(); String userName = user.getShortName(); Set<String> auths = new HashSet<>(); auths.addAll(this.labelsCache.getUserAuths(userName)); auths.addAll(this.labelsCache.getGroupAuths(user.getGroupNames())); return dropLabelsNotInUserAuths(labels, new ArrayList<>(auths), userName); } return null; }
new Authorizations(SYSTEM_LABEL)); s.setFilter(filter); Set<String> auths = new HashSet<>();
/** * Create a protocol buffer Authorizations based on a client Authorizations. * * @param authorizations * @return a protocol buffer Authorizations */ public static ClientProtos.Authorizations toAuthorizations(Authorizations authorizations) { ClientProtos.Authorizations.Builder builder = ClientProtos.Authorizations.newBuilder(); for (String label : authorizations.getLabels()) { builder.addLabel(label); } return builder.build(); }
authorizations = new Authorizations(authLabels); } catch (Throwable t) { LOG.error(t.toString(), t);
if (authorizations != null) { TAuthorization tAuthorization = new TAuthorization(); tAuthorization.setLabels(authorizations.getLabels()); out.setAuthorizations(tAuthorization);
labels = Arrays.asList(conf.getStrings(EXPORT_VISIBILITY_LABELS)); if (!labels.isEmpty()) { s.setAuthorizations(new Authorizations(labels));
if (authorizations != null) { TAuthorization tAuthorization = new TAuthorization(); tAuthorization.setLabels(authorizations.getLabels()); out.setAuthorizations(tAuthorization);