Search in sources :

Example 1 with SocketDefinition

use of won.auth.model.SocketDefinition 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 SocketDefinition

use of won.auth.model.SocketDefinition 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 SocketDefinition

use of won.auth.model.SocketDefinition 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 SocketDefinition

use of won.auth.model.SocketDefinition in project webofneeds by researchstudio-sat.

the class LDSocketAuthorizationSource method getSocketAuthorizations.

@Override
public Optional<SocketAuthorizations> getSocketAuthorizations(URI socketDefinitionURI) {
    Dataset data = linkedDataSource.getDataForPublicResource(socketDefinitionURI);
    if (data == null || data.isEmpty()) {
        throw new IllegalStateException(String.format("Could not load RDF for socket definition %s", socketDefinitionURI));
    }
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    Optional<SocketDefinition> sd = factory.accessor(data.getDefaultModel().getGraph()).getInstanceOfType(socketDefinitionURI.toString(), SocketDefinition.class);
    if (sd.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(new SocketAuthorizations(socketDefinitionURI, sd.get().getLocalAuths(), sd.get().getTargetAuths()));
}
Also used : Dataset(org.apache.jena.query.Dataset) SocketAuthorizations(won.auth.socket.SocketAuthorizations) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) SocketDefinition(won.auth.model.SocketDefinition)

Example 5 with SocketDefinition

use of won.auth.model.SocketDefinition in project webofneeds by researchstudio-sat.

the class SocketAuthorizationTest method testAddTargetAuth.

@Test
public void testAddTargetAuth() throws IOException {
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    SocketAclAlgorithms socketAclAlgos = new SocketAclAlgorithms();
    String folder = "addTargetAuth";
    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.addAuthorizationsForSocket(aclBefore, socket.getTargetAuths(), OWN_SOCKET1, TARGET_ATOM);
            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)

Aggregations

SocketDefinition (won.auth.model.SocketDefinition)7 Shacl2JavaInstanceFactory (won.shacl2java.Shacl2JavaInstanceFactory)7 Graph (org.apache.jena.graph.Graph)6 Test (org.junit.Test)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Resource (org.springframework.core.io.Resource)6 SocketAclAlgorithms (won.auth.socket.support.SocketAclAlgorithms)6 Dataset (org.apache.jena.query.Dataset)1 SocketAuthorizations (won.auth.socket.SocketAuthorizations)1