Search in sources :

Example 21 with Atom

use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.

the class DeactivateAtomMessageFromSystemReactionProcessor method process.

public void process(final Exchange exchange) throws Exception {
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI recipientAtomURI = wonMessage.getRecipientAtomURI();
    logger.debug("DEACTIVATING atom. atomURI:{}", recipientAtomURI);
    if (recipientAtomURI == null)
        throw new WonMessageProcessingException("recipientAtomURI is not set");
    Atom atom = atomService.getAtomRequired(recipientAtomURI);
    matcherProtocolMatcherClient.atomDeactivated(atom.getAtomURI(), wonMessage);
    // close all connections
    Collection<Connection> conns = connectionRepository.findByAtomURIAndNotStateForUpdate(atom.getAtomURI(), ConnectionState.CLOSED);
    for (Connection con : conns) {
        entityManager.refresh(con);
        closeConnection(atom, con);
    }
}
Also used : WonMessageProcessingException(won.protocol.exception.WonMessageProcessingException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 22 with Atom

use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.

the class DeleteAtomMessageFromOwnerProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    Optional<Atom> atom = atomService.getAtom(wonMessage.getAtomURI());
    if (!atom.isPresent()) {
        throw new NoSuchAtomException(wonMessage.getAtomURI());
    }
    if (atom.get().getState() == AtomState.DELETED) {
        throw new IllegalMessageForAtomStateException(atom.get().getAtomURI(), "DELETE", atom.get().getState());
    }
// the rest of the delete tasks are done in the reaction processor
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) NoSuchAtomException(won.protocol.exception.NoSuchAtomException) WonMessage(won.protocol.message.WonMessage) Atom(won.protocol.model.Atom) IllegalMessageForAtomStateException(won.protocol.exception.IllegalMessageForAtomStateException)

Example 23 with Atom

use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.

the class OwnerPersistenceTest method test_Atom_missing_message_container.

@Test(expected = DataIntegrityViolationException.class)
public void test_Atom_missing_message_container() {
    Atom atom = new Atom();
    atom.setAtomURI(URI.create("uri:atom"));
    atom.setCreationDate(new Date());
    atomRepository.save(atom);
}
Also used : UserAtom(won.owner.model.UserAtom) Atom(won.protocol.model.Atom) Date(java.util.Date) Test(org.junit.Test)

Example 24 with Atom

use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.

the class WonAclAccessDecisionVoter method voteForMessageRequest.

