Search in sources :

Example 1 with SocketAuthorizations

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));
}
Also used : Graph(org.apache.jena.graph.Graph) Dataset(org.apache.jena.query.Dataset) SocketAuthorizations(won.auth.socket.SocketAuthorizations) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 2 with SocketAuthorizations

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));
}
Also used : Graph(org.apache.jena.graph.Graph) SocketAuthorizations(won.auth.socket.SocketAuthorizations) URI(java.net.URI) Socket(won.protocol.model.Socket)

Example 3 with SocketAuthorizations

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()));
}
Also used : Dataset(org.apache.jena.query.Dataset) SocketAuthorizations(won.auth.socket.SocketAuthorizations) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) SocketDefinition(won.auth.model.SocketDefinition)

Aggregations

SocketAuthorizations (won.auth.socket.SocketAuthorizations)3 URI (java.net.URI)2 Graph (org.apache.jena.graph.Graph)2 Dataset (org.apache.jena.query.Dataset)2 SocketDefinition (won.auth.model.SocketDefinition)1 Atom (won.protocol.model.Atom)1 Socket (won.protocol.model.Socket)1 Shacl2JavaInstanceFactory (won.shacl2java.Shacl2JavaInstanceFactory)1