Search in sources :

Example 1 with KeyExpiredException

use of com.twinsoft.convertigo.engine.KeyExpiredException in project convertigo by convertigo.

the class ConnectorEditorPart method createCompositeDesign.

/**
 * This method initializes compositeDesign
 */
private void createCompositeDesign() {
    if (Engine.hasXulRunner() && connector instanceof HtmlConnector) {
        try {
            compositeDesign = new HtmlConnectorDesignComposite(connector, tabFolderOutputDesign, SWT.NONE);
        } catch (MaxCvsExceededException e) {
            String message = "You have reached the maximum allowed number of simultaneous HTML connectors; check your license keys.\n\n" + "Notice: according to your license key, the maximum allowed number of simultaneous HTML connectors is 2. " + "As you have more than 2 HTML connectors open, you will not be able to open another one nor run any transaction on this connector.\n\n" + "Please close unnecessary connectors.";
            ConvertigoPlugin.logError(message, true);
            compositeDesign = new Composite(tabFolderOutputDesign, SWT.NONE);
            labelNoDesign = new Label(compositeDesign, SWT.NONE | SWT.WRAP);
            labelNoDesign.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 10, 300, 200));
            labelNoDesign.setFont(new Font(null, "Tahoma", 10, 0));
            labelNoDesign.setText("\n" + message);
            Control[] children = tabFolderOutputDesign.getChildren();
            if ((children.length >= 2) && (children[1] instanceof HtmlConnectorDesignComposite))
                children[1].moveBelow(null);
        } catch (KeyExpiredException e) {
            String message = "Your HTML license key has expired; check your license keys.\n\n" + "Notice: according to your license key, your trial period has expired. " + "You will not be able to open an HTML connector nor run any transaction on this connector.\n\n";
            ConvertigoPlugin.logError(message, true);
            compositeDesign = new Composite(tabFolderOutputDesign, SWT.NONE);
            labelNoDesign = new Label(compositeDesign, SWT.NONE | SWT.WRAP);
            labelNoDesign.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 10, 300, 200));
            labelNoDesign.setFont(new Font(null, "Tahoma", 10, 0));
            labelNoDesign.setText("\n" + message);
            Control[] children = tabFolderOutputDesign.getChildren();
            if ((children.length >= 2) && (children[1] instanceof HtmlConnectorDesignComposite))
                children[1].moveBelow(null);
        }
    } else if (connector instanceof SapJcoConnector) {
        try {
            compositeDesign = new SapJcoConnectorDesignComposite(connector, tabFolderOutputDesign, SWT.NONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (connector instanceof SqlConnector) {
        try {
            compositeDesign = new SqlConnectorDesignComposite(connector, tabFolderOutputDesign, SWT.NONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        compositeDesign = new Composite(tabFolderOutputDesign, SWT.NONE);
        labelNoDesign = new Label(compositeDesign, SWT.NONE | SWT.WRAP);
        labelNoDesign.setFont(new Font(null, "Tahoma", 10, 0));
        labelNoDesign.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 10, 300, 200));
        labelNoDesign.setText("This connector does not provide any design tool");
    }
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) Font(org.eclipse.swt.graphics.Font) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException) IOException(java.io.IOException) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException)

Example 2 with KeyExpiredException

use of com.twinsoft.convertigo.engine.KeyExpiredException in project convertigo by convertigo.

the class SqlConnector method prepareForTransaction.

public void prepareForTransaction(Context context) throws EngineException {
    SqlTransaction sqlTransaction = null;
    try {
        sqlTransaction = (SqlTransaction) context.requestedObject;
    } catch (ClassCastException e) {
        throw new EngineException("Requested object is not a SQL transaction", e);
    }
    if (Engine.isEngineMode() && KeyManager.getCV(Session.EmulIDSQL) < 1) {
        String msg;
        if (KeyManager.has(Session.EmulIDSQL) && KeyManager.hasExpired(Session.EmulIDSQL)) {
            Engine.logEngine.error(msg = "Key expired for the SQL connector.");
            throw new KeyExpiredException(msg);
        }
        Engine.logEngine.error(msg = "No key for the SQL connector.");
        throw new MaxCvsExceededException(msg);
    }
    // Overwrites JDBC url, user and password if needed (#369)
    String variableValue = sqlTransaction.getParameterStringValue(Parameter.ConnectorConnectionString.getName());
    if (variableValue != null && !variableValue.isEmpty()) {
        if (!variableValue.equals(getJdbcURL()) && !variableValue.equals(getOverJdbcURL())) {
            setOverJdbcURL(variableValue);
            Engine.logBeans.debug("(SqlConnector) Connection string overriden!");
        }
    }
    Engine.logBeans.debug("(SqlConnector) JDBC URL: " + getConnectionJdbcURL());
}
Also used : KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) EngineException(com.twinsoft.convertigo.engine.EngineException) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException)

