Search in sources :

Example 1 with org.ow2.proactive_grid_cloud_portal.common

use of org.ow2.proactive_grid_cloud_portal.common in project core by authzforce.

the class PepActionExpression method evaluate.

/**
 * Evaluates to a PEP action (obligation/advice).
 *
 * @param context
 *            Individual Decision evaluation context
 * @param mdpContext
 * 	 the context of the Multiple Decision request that the {@code context} belongs to if the Multiple Decision Profile is used.
 * @return an instance of a PEP action in JAXB model (JAXB Obligation/Advice)
 * @throws org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException
 *             if any of the attribute assignment expressions evaluates to "Indeterminate" (see XACML 3.0 core spec, section 7.18)
 */
public PepAction evaluate(final EvaluationContext context, final Optional<EvaluationContext> mdpContext) throws IndeterminateEvaluationException {
    // else there are assignmentExpressions
    final List<PepActionAttributeAssignment<?>> assignments = new ArrayList<>();
    for (final AttributeAssignmentExpressionEvaluator attrAssignmentExpr : this.evaluableAttributeAssignmentExpressions) {
        /*
			 * Section 5.39 of XACML 3.0 core spec says there may be multiple AttributeAssignments resulting from one AttributeAssignmentExpression
			 */
        final Collection<PepActionAttributeAssignment<?>> attrAssignsFromExpr;
        try {
            attrAssignsFromExpr = attrAssignmentExpr.evaluate(context, mdpContext);
            LOGGER.debug("{}/{} -> {}", this, attrAssignmentExpr, attrAssignsFromExpr);
        } catch (final IndeterminateEvaluationException e) {
            throw new IndeterminateEvaluationException(this + ": Error evaluating " + attrAssignmentExpr, e);
        }
        assignments.addAll(attrAssignsFromExpr);
    }
    return new PepAction(actionId, isMandatory, ImmutableList.copyOf(assignments));
}
Also used : PepActionAttributeAssignment(org.ow2.authzforce.core.pdp.api.PepActionAttributeAssignment) IndeterminateEvaluationException(org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException) PepAction(org.ow2.authzforce.core.pdp.api.PepAction)

Example 2 with org.ow2.proactive_grid_cloud_portal.common

use of org.ow2.proactive_grid_cloud_portal.common in project petals-se-flowable by petalslink.

the class GetProcessInstancesOperation method searchProcessInstances.

/**
 * Search process instances that are not ended (in state 'active' or 'suspended').
 */
