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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
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());
}
Aggregations