Search in sources :

Example 6 with Stop

use of org.wso2.carbon.humantask.core.engine.commands.Stop in project ballerina by ballerina-lang.

the class BLangParserListener method getCurrentPos.

private DiagnosticPos getCurrentPos(ParserRuleContext ctx) {
    int startLine = ctx.getStart().getLine();
    int startCol = ctx.getStart().getCharPositionInLine() + 1;
    int endLine = -1;
    int endCol = -1;
    Token stop = ctx.getStop();
    if (stop != null) {
        endLine = stop.getLine();
        endCol = stop.getCharPositionInLine() + 1;
    }
    return new DiagnosticPos(diagnosticSrc, startLine, endLine, startCol, endCol);
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) Token(org.antlr.v4.runtime.Token) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 7 with Stop

use of org.wso2.carbon.humantask.core.engine.commands.Stop in project charon by wso2.

the class AbstractValidator method checkIfReadOnlyAndImmutableSubAttributesModified.

/*
     * check for read only and immutable sub attributes which has been modified on update request
     *
     * @param newAttributeList
     * @param oldAttributeList
     * @param attributeSchema
     * @throws BadRequestException
     * @throws CharonException
     */
private static void checkIfReadOnlyAndImmutableSubAttributesModified(Map<String, Attribute> newAttributeList, Map<String, Attribute> oldAttributeList, AttributeSchema attributeSchema) throws BadRequestException, CharonException {
    // check for sub attributes.
    AbstractAttribute newAttribute = (AbstractAttribute) newAttributeList.get(attributeSchema.getName());
    AbstractAttribute oldAttribute = (AbstractAttribute) oldAttributeList.get(attributeSchema.getName());
    List<SCIMAttributeSchema> subAttributeSchemaList = attributeSchema.getSubAttributeSchemas();
    if (subAttributeSchemaList != null) {
        if (SCIMResourceSchemaManager.getInstance().getExtensionName() != null) {
            if (attributeSchema.getName().equals(SCIMResourceSchemaManager.getInstance().getExtensionName())) {
                checkIfReadOnlyAndImmutableExtensionAttributesModified(subAttributeSchemaList, newAttribute, oldAttribute);
            }
        }
        if (newAttribute != null && oldAttribute != null) {
            if (attributeSchema.getMultiValued()) {
                // this is complex multivalued case
                List<Attribute> newSubValuesList = ((MultiValuedAttribute) newAttribute).getAttributeValues();
                List<Attribute> oldSubValuesList = ((MultiValuedAttribute) oldAttribute).getAttributeValues();
                // if size aren't equal, they do not preserver immutable quality
                if (newSubValuesList.size() != oldSubValuesList.size() && attributeSchema.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE)) {
                    throw new BadRequestException(ResponseCodeConstants.MUTABILITY);
                }
                // no need to check sub attributes of sub values separately for equality, stop at the sub value level
                for (Attribute subValue : newSubValuesList) {
                    if (!isListContains((((ComplexAttribute) subValue).getName()), oldSubValuesList) && attributeSchema.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE)) {
                        throw new BadRequestException(ResponseCodeConstants.MUTABILITY);
                    }
                }
            } else {
                // A complex attribute itself can not be immutable if it's sub variables are not immutable
                checkForReadOnlyAndImmutableInComplexAttributes(newAttribute, oldAttribute, subAttributeSchemaList);
            }
        } else if (newAttribute == null && oldAttribute != null) {
            if (attributeSchema.getMultiValued()) {
                List<Attribute> oldSubValuesList = ((MultiValuedAttribute) oldAttribute).getAttributeValues();
                Attribute clonedMultiValuedAttribute = (Attribute) CopyUtil.deepCopy(oldAttribute);
                clonedMultiValuedAttribute.deleteSubAttributes();
                for (Attribute subValue : oldSubValuesList) {
                    Attribute clonedSubValue = (Attribute) CopyUtil.deepCopy(subValue);
                    clonedSubValue.deleteSubAttributes();
                    for (AttributeSchema subAttributeSchema : subAttributeSchemaList) {
                        if (subAttributeSchema.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subAttributeSchema.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE)) {
                            if (((ComplexAttribute) subValue).isSubAttributeExist(subAttributeSchema.getName())) {
                                Attribute clonedSubValuesAttribute = (Attribute) CopyUtil.deepCopy(((ComplexAttribute) subValue).getSubAttribute(subAttributeSchema.getName()));
                                ((ComplexAttribute) clonedSubValue).setSubAttribute(clonedSubValuesAttribute);
                            }
                        }
                    }
                    ((MultiValuedAttribute) (clonedMultiValuedAttribute)).setAttributeValue(clonedSubValue);
                }
            } else {
                Map<String, Attribute> oldSubAttributeList = ((ComplexAttribute) (oldAttribute)).getSubAttributesList();
                Attribute clonedAttribute = (Attribute) CopyUtil.deepCopy(oldAttribute);
                clonedAttribute.deleteSubAttributes();
                for (AttributeSchema subAttributeSchema : subAttributeSchemaList) {
                    if (subAttributeSchema.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subAttributeSchema.getMutability().equals(SCIMDefinitions.Mutability.IMMUTABLE)) {
                        if (oldSubAttributeList.containsKey(subAttributeSchema.getName())) {
                            ((ComplexAttribute) (clonedAttribute)).setSubAttribute((Attribute) CopyUtil.deepCopy(oldSubAttributeList.get(subAttributeSchema.getName())));
                        }
                    }
                }
                newAttributeList.put(clonedAttribute.getName(), clonedAttribute);
            }
        } else if (newAttribute != null && oldAttribute == null) {
            if (attributeSchema.getMultiValued()) {
                if (attributeSchema.getMultiValued()) {
                    List<Attribute> newSubValuesList = ((MultiValuedAttribute) newAttribute).getAttributeValues();
                    for (Attribute subValue : newSubValuesList) {
                        for (AttributeSchema subAttributeSchema : subAttributeSchemaList) {
                            if (subAttributeSchema.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY)) {
                                ((ComplexAttribute) (subValue)).removeSubAttribute(subAttributeSchema.getName());
                            }
                        }
                    }
                }
            } else {
                // this is complex attribute case
                Map<String, Attribute> newSubAttributeList = ((ComplexAttribute) (newAttribute)).getSubAttributesList();
                for (AttributeSchema subAttributeSchema : subAttributeSchemaList) {
                    if (subAttributeSchema.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY)) {
                        if (newSubAttributeList.containsKey(subAttributeSchema.getName())) {
                            String error = "Read only attribute: " + subAttributeSchema.getName() + " is set from consumer in the SCIM Object. Removing it.";
                            logger.debug(error);
                            ((ComplexAttribute) newAttribute).removeSubAttribute(subAttributeSchema.getName());
                        }
                    }
                }
            }
        }
    }
}
Also used : MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) AbstractAttribute(org.wso2.charon3.core.attributes.AbstractAttribute) Attribute(org.wso2.charon3.core.attributes.Attribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) AbstractAttribute(org.wso2.charon3.core.attributes.AbstractAttribute) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with Stop