private GetProcessInstancesResponse searchProcessInstances(final GetProcessInstances incomingObject, final ProcessInstanceState state) throws MessagingException {
    final ProcessInstanceQuery processInstanceQuery = this.runtimeService.createProcessInstanceQuery();
    if (state == ProcessInstanceState.ACTIVE) {
        processInstanceQuery.active();
    } else if (state == ProcessInstanceState.SUSPENDED) {
        processInstanceQuery.suspended();
    } else {
        // we search all process instances independently of their state: ACTIVE and SUSPENDED
        assert state == null;
    }
    final String processDefinitionId = incomingObject.getProcessDefinitionIdentifier();
    if (processDefinitionId != null && !processDefinitionId.isEmpty()) {
        processInstanceQuery.processDefinitionKey(processDefinitionId);
    }
    final String processInstanceId = incomingObject.getProcessInstanceIdentifier();
    if (processInstanceId != null && !processInstanceId.isEmpty()) {
        processInstanceQuery.processInstanceId(processInstanceId);
    }
    final Variables variables = incomingObject.getVariables();
    if (variables != null && !variables.getVariable().isEmpty()) {
        for (final Variable variable : variables.getVariable()) {
            processInstanceQuery.variableValueEquals(variable.getName(), Utils.parseVariableValue(variable));
        }
    }
    processInstanceQuery.includeProcessVariables();
    final GetProcessInstancesResponse response = new GetProcessInstancesResponse();
    final ProcessInstances responseProcessInstances = new ProcessInstances();
    response.setProcessInstances(responseProcessInstances);
    final List<ProcessInstance> processInstances = processInstanceQuery.list();
    for (final ProcessInstance processInstance : processInstances) {
        final org.ow2.petals.components.flowable.generic._1.ProcessInstance responseProcessInstance = new org.ow2.petals.components.flowable.generic._1.ProcessInstance();
        responseProcessInstances.getProcessInstance().add(responseProcessInstance);
        responseProcessInstance.setProcessInstanceIdentifier(processInstance.getProcessInstanceId());
        if (processInstance.isSuspended()) {
            responseProcessInstance.setState(ProcessInstanceState.SUSPENDED);
        } else if (processInstance.isEnded()) {
            responseProcessInstance.setState(ProcessInstanceState.FINISHED);
        } else {
            responseProcessInstance.setState(ProcessInstanceState.ACTIVE);
        }
        final ProcessDefinitionQuery processDefQuery = this.repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId());
        final ProcessDefinition processDefinition = processDefQuery.singleResult();
        responseProcessInstance.setProcessDefinitionIdentifier(processDefinition.getKey());
        responseProcessInstance.setVariables(Utils.buildVariables(processInstance.getProcessVariables(), this.log));
    }
    return response;
}
Also used : Variable(org.ow2.petals.components.flowable.generic._1.Variable) GetProcessInstancesResponse(org.ow2.petals.components.flowable.generic._1.GetProcessInstancesResponse) ProcessDefinitionQuery(org.flowable.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) Variables(org.ow2.petals.components.flowable.generic._1.Variables) ProcessInstances(org.ow2.petals.components.flowable.generic._1.ProcessInstances) GetProcessInstances(org.ow2.petals.components.flowable.generic._1.GetProcessInstances) ProcessInstanceQuery(org.flowable.engine.runtime.ProcessInstanceQuery) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance)

Example 3 with org.ow2.proactive_grid_cloud_portal.common

use of org.ow2.proactive_grid_cloud_portal.common in project petals-se-flowable by petalslink.

the class NormalizedMessageOutputStream method close.

