Search in sources :

Example 1 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class SocketAuthorizationTest method testRemoveLocalAuth.

@Test
public void testRemoveLocalAuth() throws IOException {
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    SocketAclAlgorithms socketAclAlgos = new SocketAclAlgorithms();
    String folder = "removeLocalAuth";
    for (Resource socketGraphResource : getInputs(folder)) {
        String baseName = getTestBaseName(socketGraphResource.getFilename());
        String testIdentifier = folder + "/" + baseName;
        logger.debug("running test {}", testIdentifier);
        Graph expectedResult = loadGraph(new ClassPathResource("/won/socket/" + folder + "/" + baseName + "-acl-after.ttl"));
        Graph aclBefore = loadGraph(new ClassPathResource("/won/socket/" + folder + "/" + baseName + "-acl-before.ttl"));
        Shacl2JavaInstanceFactory.Accessor ac = factory.accessor(loadGraph(socketGraphResource));
        Set<SocketDefinition> sockets = ac.getInstancesOfType(SocketDefinition.class);
        for (SocketDefinition socket : sockets) {
            Graph actualResult = socketAclAlgos.removeAuthorizationsForSocket(aclBefore, OWN_SOCKET1, TARGET_ATOM, false);
            assertIsomorphicGraphs(expectedResult, actualResult, testIdentifier);
        }
    }
}
Also used : Graph(org.apache.jena.graph.Graph) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SocketAclAlgorithms(won.auth.socket.support.SocketAclAlgorithms) ClassPathResource(org.springframework.core.io.ClassPathResource) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) SocketDefinition(won.auth.model.SocketDefinition) Test(org.junit.Test)

Example 2 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class SocketAuthorizationTest method testRemoveLocalAuthRemoveSocket.

@Test
public void testRemoveLocalAuthRemoveSocket() throws IOException {
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    SocketAclAlgorithms socketAclAlgos = new SocketAclAlgorithms();
    String folder = "removeLocalAuthRemoveSocket";
    for (Resource socketGraphResource : getInputs(folder)) {
        String baseName = getTestBaseName(socketGraphResource.getFilename());
        String testIdentifier = folder + "/" + baseName;
        logger.debug("running test {}", testIdentifier);
        Graph expectedResult = loadGraph(new ClassPathResource("/won/socket/" + folder + "/" + baseName + "-acl-after.ttl"));
        Graph aclBefore = loadGraph(new ClassPathResource("/won/socket/" + folder + "/" + baseName + "-acl-before.ttl"));
        Shacl2JavaInstanceFactory.Accessor ac = factory.accessor(loadGraph(socketGraphResource));
        Set<SocketDefinition> sockets = ac.getInstancesOfType(SocketDefinition.class);
        for (SocketDefinition socket : sockets) {
            Graph actualResult = socketAclAlgos.removeAuthorizationsForSocket(aclBefore, OWN_SOCKET1, TARGET_ATOM, true);
            assertIsomorphicGraphs(expectedResult, actualResult, testIdentifier);
        }
    }
}
Also used : Graph(org.apache.jena.graph.Graph) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SocketAclAlgorithms(won.auth.socket.support.SocketAclAlgorithms) ClassPathResource(org.springframework.core.io.ClassPathResource) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) SocketDefinition(won.auth.model.SocketDefinition) Test(org.junit.Test)

Example 3 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class SocketAuthorizationTest method testRemoveTargetAuth.

@Test
public void testRemoveTargetAuth() throws IOException {
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    SocketAclAlgorithms socketAclAlgos = new SocketAclAlgorithms();
    String folder = "removeTargetAuth";
    for (Resource socketGraphResource : getInputs(folder)) {
        String baseName = getTestBaseName(socketGraphResource.getFilename());
        String testIdentifier = folder + "/" + baseName;
        logger.debug("running test {}", testIdentifier);
        Graph expectedResult = loadGraph(new ClassPathResource("/won/socket/" + folder + "/" + baseName + "-acl-after.ttl"));
        Graph aclBefore = loadGraph(new ClassPathResource("/won/socket/" + folder + "/" + baseName + "-acl-before.ttl"));
        Shacl2JavaInstanceFactory.Accessor ac = factory.accessor(loadGraph(socketGraphResource));
        Set<SocketDefinition> sockets = ac.getInstancesOfType(SocketDefinition.class);
        for (SocketDefinition socket : sockets) {
            Graph actualResult = socketAclAlgos.removeAuthorizationsForSocket(aclBefore, OWN_SOCKET1, TARGET_ATOM, false);
            assertIsomorphicGraphs(expectedResult, actualResult, testIdentifier);
        }
    }
}
Also used : Graph(org.apache.jena.graph.Graph) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SocketAclAlgorithms(won.auth.socket.support.SocketAclAlgorithms) ClassPathResource(org.springframework.core.io.ClassPathResource) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) SocketDefinition(won.auth.model.SocketDefinition) Test(org.junit.Test)

Example 4 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class GrantedOperationsTest method testSet1.

