Skip to content

Commit 1645738

Browse files
committed
Adds new constructor to ColumnVisibility
Adds a new constructor that supports an AccessExpression. Also adds deep copy method for existing ColumnVisibilities.
1 parent 712e50e commit 1645738

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
<groupId>io.opentelemetry</groupId>
8686
<artifactId>opentelemetry-context</artifactId>
8787
</dependency>
88+
<dependency>
89+
<groupId>org.apache.accumulo</groupId>
90+
<artifactId>accumulo-access</artifactId>
91+
</dependency>
8892
<dependency>
8993
<groupId>org.apache.accumulo</groupId>
9094
<artifactId>accumulo-start</artifactId>
@@ -274,6 +278,8 @@
274278
<allow>javax[.]security[.]auth[.]DestroyFailedException</allow>
275279
<!-- allow questionable Hadoop exceptions for mapreduce -->
276280
<allow>org[.]apache[.]hadoop[.]mapred[.](FileAlreadyExistsException|InvalidJobConfException)</allow>
281+
<!-- allow the following types from the visibility API -->
282+
<allow>org[.]apache[.]accumulo[.]access[.].*</allow>
277283
</allows>
278284
</configuration>
279285
</execution>

core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.List;
2929
import java.util.TreeSet;
3030

31+
import org.apache.accumulo.access.AccessExpression;
3132
import org.apache.accumulo.core.data.ArrayByteSequence;
3233
import org.apache.accumulo.core.data.ByteSequence;
3334
import org.apache.accumulo.core.util.BadArgumentException;
@@ -133,6 +134,24 @@ public void add(Node child) {
133134
children.add(child);
134135
}
135136

137+
/**
138+
* Creates a new node by performing a deep copy of an existing node object
139+
*
140+
* @param node Node object
141+
* @since 2.1.4
142+
*/
143+
private Node(Node node) {
144+
List<Node> childrenNew =
145+
node.children.isEmpty() ? EMPTY : new ArrayList<>(node.children.size());
146+
for (Node child : node.children) {
147+
childrenNew.add(new Node(child));
148+
}
149+
this.type = node.type;
150+
this.start = node.start;
151+
this.end = node.end;
152+
this.children = childrenNew;
153+
}
154+
136155
public NodeType getType() {
137156
return type;
138157
}
@@ -505,6 +524,31 @@ public ColumnVisibility(byte[] expression) {
505524
validate(expression);
506525
}
507526

527+
/**
528+
* Creates a column visibility for a Mutation from an AccessExpression.
529+
*
530+
* @param expression visibility expression, encoded as UTF-8 bytes
531+
* @see #ColumnVisibility(String)
532+
* @since 2.1.4
533+
*/
534+
public ColumnVisibility(AccessExpression expression) {
535+
// AccessExpression is a validated immutable object, so no need to re validate
536+
this.expression = expression.getExpression().getBytes(UTF_8);
537+
}
538+
539+
/**
540+
* Creates a new column visibility by performing a deep copy of an existing column visibility
541+
* object
542+
*
543+
* @param visibility ColumnVisibility object
544+
* @since 2.1.4
545+
*/
546+
public ColumnVisibility(ColumnVisibility visibility) {
547+
byte[] incomingExpression = visibility.expression;
548+
this.expression = Arrays.copyOf(incomingExpression, incomingExpression.length);
549+
this.node = new Node(visibility.node);
550+
}
551+
508552
@Override
509553
public String toString() {
510554
return "[" + new String(expression, UTF_8) + "]";

core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.apache.accumulo.core.security.ColumnVisibility.quote;
2323
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2424
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertNotSame;
2526
import static org.junit.jupiter.api.Assertions.assertThrows;
2627
import static org.junit.jupiter.api.Assertions.assertTrue;
2728

@@ -238,6 +239,15 @@ public void testParseTreesOrdering() {
238239
assertTrue(flat.indexOf('b') < flat.indexOf('a'), "shortest children sort first");
239240
}
240241

242+
@Test
243+
public void testDeepCopy() {
244+
ColumnVisibility cv1 = new ColumnVisibility("(b&c&d)|((a|m)&y&z)|(e&f)");
245+
ColumnVisibility cv2 = new ColumnVisibility(cv1);
246+
assertNotSame(cv1.getExpression(), cv2.getExpression());
247+
assertNotSame(cv1.getParseTree(), cv2.getParseTree());
248+
assertEquals(cv1.toString(), cv2.toString());
249+
}
250+
241251
private Node parse(String s) {
242252
ColumnVisibility v = new ColumnVisibility(s);
243253
return v.getParseTree();

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<surefire.reuseForks>true</surefire.reuseForks>
147147
<unitTestMemSize>-Xmx1G</unitTestMemSize>
148148
<!-- dependency and plugin versions managed with properties -->
149+
<version.accumulo-access>1.0.0-SNAPSHOT</version.accumulo-access>
149150
<version.auto-service>1.1.1</version.auto-service>
150151
<version.bouncycastle>1.78.1</version.bouncycastle>
151152
<version.curator>5.5.0</version.curator>
@@ -328,6 +329,11 @@
328329
<artifactId>junit</artifactId>
329330
<version>4.13.2</version>
330331
</dependency>
332+
<dependency>
333+
<groupId>org.apache.accumulo</groupId>
334+
<artifactId>accumulo-access</artifactId>
335+
<version>${version.accumulo-access}</version>
336+
</dependency>
331337
<dependency>
332338
<groupId>org.apache.accumulo</groupId>
333339
<artifactId>accumulo-compaction-coordinator</artifactId>

0 commit comments

Comments
 (0)