@Override
public void close() throws IOException {
    super.close();
    // needed so that logs are put in the right flow instance folder
    PetalsExecutionContext.putFlowAttributes(this.flowAttributes);
    final Exchange cxfExchange = this.cxfMessage.getExchange();
    final EndpointInfo endpointInfo = cxfExchange.getEndpoint().getEndpointInfo();
    final QName interfaceName = endpointInfo.getInterface().getName();
    final QName serviceName = endpointInfo.getService().getName();
    final OperationInfo operationInfo = cxfExchange.getBindingOperationInfo().getOperationInfo();
    final QName operationName = operationInfo.getName();
    try {
        Consumes consume = this.sender.getComponent().getServiceUnitManager().getConsumesFromDestination(null, serviceName, interfaceName, operationName);
        final MEPPatternConstants mep = getMEP(operationInfo, consume);
        if (consume == null) {
            this.sender.getLogger().log(Level.WARNING, String.format("No Consumes declared in the JBI descriptor for the request to send, using informations from the process and default timeout: interface=%s, serviceName=%s, operation=%s, mep=%s", interfaceName, serviceName, operationName, mep));
            consume = new Consumes();
            // TODO: Create a unit test where the interface name is missing
            consume.setInterfaceName(interfaceName);
            // TODO: Create a unit test where the service name is missing
            consume.setServiceName(serviceName);
        } else {
            if (interfaceName != null && !consume.getInterfaceName().equals(interfaceName)) {
                this.sender.getLogger().log(Level.WARNING, "Mismatch between JBI Consumes interface name and process information (" + consume.getInterfaceName() + " vs " + interfaceName + "), using Consumes information.");
            }
            if (serviceName != null && !serviceName.equals(consume.getServiceName())) {
                this.sender.getLogger().log(Level.WARNING, "Mismatch between JBI Consumes service name and process information (" + consume.getServiceName() + " vs " + serviceName + "), using Consumes information.");
            }
        }
        // TODO: Find a way to define the endpoint name to use: maybe the address could contain it in endpointInfo?
        // TODO: Create a unit test where the endpoint name is missing
        // TODO: Create a unit test where the operation name is missing
        final org.ow2.petals.component.framework.api.message.Exchange jbiExchange = this.sender.createExchange(consume, mep, this.extFlowTracingActivated);
        // We always use the operation from the process (the JBI Consumes defines the service used, not the
        // operation)
        jbiExchange.setOperation(operationName);
        // Set timeout at CXF level. It must be upper than the timeout defined into SU JBI descriptor level)
        final long timeout = this.sender.getTimeout(consume);
        if (timeout > 0) {
            cxfExchange.getOutMessage().put(ClientImpl.SYNC_TIMEOUT, timeout + CXF_SYNC_TIMEOUT_INTERNAL_PART);
        }
        // TODO: Add support for attachments
        // TODO: MUST be optimized generating directly an XML message by CXF or Flowable
        // The buffer contains a SOAP message, we just remove the SOAP envelope
        final DocumentBuilder docBuilder = DocumentBuilders.takeDocumentBuilder();
        try {
            if (this.sender.getLogger().isLoggable(Level.FINE)) {
                this.sender.getLogger().fine("Request to send: " + new String(buf));
            }
            final Document doc = docBuilder.parse(new ByteArrayInputStream(buf));
            final NodeList soapBodies = doc.getElementsByTagNameNS("http://schemas.xmlsoap.org/soap/envelope/", "Body");
            if (soapBodies.item(0).hasChildNodes()) {
                final Node xmlPayload = soapBodies.item(0).getFirstChild();
                jbiExchange.setInMessageContent(new DOMSource(xmlPayload));
            } else {
                throw new IOException("Empty service task request");
            }
        } catch (final SAXException e) {
            throw new IOException(e);
        } finally {
            DocumentBuilders.releaseDocumentBuilder(docBuilder);
        }
        // TODO: Try to find a way to send exchange asynchronously
        if (cxfExchange.isOneWay()) {
            if (this.sender.sendSync(jbiExchange)) {
                if (jbiExchange.isErrorStatus()) {
                    // An error was returned
                    throw jbiExchange.getError();
                } else if (jbiExchange.isDoneStatus()) {
                // Status DONE returned
                } else {
                    // A fault was returned
                    final Message cxfInMessage = new MessageImpl();
                    cxfInMessage.setExchange(cxfExchange);
                    final Document faultReceived = PetalsConduit.wrapAsSoapFault(jbiExchange.getFault());
                    final EasyByteArrayOutputStream ebaos = new EasyByteArrayOutputStream();
                    DOMHelper.prettyPrint(faultReceived, ebaos);
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("Fault XML payload received: " + ebaos.toString());
                    }
                    cxfInMessage.setContent(InputStream.class, ebaos.toByteArrayInputStream());
                    this.conduit.getMessageObserver().onMessage(cxfInMessage);
                    jbiExchange.setDoneStatus();
                    this.sender.send(jbiExchange);
                }
            } else {
                // A timeout occurs
                throw new MessagingException("A timeout occurs invoking service.");
            }
        } else {
            this.sender.sendAsync(jbiExchange, new PetalsFlowableAsyncContext(cxfExchange, this.asyncCallback));
        }
    } catch (final IOException e) {
        throw e;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) DOMSource(javax.xml.transform.dom.DOMSource) Message(org.apache.cxf.message.Message) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Consumes(org.ow2.petals.component.framework.jbidescriptor.generated.Consumes) PetalsFlowableAsyncContext(org.ow2.petals.flowable.outgoing.PetalsFlowableAsyncContext) EasyByteArrayOutputStream(com.ebmwebsourcing.easycommons.stream.EasyByteArrayOutputStream) MessagingException(javax.jbi.messaging.MessagingException) QName(javax.xml.namespace.QName) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) MessagingException(javax.jbi.messaging.MessagingException) Exchange(org.apache.cxf.message.Exchange) MessageExchange(javax.jbi.messaging.MessageExchange) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) MEPPatternConstants(org.ow2.easywsdl.wsdl.api.abstractItf.AbsItfOperation.MEPPatternConstants) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 4 with org.ow2.proactive_grid_cloud_portal.common