Example 3 with KeyExpiredException

use of com.twinsoft.convertigo.engine.KeyExpiredException in project convertigo by convertigo.

the class RestApiServlet method service.

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (request.getCharacterEncoding() == null) {
        try {
            // Set encoding if needed
            request.setCharacterEncoding("UTF-8");
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }
    try {
        if (EnginePropertiesManager.getPropertyAsBoolean(PropertyName.XSRF_API)) {
            HttpUtils.checkXSRF(request, response);
        }
        HttpSessionListener.checkSession(request);
    } catch (Throwable e) {
        throw new ServletException(e.getMessage(), e);
    }
    if (Engine.isEngineMode() && KeyManager.getCV(Session.EmulIDURLMAPPER) < 1) {
        String msg;
        if (KeyManager.has(Session.EmulIDURLMAPPER) && KeyManager.hasExpired(Session.EmulIDURLMAPPER)) {
            Engine.logEngine.error(msg = "Key expired for the URL Mapper.");
            throw new ServletException(new KeyExpiredException(msg));
        }
        Engine.logEngine.error(msg = "No key for the URL Mapper.");
        throw new ServletException(new MaxCvsExceededException(msg));
    }
    HttpServletRequestTwsWrapper wrapped_request = new HttpServletRequestTwsWrapper(request);
    request = wrapped_request;
    try {
        HttpSessionListener.checkSession(request);
    } catch (TASException e) {
        HttpUtils.terminateSession(request.getSession());
        throw new RuntimeException(e);
    }
    HttpSession httpSession = request.getSession();
    LogParameters logParameters = GenericUtils.cast(httpSession.getAttribute(RestApiServlet.class.getCanonicalName()));
    if (logParameters == null) {
        httpSession.setAttribute(RestApiServlet.class.getCanonicalName(), logParameters = new LogParameters());
        logParameters.put(mdcKeys.ContextID.toString().toLowerCase(), httpSession.getId());
    }
    Log4jHelper.mdcSet(logParameters);
    logParameters.put(mdcKeys.ClientIP.toString().toLowerCase(), request.getRemoteAddr());
    String encoded = request.getParameter(Parameter.RsaEncoded.getName());
    if (encoded != null) {
        String query = Engine.theApp.rsaManager.decrypt(encoded, request.getSession());
        wrapped_request.clearParameters();
        wrapped_request.addQuery(query);
    }
    String method = request.getMethod();
    String uri = request.getRequestURI();
    String query = request.getQueryString();
    Engine.logEngine.debug("(RestApiServlet) Requested URI: " + method + " " + uri);
    boolean isYaml = request.getParameter("YAML") != null;
    boolean isJson = request.getParameter("JSON") != null;
    if ("GET".equalsIgnoreCase(method) && (query == null || query.isEmpty()) && (uri.endsWith("/" + SwaggerUtils.servletMappingPath) || uri.endsWith("/" + OpenApiUtils.servletMappingPath))) {
        isJson = true;
    }
    // Generate YAML/JSON definition (swagger specific)
    if ("GET".equalsIgnoreCase(method) && (isYaml || isJson)) {
        try {
            String requestUrl = HttpUtils.originalRequestURL(request);
            // force endpoint in definition
            try {
                String endPointUrl = EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_ENDPOINT);
                if (endPointUrl != null && !endPointUrl.isEmpty()) {
                    requestUrl = endPointUrl + (uri.indexOf("/" + SwaggerUtils.servletMappingPath) != -1 ? uri.substring(uri.indexOf("/" + SwaggerUtils.servletMappingPath)) : uri.substring(uri.indexOf("/" + OpenApiUtils.servletMappingPath)));
                    Engine.logEngine.debug("(RestApiServlet) Force requestUrl: " + requestUrl);
                } else {
                    Engine.logEngine.debug("(RestApiServlet) Set requestUrl: " + requestUrl);
                }
            } catch (Throwable t) {
                Engine.logEngine.error("(RestApiServlet) Unable to retrieve server endpoint url: ", t);
            }
            Engine.logEngine.debug("(RestApiServlet) Projects path: " + new File(Engine.PROJECTS_PATH).getAbsolutePath());
            String output = uri.indexOf("/" + SwaggerUtils.servletMappingPath) != -1 ? buildSwaggerDefinition(requestUrl, request.getParameter("__project"), isYaml) : buildOpenApiDefinition(requestUrl, request.getParameter("__project"), isYaml);
            response.setCharacterEncoding("UTF-8");
            response.setContentType((isYaml ? MimeType.Yaml : MimeType.Json).value());
            Writer writer = response.getWriter();
            writer.write(output);
            Engine.logEngine.debug("(RestApiServlet) Definition sent :\n" + output);
        } catch (Exception e) {
            throw new ServletException(e);
        }
    } else // Handle REST request
    {
        long t0 = System.currentTimeMillis();
        try {
            Collection<UrlMapper> collection = RestApiManager.getInstance().getUrlMappers();
            if (collection.size() > 0) {
                if (method.equalsIgnoreCase("OPTIONS")) {
                    String origin = HeaderName.Origin.getHeader(request);
                    if (origin != null) {
                        Set<String> methods = new HashSet<String>();
                        String corsOrigin = null;
                        for (UrlMapper urlMapper : collection) {
                            String co = HttpUtils.filterCorsOrigin(urlMapper.getProject().getCorsOrigin(), origin);
                            if (co != null) {
                                if (corsOrigin == null || co.length() > corsOrigin.length()) {
                                    corsOrigin = co;
                                }
                                urlMapper.addMatchingMethods(wrapped_request, methods);
                            }
                        }
                        HttpUtils.applyCorsHeaders(request, response, corsOrigin, String.join(", ", methods));
                    }
                    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
                    return;
                }
                // Found a matching operation
                UrlMappingOperation urlMappingOperation = null;
                List<UrlAuthentication> urlAuthentications = null;
                for (UrlMapper urlMapper : collection) {
                    urlMappingOperation = urlMapper.getMatchingOperation(request);
                    if (urlMappingOperation != null) {
                        urlAuthentications = urlMapper.getAuthenticationList();
                        break;
                    }
                }
                // Handle request
                if (urlMappingOperation != null) {
                    StringBuffer buf;
                    // Request headers
                    if (Engine.logEngine.isDebugEnabled()) {
                        buf = new StringBuffer();
                        buf.append("(RestApiServlet) Request headers:\n");
                        Enumeration<String> headerNames = request.getHeaderNames();
                        while (headerNames.hasMoreElements()) {
                            String headerName = headerNames.nextElement();
                            String headerValue = request.getHeader(headerName);
                            buf.append(" " + headerName + "=" + headerValue + "\n");
                        }
                        Engine.logEngine.debug(buf.toString());
                        Engine.logEngine.debug("(RestApiServlet) Request parameters: " + Collections.list(request.getParameterNames()));
                    }
                    // The response content
                    String content = null;
                    // Check for authentication
                    if (urlMappingOperation.isTargetAuthenticationContextRequired()) {
                        // Case Authentications are defined for mapper
                        if (urlAuthentications != null) {
                            boolean authenticated = false;
                            int len = urlAuthentications.size();
                            if (len > 0) {
                                for (UrlAuthentication urlAuthentication : urlAuthentications) {
                                    // Handle Auth request
                                    response.reset();
                                    RequestAttribute.responseHeader.set(request, new HashMap<String, String>());
                                    RequestAttribute.responseStatus.set(request, new HashMap<Integer, String>());
                                    urlAuthentication.handleAuthRequest(request, response);
                                    // Check user has been authenticated
                                    authenticated = SessionAttribute.authenticatedUser.string(request.getSession()) != null;
                                    if (authenticated) {
                                        break;
                                    }
                                }
                                // Handle User request
                                if (authenticated) {
                                    response.reset();
                                    RequestAttribute.responseHeader.set(request, new HashMap<String, String>());
                                    RequestAttribute.responseStatus.set(request, new HashMap<Integer, String>());
                                    content = urlMappingOperation.handleRequest(request, response);
                                }
                            } else // HTTP authentication required
                            {
                                response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                            }
                        } else // HTTP authentication required
                        {
                            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                        }
                    } else // Handle User request
                    {
                        content = urlMappingOperation.handleRequest(request, response);
                    }
                    // Set response status
                    ServletUtils.applyCustomStatus(request, response);
                    Engine.logEngine.debug("(RestApiServlet) Response status code: " + response.getStatus());
                    // Set response headers
                    ServletUtils.applyCustomHeaders(request, response);
                    if (Engine.logEngine.isDebugEnabled()) {
                        buf = new StringBuffer();
                        buf.append("(RestApiServlet) Response headers:\n");
                        Collection<String> headerNames = response.getHeaderNames();
                        for (String headerName : headerNames) {
                            String headerValue = response.getHeader(headerName);
                            buf.append(" " + headerName + "=" + headerValue + "\n");
                        }
                        Engine.logEngine.debug(buf.toString());
                    }
                    // terminate session to avoid max session exceeded (case new session initiated for authentication)
                    if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {
                        if (urlMappingOperation instanceof com.twinsoft.convertigo.beans.rest.AbstractRestOperation) {
                            com.twinsoft.convertigo.beans.rest.AbstractRestOperation aro = (com.twinsoft.convertigo.beans.rest.AbstractRestOperation) urlMappingOperation;
                            if (aro.isTerminateSession()) {
                                Engine.logEngine.debug("(RestApiServlet) requireEndOfContext because of required authentication");
                                request.setAttribute("convertigo.requireEndOfContext", true);
                            }
                        }
                    }
                    if (content != null) {
                        Writer writer = response.getWriter();
                        writer.write(content);
                    }
                    Engine.logEngine.debug("(RestApiServlet) Request successfully handled");
                } else {
                    Engine.logEngine.debug("(RestApiServlet) No matching operation for request");
                    super.service(request, response);
                }
            } else {
                Engine.logEngine.debug("(RestApiServlet) No mapping defined");
                super.service(request, response);
            }
        } catch (Exception e) {
            throw new ServletException(e);
        } finally {
            Requester requester = (Requester) request.getAttribute("convertigo.requester");
            if (requester != null) {
                Engine.logEngine.debug("(RestApiServlet) processRequestEnd, onFinally");
                processRequestEnd(request, requester);
                onFinally(request);
            } else {
                Engine.logEngine.debug("(RestApiServlet) terminate session");
                try {
                    HttpUtils.terminateSession(httpSession);
                } catch (Exception e) {
                    Engine.logEngine.warn("(RestApiServlet) unabled to terminate session", e);
                }
            }
            long t1 = System.currentTimeMillis();
            Engine.theApp.pluginsManager.fireHttpServletRequestEnd(request, t0, t1);
        }
    }
}
Also used : TASException(com.twinsoft.tas.TASException) ServletException(javax.servlet.ServletException) Requester(com.twinsoft.convertigo.engine.requesters.Requester) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException) HttpServletRequestTwsWrapper(com.twinsoft.convertigo.engine.util.HttpServletRequestTwsWrapper) HashSet(java.util.HashSet) UrlMapper(com.twinsoft.convertigo.beans.core.UrlMapper) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) HttpSession(javax.servlet.http.HttpSession) ServletException(javax.servlet.ServletException) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException) TASException(com.twinsoft.tas.TASException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) EngineException(com.twinsoft.convertigo.engine.EngineException) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) LogParameters(com.twinsoft.convertigo.engine.LogParameters) UrlAuthentication(com.twinsoft.convertigo.beans.core.UrlAuthentication) File(java.io.File) Writer(java.io.Writer)

Aggregations

KeyExpiredException (com.twinsoft.convertigo.engine.KeyExpiredException)3 MaxCvsExceededException (com.twinsoft.convertigo.engine.MaxCvsExceededException)3 EngineException (com.twinsoft.convertigo.engine.EngineException)2 IOException (java.io.IOException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)1 SapJcoConnector (com.twinsoft.convertigo.beans.connectors.SapJcoConnector)1 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)1 UrlAuthentication (com.twinsoft.convertigo.beans.core.UrlAuthentication)1 UrlMapper (com.twinsoft.convertigo.beans.core.UrlMapper)1 UrlMappingOperation (com.twinsoft.convertigo.beans.core.UrlMappingOperation)1 SqlTransaction (com.twinsoft.convertigo.beans.transactions.SqlTransaction)1 LogParameters (com.twinsoft.convertigo.engine.LogParameters)1 Requester (com.twinsoft.convertigo.engine.requesters.Requester)1 HttpServletRequestTwsWrapper (com.twinsoft.convertigo.engine.util.HttpServletRequestTwsWrapper)1 TASException (com.twinsoft.tas.TASException)1 File (java.io.File)1 Writer (java.io.Writer)1 HashSet (java.util.HashSet)1 ServletException (javax.servlet.ServletException)1