use of org.wso2.carbon.humantask.core.engine.commands.Stop in project carbon-apimgt by wso2.

the class RESTAPISecurityInterceptor method preCall.

/**
 * preCall is run before a handler method call is made. If any of the preCalls throw exception or return false then
 * no other subsequent preCalls will be called and the request processing will be terminated,
 * also no postCall interceptors will be called.
 *
 * @param request           HttpRequest being processed.
 * @param response          HttpResponder to send response.
 * @param serviceMethodInfo Info on handler method that will be called.
 * @return true if the request processing can continue, otherwise the hook should send response and return false to
 * stop further processing.
 * @throws APIMgtSecurityException if error occurs while executing the preCall
 */
@Override
public boolean preCall(Request request, Response response, ServiceMethodInfo serviceMethodInfo) throws APIMgtSecurityException {
    ErrorHandler errorHandler = null;
    boolean isAuthenticated = false;
    // CORS for Environments - Add allowed Origin when User-Agent sent 'Origin' header.
    String origin = request.getHeader(RestApiConstants.ORIGIN_HEADER);
    String allowedOrigin = EnvironmentUtils.getAllowedOrigin(origin);
    if (allowedOrigin != null) {
        response.setHeader(RestApiConstants.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, allowedOrigin).setHeader(RestApiConstants.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER, "true");
    }
    // CORS for Environments - Add allowed Methods and Headers when 'OPTIONS' method is called.
    if (request.getHttpMethod().equalsIgnoreCase(APIConstants.HTTP_OPTIONS)) {
        try {
            String definedHttpMethods = RestApiUtil.getDefinedMethodHeadersInSwaggerContent(request, serviceMethodInfo);
            if (definedHttpMethods != null) {
                response.setHeader(RestApiConstants.ACCESS_CONTROL_ALLOW_METHODS_HEADER, definedHttpMethods).setHeader(RestApiConstants.ACCESS_CONTROL_ALLOW_HEADERS_HEADER, RestApiConstants.ACCESS_CONTROL_ALLOW_HEADERS_LIST).setStatus(javax.ws.rs.core.Response.Status.OK.getStatusCode()).send();
                return false;
            }
        } catch (APIManagementException e) {
            String msg = "Couldn't find declared HTTP methods in swagger.yaml";
            ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
            log.error(msg, e);
            response.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).setEntity(errorDTO).send();
            return false;
        }
    }
    /* TODO: Following string contains check is done to avoid checking security headers in non API requests.
         * Consider this as a temporary fix until MSF4J support context based interceptor registration */
    String requestURI = request.getUri().toLowerCase(Locale.ENGLISH);
    if (!requestURI.contains("/api/am/")) {
        return true;
    }
    if (requestURI.contains("/login/token")) {
        return true;
    }
    String yamlContent = null;
    String protocol = (String) request.getProperty(PROTOCOL);
    Swagger swagger = null;
    if (requestURI.contains("/api/am/publisher")) {
        if (requestURI.contains("swagger.yaml")) {
            try {
                yamlContent = RestApiUtil.getPublisherRestAPIResource();
                response.setStatus(javax.ws.rs.core.Response.Status.OK.getStatusCode()).setEntity(yamlContent).setMediaType("text/x-yaml").send();
            } catch (APIManagementException e) {
                String msg = "Couldn't find swagger.yaml for publisher";
                ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
                log.error(msg, e);
                response.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).setEntity(errorDTO).send();
            }
            return false;
        }
    } else if (requestURI.contains("/api/am/store")) {
        if (requestURI.contains("swagger.json")) {
            try {
                yamlContent = RestApiUtil.getStoreRestAPIResource();
                swagger = new SwaggerParser().parse(yamlContent);
                swagger.setBasePath(RestApiUtil.getContext(RestApiConstants.APPType.STORE));
                swagger.setHost(RestApiUtil.getHost(protocol.toLowerCase(Locale.ENGLISH)));
                response.setStatus(javax.ws.rs.core.Response.Status.OK.getStatusCode()).setEntity(Json.pretty(swagger)).setMediaType(MediaType.APPLICATION_JSON).send();
            } catch (APIManagementException e) {
                String msg = "Couldn't find swagger.json for store";
                ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
                log.error(msg, e);
                response.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).setEntity(errorDTO).send();
            }
            return false;
        } else if (requestURI.contains("swagger.yaml")) {
            try {
                yamlContent = RestApiUtil.getStoreRestAPIResource();
                response.setStatus(javax.ws.rs.core.Response.Status.OK.getStatusCode()).setEntity(yamlContent).setMediaType("text/x-yaml").send();
            } catch (APIManagementException e) {
                String msg = "Couldn't find swagger.yaml for store";
                ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
                log.error(msg, e);
                response.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).setEntity(errorDTO).send();
            }
            return false;
        }
    } else if (requestURI.contains("/api/am/analytics")) {
        if (requestURI.contains("swagger.json")) {
            try {
                yamlContent = RestApiUtil.getAnalyticsRestAPIResource();
                swagger = new SwaggerParser().parse(yamlContent);
                swagger.setBasePath(RestApiUtil.getContext(RestApiConstants.APPType.ANALYTICS));
                swagger.setHost(RestApiUtil.getHost(protocol.toLowerCase(Locale.ENGLISH)));
            } catch (APIManagementException e) {
                log.error("Couldn't find swagger.json for analytics", e);
            }
            response.setStatus(javax.ws.rs.core.Response.Status.OK.getStatusCode()).setEntity(Json.pretty(swagger)).setMediaType(MediaType.APPLICATION_JSON).send();
            return false;
        }
    } else if (requestURI.contains("/editor") || requestURI.contains("keyserver") || requestURI.contains("core") || requestURI.contains("/api/am/config")) {
        return true;
    } else if (requestURI.contains("/api/am/admin")) {
        if (requestURI.contains("swagger.json")) {
            try {
                yamlContent = RestApiUtil.getAdminRestAPIResource();
                swagger = new SwaggerParser().parse(yamlContent);
                swagger.setBasePath(RestApiUtil.getContext(RestApiConstants.APPType.ADMIN));
                swagger.setHost(RestApiUtil.getHost(protocol.toLowerCase(Locale.ENGLISH)));
                response.setStatus(javax.ws.rs.core.Response.Status.OK.getStatusCode()).setEntity(Json.pretty(swagger)).setMediaType(MediaType.APPLICATION_JSON).send();
            } catch (APIManagementException e) {
                String msg = "Couldn't find swagger.yaml for admin";
                ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
                log.error(msg, e);
                response.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).setEntity(errorDTO).send();
            }
            return false;
        } else if (requestURI.contains("swagger.yaml")) {
            try {
                yamlContent = RestApiUtil.getAdminRestAPIResource();
                response.setStatus(javax.ws.rs.core.Response.Status.OK.getStatusCode()).setEntity(yamlContent).setMediaType("text/x-yaml").send();
            } catch (APIManagementException e) {
                String msg = "Couldn't find swagger.yaml for admin";
                ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
                log.error(msg, e);
                response.setStatus(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).setEntity(errorDTO).send();
            }
            return false;
        }
    }
    try {
        if (authenticatorImplClass == null) {
            Class<?> implClass = null;
            try {
                implClass = Class.forName(authenticatorName);
            } catch (ClassNotFoundException e) {
                throw new APIMgtSecurityException("Error while loading class " + authenticatorName, e);
            }
            authenticatorImplClass = (RESTAPIAuthenticator) implClass.newInstance();
        }
        isAuthenticated = authenticatorImplClass.authenticate(request, response, serviceMethodInfo);
    } catch (APIMgtSecurityException e) {
        errorHandler = e.getErrorHandler();
        log.error(e.getMessage() + " Requested Path: " + request.getUri());
    } catch (InstantiationException e) {
        log.error(e.getMessage() + " Error while instantiating authenticator: " + authenticatorName);
        isAuthenticated = false;
        errorHandler = ExceptionCodes.AUTH_GENERAL_ERROR;
    } catch (IllegalAccessException e) {
        log.error(e.getMessage() + " Error while accessing resource : " + authenticatorName);
        isAuthenticated = false;
        errorHandler = ExceptionCodes.AUTH_GENERAL_ERROR;
    }
    if (!isAuthenticated) {
        handleSecurityError(errorHandler, response);
    }
    return isAuthenticated;
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) ErrorHandler(org.wso2.carbon.apimgt.core.exception.ErrorHandler) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIMgtSecurityException(org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Swagger(io.swagger.models.Swagger)

Example 9 with Stop

use of org.wso2.carbon.humantask.core.engine.commands.Stop in project wso2-synapse by wso2.

the class Axis2SynapseController method stop.

/**
 * Cleanup the axis2 environment and stop the synapse environment.
 */
public void stop() {
    try {
        // stop tasks
        SynapseTaskManager synapseTaskManager = synapseEnvironment.getTaskManager();
        if (synapseTaskManager.isInitialized()) {
            synapseTaskManager.cleanup();
        }
        EnterpriseBeanstalkManager manager = (EnterpriseBeanstalkManager) serverContextInformation.getProperty(EnterpriseBeanstalkConstants.BEANSTALK_MANAGER_PROP_NAME);
        if (manager != null) {
            manager.destroy();
        }
        // stop the listener manager
        if (listenerManager != null) {
            listenerManager.stop();
        }
        // detach the synapse handlers
        if (configurationContext != null) {
            List<Phase> inflowPhases = configurationContext.getAxisConfiguration().getInFlowPhases();
            for (Phase inPhase : inflowPhases) {
                // we are interested about the Dispatch phase in the inflow
                if (PhaseMetadata.PHASE_DISPATCH.equals(inPhase.getPhaseName())) {
                    List<HandlerDescription> synapseHandlers = new ArrayList<HandlerDescription>();
                    for (Handler handler : inPhase.getHandlers()) {
                        if (SynapseDispatcher.NAME.equals(handler.getName()) || SynapseMustUnderstandHandler.NAME.equals(handler.getName())) {
                            synapseHandlers.add(handler.getHandlerDesc());
                        }
                    }
                    for (HandlerDescription handlerMD : synapseHandlers) {
                        inPhase.removeHandler(handlerMD);
                    }
                }
            }
        } else {
            handleException("Couldn't detach the Synapse handlers, " + "ConfigurationContext not found.");
        }
        // continue stopping the axis2 environment if we created it
        if (serverConfigurationInformation.isCreateNewInstance() && configurationContext != null && configurationContext.getAxisConfiguration() != null) {
            Map<String, AxisService> serviceMap = configurationContext.getAxisConfiguration().getServices();
            for (AxisService svc : serviceMap.values()) {
                svc.setActive(false);
            }
            // stop all modules
            Map<String, AxisModule> moduleMap = configurationContext.getAxisConfiguration().getModules();
            for (AxisModule mod : moduleMap.values()) {
                if (mod.getModule() != null && !"synapse".equals(mod.getName())) {
                    mod.getModule().shutdown(configurationContext);
                }
            }
        }
    } catch (AxisFault e) {
        log.error("Error stopping the Axis2 Environment");
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) EnterpriseBeanstalkManager(org.apache.synapse.commons.beanstalk.enterprise.EnterpriseBeanstalkManager) SecretCallbackHandler(org.wso2.securevault.secret.SecretCallbackHandler)

Example 10 with Stop

use of org.wso2.carbon.humantask.core.engine.commands.Stop in project carbon-business-process by wso2.

the class TaskOperationsImpl method stop.

/**
 * Cancel/stop the processing of the task. The task returns to the Reserved state.
 *
 * @param taskId : task identifier
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void stop(final URI taskId) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        validateTaskId(taskId);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                HumanTaskCommand stop = new Stop(getCaller(), new Long(taskId.toString()));
                stop.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : Stop(org.wso2.carbon.humantask.core.engine.commands.Stop) HumanTaskCommand(org.wso2.carbon.humantask.core.engine.HumanTaskCommand) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Aggregations

Map (java.util.Map)2 AxisFault (org.apache.axis2.AxisFault)2 Test (org.testng.annotations.Test)2 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)2 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)2 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Swagger (io.swagger.models.Swagger)1 SwaggerParser (io.swagger.parser.SwaggerParser)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Scanner (java.util.Scanner)1 ParseException (javax.mail.internet.ParseException)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Token (org.antlr.v4.runtime.Token)1 ClusteringAgent (org.apache.axis2.clustering.ClusteringAgent)1 FileNotFolderException (org.apache.commons.vfs2.FileNotFolderException)1