|
4 | 4 |
|
5 | 5 | Another one of Gaffer's key features is visibility filtering, fine grained data access and query execution controls.
|
6 | 6 |
|
7 |
| -The code for this example is [Visibilities](https://github.com/gchq/gaffer-doc/blob/v1docs/src/main/java/uk/gov/gchq/gaffer/doc/dev/walkthrough/Visibilities.java) |
| 7 | +[Javadoc](https://gchq.github.io/Gaffer/uk/gov/gchq/gaffer/commonutil/elementvisibilityutil/VisibilityEvaluator.html) |
8 | 8 |
|
9 | 9 | In this example we'll add a visibility property to our edges so that we can control access to them.
|
10 | 10 |
|
@@ -97,55 +97,86 @@ We've defined a new "visibility" type in our Types, which is a Java String and m
|
97 | 97 | }
|
98 | 98 |
|
99 | 99 | ```
|
| 100 | +### Adding elements with visibility |
100 | 101 |
|
101 |
| -We have updated the generator to add the visibility label as a new property (a Java String) on the edges: |
| 102 | +??? example "Adding a new edges with visibilities" |
102 | 103 |
|
103 |
| -```java |
104 |
| -public class RoadAndRoadUseWithSecurityElementGenerator implements OneToManyElementGenerator<String> { |
105 |
| - @Override |
106 |
| - public Iterable<Element> _apply(final String line) { |
107 |
| - final String[] t = line.split(","); |
108 |
| - |
109 |
| - final String road = t[0]; |
110 |
| - final String junctionA = t[1]; |
111 |
| - final String junctionB = t[2]; |
112 |
| - |
113 |
| - final int junctionAInt = Integer.parseInt(junctionA); |
114 |
| - final int junctionBInt = Integer.parseInt(junctionA); |
115 |
| - final String visibility; |
116 |
| - if (junctionAInt >= 20 || junctionBInt >= 20) { |
117 |
| - visibility = "private"; |
118 |
| - } else { |
119 |
| - visibility = "public"; |
120 |
| - } |
| 104 | + === "Java" |
121 | 105 |
|
122 |
| - return Arrays.asList( |
123 |
| - new Edge.Builder() |
| 106 | + ```java |
| 107 | + new AddElements.Builder() |
| 108 | + .input(new Edge.Builder() |
124 | 109 | .group("RoadHasJunction")
|
125 |
| - .source(road) |
126 |
| - .dest(junctionA) |
127 |
| - .directed(true) |
| 110 | + .source("1").dest("2").directed(true) |
| 111 | + .property("count", 1) |
| 112 | + .property("visibility", "private") |
128 | 113 | .build(),
|
129 |
| - |
130 |
| - new Edge.Builder() |
| 114 | + new Edge.Builder() |
131 | 115 | .group("RoadHasJunction")
|
132 |
| - .source(road) |
133 |
| - .dest(junctionB) |
134 |
| - .directed(true) |
135 |
| - .build(), |
| 116 | + .source("1").dest("2").directed(true) |
| 117 | + .property("count", 2) |
| 118 | + .property("visibility", "public") |
| 119 | + .build()) |
| 120 | + .build(); |
| 121 | + ``` |
| 122 | + |
| 123 | + === "JSON" |
| 124 | + |
| 125 | + ``` JSON |
| 126 | + { |
| 127 | + "class" : "AddElements", |
| 128 | + "input" : [ { |
| 129 | + "class" : "Edge", |
| 130 | + "group" : "RoadHasJunction", |
| 131 | + "source" : "1", |
| 132 | + "destination" : "2", |
| 133 | + "directed" : true, |
| 134 | + "properties" : { |
| 135 | + "count" : 1, |
| 136 | + "visibility": "private" |
| 137 | + } |
| 138 | + }, |
| 139 | + { |
| 140 | + "class" : "Edge", |
| 141 | + "group" : "RoadHasJunction", |
| 142 | + "source" : "1", |
| 143 | + "destination" : "2", |
| 144 | + "directed" : true, |
| 145 | + "properties" : { |
| 146 | + "count" : 2, |
| 147 | + "visibility": "public" |
| 148 | + } |
| 149 | + } ], |
| 150 | + "skipInvalidElements" : false, |
| 151 | + "validate" : true |
| 152 | + } |
| 153 | + ``` |
| 154 | + |
| 155 | + === "Python" |
| 156 | + |
| 157 | + ``` Python |
| 158 | + g.AddElements( |
| 159 | + input=[ |
| 160 | + g.Edge( |
| 161 | + group="RoadHasJunction", |
| 162 | + properties={"count": 1, "visibility": "private"}, |
| 163 | + source="1", |
| 164 | + destination="2", |
| 165 | + directed=True |
| 166 | + ), |
| 167 | + g.Edge( |
| 168 | + group="RoadHasJunction", |
| 169 | + properties={"count": 2, "visibility": "public"}, |
| 170 | + source="1", |
| 171 | + destination="2", |
| 172 | + directed=True |
| 173 | + ) |
| 174 | + ], |
| 175 | + skip_invalid_elements=False, |
| 176 | + validate=True |
| 177 | + ) |
| 178 | + ``` |
136 | 179 |
|
137 |
| - new Edge.Builder() |
138 |
| - .group("RoadUse") |
139 |
| - .source(junctionA) |
140 |
| - .dest(junctionB) |
141 |
| - .directed(true) |
142 |
| - .property("count", 1L) |
143 |
| - .property("visibility", visibility) |
144 |
| - .build() |
145 |
| - ); |
146 |
| - } |
147 |
| -} |
148 |
| -``` |
149 | 180 | After creating a Graph and adding our edges to it we run a simple query to get back all RoadUse edges containing vertex "20"... and we get nothing back. This is because the user we ran the query as was not allowed to see edges with a visibility of public or private, so no edges were returned.
|
150 | 181 |
|
151 | 182 | We can create a user that can see public edges only (and not private edges) and then run the query as this user.
|
|
0 commit comments