public int voteForMessageRequest(String webId, AuthToken authToken, URI resourceUri, FilterInvocation filterInvocation, Supplier<Integer> legacyImpl) {
    // if we're requesting a message, we have to check access for each message
    // container
    // that it is in
    Map<URI, Set<OperationRequest>> opReqs = new HashMap<>();
    Map<URI, Graph> aclGraphs = new HashMap<>();
    Map<URI, Integer> legacyResults = new HashMap<>();
    URI messageUri = WonMessageUriHelper.toGenericMessageURI(resourceUri, uriService.getMessageResourceURIPrefix());
    List<MessageEvent> msgs = messageEventRepository.findByMessageURI(messageUri);
    for (MessageEvent msg : msgs) {
        URI parent = msg.getParentURI();
        URI atomUri = uriService.getAtomURIofSubURI(parent);
        Optional<Atom> atom = atomService.getAtom(atomUri);
        if (!atom.isPresent()) {
            return ACCESS_DENIED;
        }
        if (!aclGraphs.containsKey(atomUri)) {
            Optional<Graph> aclGraph = atom.get().getAclGraph();
            if (aclGraph.isEmpty()) {
                legacyResults.put(atomUri, legacyImpl.get());
                continue;
            }
            aclGraphs.put(atomUri, aclGraph.get());
        }
        if (!atom.isPresent()) {
            continue;
        }
        OperationRequest operationRequest = new OperationRequest();
        if (authToken != null) {
            operationRequest.addBearsToken(authToken);
        }
        operationRequest.setRequestor(URI.create(webId));
        operationRequest.setReqAtomState(toAuthAtomState(atom.get().getState()));
        operationRequest.setReqAtom(atomUri);
        operationRequest.setOperationSimpleOperationExpression(OP_READ);
        if (uriService.isConnectionURI(parent)) {
            Optional<Connection> con = connectionRepository.findOneByConnectionURI(parent);
            if (con == null) {
                continue;
            }
            operationRequest.setReqPosition(POSITION_CONNECTION_MESSAGE);
            operationRequest.setReqConnectionMessage(msg.getMessageURI());
            operationRequest.setReqConnection(con.get().getConnectionURI());
            operationRequest.setReqSocket(con.get().getSocketURI());
            operationRequest.setReqSocketType(con.get().getTypeURI());
            operationRequest.setReqConnectionState(toAuthConnectionState(con.get().getState()));
            operationRequest.setReqConnectionTargetAtom(con.get().getTargetAtomURI());
        } else if (uriService.isAtomURI(parent)) {
            operationRequest.setReqPosition(POSITION_ATOM_MESSAGE);
        } else {
            legacyResults.put(atomUri, legacyImpl.get());
            continue;
        }
        if (!opReqs.containsKey(atomUri)) {
            Set<OperationRequest> ors = new HashSet<>();
            ors.add(operationRequest);
            opReqs.put(atomUri, ors);
        } else {
            opReqs.get(atomUri).add(operationRequest);
        }
    }
    Set<AclEvalResult> aclEvalResults = new HashSet<>();
    for (URI atomUri : aclGraphs.keySet()) {
        Graph aclGraph = aclGraphs.get(atomUri);
        for (OperationRequest opReq : opReqs.get(atomUri)) {
            aclEvalResults.add(wonAclEvaluatorFactory.create(aclGraph).decide(opReq));
        }
    }
    Optional<AclEvalResult> aclEvalResult = aclEvalResults.stream().reduce(WonAclEvaluator::mergeAclEvalResults);
    Integer legacyResult = legacyResults.values().stream().reduce((left, right) -> {
        if (left.equals(right)) {
            return left;
        }
        if (left.equals(ACCESS_GRANTED) || right.equals(ACCESS_GRANTED)) {
            return ACCESS_GRANTED;
        } else if (left.equals(ACCESS_ABSTAIN) || right.equals(ACCESS_ABSTAIN)) {
            return ACCESS_ABSTAIN;
        }
        return ACCESS_DENIED;
    }).orElse(ACCESS_ABSTAIN);
    if (legacyResult.equals(ACCESS_GRANTED) || (aclEvalResult.isPresent() && aclEvalResult.get().getDecision().equals(DecisionValue.ACCESS_GRANTED))) {
        return ACCESS_GRANTED;
    } else {
        if (aclEvalResult.isPresent()) {
            setAuthInfoIfDenied(filterInvocation, aclEvalResult.get());
        }
        return ACCESS_DENIED;
    }
}
Also used : AtomNodeChecker(won.auth.check.AtomNodeChecker) java.util(java.util) Connection(won.protocol.model.Connection) WonMessageUriHelper(won.protocol.util.WonMessageUriHelper) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) won.auth.model(won.auth.model) Autowired(org.springframework.beans.factory.annotation.Autowired) Supplier(java.util.function.Supplier) Graph(org.apache.jena.graph.Graph) WonAclEvaluator(won.auth.WonAclEvaluator) WonAclEvaluatorFactory(won.auth.WonAclEvaluatorFactory) AuthUtils(won.auth.AuthUtils) AccessDecisionVoter(org.springframework.security.access.AccessDecisionVoter) MessageEventRepository(won.protocol.repository.MessageEventRepository) WebIdUserDetails(won.node.springsecurity.userdetails.WebIdUserDetails) Individuals(won.auth.model.Individuals) WonDefaultAccessControlRules(won.node.springsecurity.WonDefaultAccessControlRules) WebIdKeyLoader(won.cryptography.rdfsign.WebIdKeyLoader) URI(java.net.URI) ConnectionRepository(won.protocol.repository.ConnectionRepository) URIService(won.node.service.nodeconfig.URIService) ConfigAttribute(org.springframework.security.access.ConfigAttribute) Atom(won.protocol.model.Atom) Logger(org.slf4j.Logger) Transactional(javax.transaction.Transactional) MethodHandles(java.lang.invoke.MethodHandles) ConnectionTargetCheckEvaluator(won.auth.check.ConnectionTargetCheckEvaluator) DatasetHolderRepository(won.protocol.repository.DatasetHolderRepository) StopWatch(org.springframework.util.StopWatch) Collectors(java.util.stream.Collectors) CryptographyService(won.cryptography.service.CryptographyService) GrantedAuthority(org.springframework.security.core.GrantedAuthority) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) FilterInvocation(org.springframework.security.web.FilterInvocation) MessageEvent(won.protocol.model.MessageEvent) Authentication(org.springframework.security.core.Authentication) AtomService(won.node.service.persistence.AtomService) MessageEvent(won.protocol.model.MessageEvent) Connection(won.protocol.model.Connection) WonAclEvaluator(won.auth.WonAclEvaluator) URI(java.net.URI) Atom(won.protocol.model.Atom) Graph(org.apache.jena.graph.Graph)

Aggregations

Atom (won.protocol.model.Atom)24 URI (java.net.URI)17 WonMessage (won.protocol.message.WonMessage)15 Connection (won.protocol.model.Connection)11 Graph (org.apache.jena.graph.Graph)5 Message (org.apache.camel.Message)4 WonMessageProcessingException (won.protocol.exception.WonMessageProcessingException)4 Dataset (org.apache.jena.query.Dataset)3 WonAclEvaluator (won.auth.WonAclEvaluator)3 URISyntaxException (java.net.URISyntaxException)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 MethodHandles (java.lang.invoke.MethodHandles)1 Date (java.util.Date)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 Transactional (javax.transaction.Transactional)1