use of org.ow2.proactive_grid_cloud_portal.common in project petals-se-flowable by petalslink.

the class PetalsConduit method onExpiredMessage.

@Override
public void onExpiredMessage(final org.ow2.petals.component.framework.api.message.Exchange asyncExchange, final Exchange cxfExchange) {
    // A timeout occurs, the error is pushed into CXF exchange as a standard fault
    final String errorMsg = String.format("A timeout occurs on exchange '%s'", asyncExchange.getExchangeId());
    this.logger.warning(errorMsg);
    final Document xmlPayload = wrapAsSoapCommonFault(new Exception(errorMsg));
    final EasyByteArrayOutputStream ebaos = new EasyByteArrayOutputStream();
    DOMHelper.prettyPrint(xmlPayload, ebaos);
    if (this.logger.isLoggable(Level.FINE)) {
        this.logger.fine("Timeout received as common soap fault: " + ebaos.toString());
    }
    final MessageImpl msg = new MessageImpl();
    msg.setContent(InputStream.class, ebaos.toByteArrayInputStream());
    cxfExchange.setInMessage(msg);
    this.incomingObserver.onMessage(msg);
}
Also used : EasyByteArrayOutputStream(com.ebmwebsourcing.easycommons.stream.EasyByteArrayOutputStream) Document(org.w3c.dom.Document) MessageImpl(org.apache.cxf.message.MessageImpl) PEtALSCDKException(org.ow2.petals.component.framework.api.exception.PEtALSCDKException) IOException(java.io.IOException) MessagingException(javax.jbi.messaging.MessagingException)

Example 5 with org.ow2.proactive_grid_cloud_portal.common

use of org.ow2.proactive_grid_cloud_portal.common in project petals-bc-gateway by petalslink.

the class MonitTraceFilteringTest method monitTracesFiltering.

/**
 * <p>
 * Check the MONIT trace filtering.
 * </p>
 * <p>
 * Note: According to the Petals CDK JUnit, the flow tracing configuration of the <b>service provider consumed</b>
 * depends on the received exchange. If it contains the property
 * {@value org.ow2.petals.component.framework.api.Message#FLOW_TRACING_ACTIVATION_MSGEX_PROP}, its value is used,
 * otherwise the flow tracing is enabled.
 * </p>
 */
@Test
public void monitTracesFiltering() throws Exception {
    final InputStream isMonitTraceFilteringRules = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/ow2/petals/bc/gateway/monit/monitTraceFilteringRules.csv");
    assertNotNull(isMonitTraceFilteringRules);
    final List<MonitTraceFilteringRule> monitTraceFilteringRules = this.readMonitTraceFileteringRules(isMonitTraceFilteringRules);
    int ruleCpt = 0;
    for (final MonitTraceFilteringRule rule : monitTraceFilteringRules) {
        this.executeRule(rule, ++ruleCpt);
    }
}
Also used : InputStream(java.io.InputStream) ServiceEndpoint(javax.jbi.servicedesc.ServiceEndpoint) AbstractEnvironmentTest(org.ow2.petals.bc.gateway.AbstractEnvironmentTest) ComponentUnderTest(org.ow2.petals.component.framework.junit.rule.ComponentUnderTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 JobId (org.ow2.proactive.scheduler.common.job.JobId)9 File (java.io.File)7 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)6 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 IndeterminateEvaluationException (org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException)4 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)4 EasyByteArrayOutputStream (com.ebmwebsourcing.easycommons.stream.EasyByteArrayOutputStream)3 FileObject (org.apache.commons.vfs2.FileObject)3 URI (java.net.URI)2 KeyException (java.security.KeyException)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 Properties (java.util.Properties)2 MessagingException (javax.jbi.messaging.MessagingException)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)2 ProcessDefinitionQuery (org.flowable.engine.repository.ProcessDefinitionQuery)2