You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/05/29 17:37:40 UTC
[GitHub] [jena] afs commented on a change in pull request #748: JENA-1901 Provide default implementations for some of SecurityEvaluaor's methods
afs commented on a change in pull request #748:
URL: https://github.com/apache/jena/pull/748#discussion_r432635881
##########
File path: jena-permissions/src/test/java/org/apache/jena/permissions/SecurityEvaluatorTest.java
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.permissions;
+
+import static org.junit.Assert.*;
+
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.permissions.SecurityEvaluator.Action;
+import org.apache.jena.shared.AuthenticationRequiredException;
+import org.junit.Test;
+
+import java.util.EnumSet;
+
+public class SecurityEvaluatorTest {
+ private static final Object PRINCIPAL = null;
+ private static final Node GRAPH = null;
+ private static final Triple TRIPLE = null;
+ private static final EnumSet<Action> ALLOWED_ACTIONS = EnumSet.of(Action.Create, Action.Delete);
+ private static final EnumSet<Action> DISALLOWED_ACTIONS = EnumSet.complementOf(ALLOWED_ACTIONS);
+ public static final EnumSet<Action> ALL_ACTIONS = EnumSet.noneOf(Action.class);
+
+
+ private final SecurityEvaluator evaluator = new SecurityEvaluator() {
+
+ @Override
+ public boolean evaluate(Object principal, Action action, Node graphIRI) throws AuthenticationRequiredException {
+ return ALLOWED_ACTIONS.contains(action);
+ }
+
+ @Override
+ public boolean evaluate(Object principal, Action action, Node graphIRI, Triple triple) throws AuthenticationRequiredException {
+ return ALLOWED_ACTIONS.contains(action);
+ }
+
+ @Override
+ public Object getPrincipal() {
+ return null;
+ }
+
+ @Override
+ public boolean isPrincipalAuthenticated(Object principal) {
+ return false;
+ }
+ };
+
+ @Test
+ public void testAllLogicForGraphOperations() {
+ assertTrue(evaluator.evaluate(PRINCIPAL, ALL_ACTIONS, GRAPH));
+ assertTrue(evaluator.evaluate(PRINCIPAL, ALLOWED_ACTIONS, GRAPH));
+ assertFalse(evaluator.evaluate(PRINCIPAL, DISALLOWED_ACTIONS, GRAPH));
+ assertFalse(evaluator.evaluate(PRINCIPAL, EnumSet.allOf(Action.class), GRAPH));
+ }
+
+
+ @Test
+ public void testAnyLogicForGraphOperations() {
+ assertFalse(evaluator.evaluateAny(PRINCIPAL, ALL_ACTIONS, GRAPH));
+ assertTrue(evaluator.evaluateAny(PRINCIPAL, ALLOWED_ACTIONS, GRAPH));
+ assertFalse(evaluator.evaluateAny(PRINCIPAL, DISALLOWED_ACTIONS, GRAPH));
+ assertTrue(evaluator.evaluateAny(PRINCIPAL, EnumSet.allOf(Action.class), GRAPH));
+ }
+
+ public void testAllLogicForTripleOperations() {
+ assertTrue(evaluator.evaluate(PRINCIPAL, ALL_ACTIONS, GRAPH, TRIPLE));
+ assertTrue(evaluator.evaluate(PRINCIPAL, ALLOWED_ACTIONS, GRAPH, TRIPLE));
+ assertFalse(evaluator.evaluate(PRINCIPAL, DISALLOWED_ACTIONS, GRAPH, TRIPLE));
+ assertFalse(evaluator.evaluate(PRINCIPAL, EnumSet.allOf(Action.class), GRAPH, TRIPLE));
+ }
+
+
+ @Test
+ public void testAnyLogicForTripleOperations() {
+ assertFalse(evaluator.evaluateAny(PRINCIPAL, ALL_ACTIONS, GRAPH, TRIPLE));
+ assertTrue(evaluator.evaluateAny(PRINCIPAL, ALLOWED_ACTIONS, GRAPH, TRIPLE));
+ assertFalse(evaluator.evaluateAny(PRINCIPAL, DISALLOWED_ACTIONS, GRAPH, TRIPLE));
+ assertTrue(evaluator.evaluateAny(PRINCIPAL, EnumSet.allOf(Action.class), GRAPH, TRIPLE));
+ }
+}
Review comment:
Trivial: missing final newline.
##########
File path: jena-permissions/src/main/java/org/apache/jena/permissions/SecurityEvaluator.java
##########
@@ -213,7 +210,7 @@
* @throws AuthenticationRequiredException
* if user is not authenticated and is required to be.
*/
- public boolean evaluate(Object principal, Action action, Node graphIRI)
+ boolean evaluate(Object principal, Action action, Node graphIRI)
Review comment:
Minor: "public" is used elsewhere on interface methods.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org