@Test
public void testSet1() throws IOException {
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    Shapes atomDataShapes = loadShapes(atomDataShapesDef);
    ModelBasedConnectionTargetCheckEvaluator targetAtomChecker = new ModelBasedConnectionTargetCheckEvaluator(atomDataShapes, "won.auth.test.model");
    ModelBasedAtomNodeChecker atomNodeChecker = new ModelBasedAtomNodeChecker(atomDataShapes, "won.auth.test.model");
    String folder = "set1";
    for (Resource socketGraphResource : getInputs(folder)) {
        String baseName = getTestBaseName(socketGraphResource.getFilename());
        Graph inputGraph = loadGraph(socketGraphResource);
        String testIdentifier = folder + "/" + baseName;
        logger.debug("running test {}", testIdentifier);
        validateTestData(atomDataShapes, inputGraph, true, testIdentifier);
        validateTestData(AuthUtils.shapes(), inputGraph, true, testIdentifier);
        Shacl2JavaInstanceFactory.Accessor ac = factory.accessor(inputGraph);
        targetAtomChecker.loadData(inputGraph);
        atomNodeChecker.loadData(inputGraph);
        Set<OperationRequest> operationRequestSet = ac.getInstancesOfType(OperationRequest.class);
        if (operationRequestSet.size() > 1) {
            Assert.fail("only one operationRequest allowed per file");
        }
        OperationRequest operationRequest = operationRequestSet.stream().findFirst().get();
        setValidTokenExpiryDate(operationRequest);
        WonAclEvaluatorTestFactory evaluatorFactory = new WonAclEvaluatorTestFactory(targetAtomChecker, atomNodeChecker, null);
        evaluatorFactory.load(inputGraph);
        WonAclEvaluator evaluator = evaluatorFactory.create(false);
        Optional<AseRoot> grantedOperations = evaluator.getGrants(operationRequest);
        Graph actualResult = RdfOutput.toGraph(grantedOperations.get(), false);
        actualResult = new Difference(actualResult, AuthUtils.shapes().getGraph());
        Graph expectedResult = loadGraph(new ClassPathResource("/won/grantedOps/" + folder + "/" + baseName + "-expected.ttl"));
        assertIsomorphicGraphs(expectedResult, actualResult, testIdentifier);
    }
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) OperationRequest(won.auth.model.OperationRequest) Difference(org.apache.jena.graph.compose.Difference) ClassPathResource(org.springframework.core.io.ClassPathResource) Graph(org.apache.jena.graph.Graph) Shapes(org.apache.jena.shacl.Shapes) AseRoot(won.auth.model.AseRoot) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Test(org.junit.Test)

Example 5 with Shacl2JavaInstanceFactory

use of won.shacl2java.Shacl2JavaInstanceFactory in project webofneeds by researchstudio-sat.

the class SocketAclAlgorithms method removeAuthorizationsForSocket.

/**
 * In all authorizations found in the authGraph, remove <code>localSocket</code>
 * from the <code>requestedBy</code> entries if any of the following is true:
 * <ul>
 * <li><code>removeAsRequestingSocket == true</code></li>
 * <li>the <code>requestingAtom</code> is mentioned in the authorization.
 * </ul>
 * If an authorization has no <code>requestedBy</code> entries left, it is left
 * out in the result.
 *
 * @param authGraph the auth graph to manipulate
 * @param localSocket the URI of the atom's own socket
 * @param requestingAtom the URI of the atom that
 * @param removeAsRequestingSocket
 * @return
 */
public Graph removeAuthorizationsForSocket(Graph authGraph, URI localSocket, URI requestingAtom, boolean removeAsRequestingSocket) {
    Objects.requireNonNull(authGraph);
    Objects.requireNonNull(localSocket);
    Objects.requireNonNull(requestingAtom);
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    Set<Authorization> existingAuths = factory.accessor(authGraph).getInstancesOfType(Authorization.class);
    Set<Authorization> modifiedAuths = existingAuths.stream().map(existingAuth -> {
        if (removeAsRequestingSocket || mentionsAtom(existingAuth, requestingAtom)) {
            removeFromRequestedBy(existingAuth, localSocket);
        }
        return existingAuth;
    }).filter(existingAuth -> !existingAuth.getRequestedBys().isEmpty()).collect(Collectors.toSet());
    modifiedAuths.forEach(a -> a.detach());
    return new Difference(RdfOutput.toGraph(modifiedAuths), AuthUtils.shapes().getGraph());
}
Also used : won.auth.model(won.auth.model) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DeepEqualsUtils.same(won.shacl2java.runtime.DeepEqualsUtils.same) Difference(org.apache.jena.graph.compose.Difference) Collectors(java.util.stream.Collectors) Graph(org.apache.jena.graph.Graph) HashSet(java.util.HashSet) Objects(java.util.Objects) AuthUtils(won.auth.AuthUtils) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Optional(java.util.Optional) URI(java.net.URI) DeepEqualsUtils.sameContent(won.shacl2java.runtime.DeepEqualsUtils.sameContent) Difference(org.apache.jena.graph.compose.Difference) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory)

Aggregations

Shacl2JavaInstanceFactory (won.shacl2java.Shacl2JavaInstanceFactory)13 Test (org.junit.Test)11 Graph (org.apache.jena.graph.Graph)10 ClassPathResource (org.springframework.core.io.ClassPathResource)7 Resource (org.springframework.core.io.Resource)7 SocketDefinition (won.auth.model.SocketDefinition)7 SocketAclAlgorithms (won.auth.socket.support.SocketAclAlgorithms)6 URI (java.net.URI)3 HashSet (java.util.HashSet)3 Optional (java.util.Optional)3 Set (java.util.Set)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Dataset (org.apache.jena.query.Dataset)3 Shapes (org.apache.jena.shacl.Shapes)3 won.auth.model (won.auth.model)3 MethodHandles (java.lang.invoke.MethodHandles)2 Iterator (java.util.Iterator)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Difference (org.apache.jena.graph.compose.Difference)2