use of won.auth.socket.SocketAuthorizations in project webofneeds by researchstudio-sat.
the class SocketAclService method addTargetSocketAcls.
/**
* Adds the target socket's <code>targetAuth</code> authorizations to the atom's
* acl, i.e., the authorizations the target socket of an atom's connection
* specifies for the atom's ACL.
* <p>
* This operation should be executed when establishing a connection.
* </p>
*/
public void addTargetSocketAcls(Connection con) {
URI atomUri = con.getAtomURI();
URI socketAclGraphUri = WonRelativeUriHelper.createSocketAclGraphURIForAtomURI(atomUri);
Atom atom = atomService.lockAtomRequired(atomUri);
Dataset atomDataset = atom.getDatatsetHolder().getDataset();
Graph socketAcls = atomDataset.containsNamedModel(socketAclGraphUri.toString()) ? atomDataset.getNamedModel(socketAclGraphUri.toString()).getGraph() : GraphFactory.createDefaultGraph();
Optional<URI> targetSocketType = socketService.getSocketType(con.getTargetSocketURI());
Optional<SocketAuthorizations> sa = socketAuthorizationSource.getSocketAuthorizations(targetSocketType.get());
if (sa.isPresent()) {
socketAcls = socketAuthorizationAclModifierAlgorithms.addAuthorizationsForSocket(socketAcls, sa.get().getTargetAuths(), con.getSocketURI(), con.getTargetAtomURI());
}
atomDataset.addNamedModel(socketAclGraphUri.toString(), ModelFactory.createModelForGraph(socketAcls));
}
use of won.auth.socket.SocketAuthorizations in project webofneeds by researchstudio-sat.
the class SocketAclService method addLocalSocketAcls.
/**
* Adds the socket's <code>localAuth</code> authorizations to the atom's acl,
* i.e., the authorizations that the socket of an atom specifies for the atom's
* ACL.
* <p>
* This operation should be executed when the socket is added to the atom, ie.
* upon atom creation or modification.
* </p>
*/
public void addLocalSocketAcls(URI atomURI, Set<Socket> socketEntities, Dataset atomDataset) {
URI socketAclGraphUri = WonRelativeUriHelper.createSocketAclGraphURIForAtomURI(atomURI);
Graph socketAcls = atomDataset.containsNamedModel(socketAclGraphUri.toString()) ? atomDataset.getNamedModel(socketAclGraphUri.toString()).getGraph() : GraphFactory.createDefaultGraph();
for (Socket socketEntity : socketEntities) {
Optional<SocketAuthorizations> sa = socketAuthorizationSource.getSocketAuthorizations(socketEntity.getTypeURI());
if (sa.isPresent()) {
socketAcls = socketAuthorizationAclModifierAlgorithms.addAuthorizationsForSocket(socketAcls, sa.get().getLocalAuths(), socketEntity.getSocketURI(), atomURI);
}
}
atomDataset.addNamedModel(socketAclGraphUri.toString(), ModelFactory.createModelForGraph(socketAcls));
}
use of won.auth.socket.SocketAuthorizations 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()));
}
Aggregations