/** Console logout */
  protected void logout(final HttpServletRequest request, final HttpServletResponse response)
      throws ServletException, IOException {
    final HttpSession session = request.getSession();

    final PlatformSession platformSession =
        (PlatformSession) session.getAttribute(PlatformLoginServlet.PLATFORMSESSION);
    if (platformSession != null) {
      try {
        final PlatformLoginAPI platformLoginAPI = PlatformAPIAccessor.getPlatformLoginAPI();
        platformLoginAPI.logout(platformSession);
      } catch (final BonitaException e) {
        if (LOGGER.isLoggable(Level.SEVERE)) {
          LOGGER.log(Level.SEVERE, "Error while performing the logout", e);
        }
      }
    }
    session.removeAttribute(PlatformLoginServlet.PLATFORMSESSION);
    session.invalidate();

    final String redirectAfterLoginStr =
        request.getParameter(AuthenticationManager.REDIRECT_AFTER_LOGIN_PARAM_NAME);
    // Do not modify this condition: the redirection should happen unless there is redirect=false in
    // the URL
    if (!Boolean.FALSE.toString().equals(redirectAfterLoginStr)) {
      response.sendRedirect(PLATFORM_LOGIN_PAGE);
    }
  }
Esempio n. 2
0
 public PlatformAPI getPlatformAPI() {
   if (this.platformAPI == null) {
     PlatformLoginAPI platformLoginAPI;
     try {
       platformLoginAPI = PlatformAPIAccessor.getPlatformLoginAPI();
       final PlatformSession platformSession =
           platformLoginAPI.login(PLATFORM_ADMIN, PLATFORM_PASSWORD);
       this.platformAPI = PlatformAPIAccessor.getPlatformAPI(platformSession);
     } catch (final BonitaHomeNotSetException e) {
       throw new TestToolkitException("Bonita home isn't set", e);
     } catch (final ServerAPIException e) {
       throw new TestToolkitException("Failed to call server API", e);
     } catch (final UnknownAPITypeException e) {
       throw new TestToolkitException("Invalid session to create tenant", e);
     } catch (final PlatformLoginException e) {
       throw new TestToolkitException("Invalid session to create tenant", e);
     } catch (final InvalidSessionException e) {
       throw new TestToolkitException("Invalid session to create tenant", e);
     }
   }
   return this.platformAPI;
 }
Esempio n. 3
0
  @Cover(
      classes = PlatformAPI.class,
      concept = BPMNConcept.NONE,
      keywords = {"Platform"},
      story = "The platform version must be the same than the project version.",
      jira = "")
  @Test
  public void getPlatformVersion() throws BonitaException, IOException {
    logoutOnTenant();
    final PlatformSession platformSession = loginOnPlatform();
    final PlatformAPI platformAPI = PlatformAPIAccessor.getPlatformAPI(platformSession);
    final Platform platform = platformAPI.getPlatform();
    logoutOnPlatform(platformSession);
    loginOnDefaultTenantWith(USERNAME, PASSWORD);
    final String platformVersionToTest = getBonitaVersion();

    assertNotNull("can't find the platform", platform);
    assertEquals("platformAdmin", platform.getCreatedBy());
    assertEquals(platformVersionToTest, platform.getVersion());
    assertEquals(platformVersionToTest, platform.getInitialVersion());
  }
Esempio n. 4
0
  @Test
  @Cover(
      classes = {},
      concept = BPMNConcept.ACTIVITIES,
      jira = "ENGINE-469",
      keywords = {"node", "restart", "transition", "flownode"},
      story = "elements must be restarted when they were not completed when the node was shut down")
  public void restartHandlerTests() throws Exception {
    /*
     * process with blocking connector
     */
    final ProcessDefinitionBuilder builder1 =
        new ProcessDefinitionBuilder().createNewInstance("p1", "1.0");
    builder1.addActor(ACTOR_NAME);
    builder1.addUserTask("step1", ACTOR_NAME);
    builder1
        .addAutomaticTask("step2")
        .addConnector("myConnector", "blocking-connector", "1.0", ConnectorEvent.ON_ENTER);
    builder1.addTransition("step1", "step2");
    builder1.addUserTask("ustep2", ACTOR_NAME);
    builder1.addTransition("step2", "ustep2");
    final BusinessArchive businessArchive =
        new BusinessArchiveBuilder()
            .createNewBusinessArchive()
            .setProcessDefinition(builder1.done())
            .addConnectorImplementation(
                new BarResource(
                    "blocking-connector.impl",
                    BuildTestUtil.buildConnectorImplementationFile(
                        "blocking-connector",
                        "1.0",
                        "blocking-connector-impl",
                        "1.0",
                        BlockingConnector.class.getName())))
            .done();
    final ProcessDefinition p1 = deployAndEnableProcessWithActor(businessArchive, ACTOR_NAME, john);

    /*
     * process with blocking operation (executing work)
     */
    final ProcessDefinitionBuilder builder2 =
        new ProcessDefinitionBuilder().createNewInstance("p2", "1.0");
    final String blockingGroovyScript1 =
        "org.bonitasoft.engine.test.BPMLocalIT.tryAcquireSemaphore1();\nreturn \"done\";";
    builder2.addActor(ACTOR_NAME);
    builder2.addShortTextData("data", null);
    builder2.addUserTask("step1", ACTOR_NAME);
    builder2
        .addAutomaticTask("step2")
        .addOperation(
            new OperationBuilder()
                .createSetDataOperation(
                    "data",
                    new ExpressionBuilder()
                        .createGroovyScriptExpression(
                            "blockingGroovyScript1",
                            blockingGroovyScript1,
                            String.class.getName())));
    builder2.addTransition("step1", "step2");
    builder2.addUserTask("ustep2", ACTOR_NAME);
    builder2.addTransition("step2", "ustep2");

    final ProcessDefinition p2 = deployAndEnableProcessWithActor(builder2.done(), ACTOR_NAME, john);

    /*
     * process with blocking transition (notify work)
     */
    final ProcessDefinitionBuilder builder3 =
        new ProcessDefinitionBuilder().createNewInstance("p3", "1.0");
    final String blockingGroovyScript2 =
        "org.bonitasoft.engine.test.BPMLocalIT.tryAcquireSemaphore2();\nreturn true;";
    builder3.addActor(ACTOR_NAME);
    builder3.addUserTask("step1", ACTOR_NAME);
    builder3.addAutomaticTask("step2");
    builder3.addTransition(
        "step1",
        "step2",
        new ExpressionBuilder()
            .createGroovyScriptExpression(
                "blockingGroovyScript2", blockingGroovyScript2, Boolean.class.getName()));
    builder3.addUserTask("ustep2", ACTOR_NAME);
    builder3.addTransition("step2", "ustep2");

    final ProcessDefinition p3 = deployAndEnableProcessWithActor(builder3.done(), ACTOR_NAME, john);

    // Block all 3 tasks
    BlockingConnector.semaphore.acquire();
    semaphore1.acquire();
    semaphore2.acquire();

    System.out.println("Start the process");
    final ProcessInstance pi1 = getProcessAPI().startProcess(p1.getId());
    final ProcessInstance pi2 = getProcessAPI().startProcess(p2.getId());
    final ProcessInstance pi3 = getProcessAPI().startProcess(p3.getId());
    waitForUserTaskAndExecuteIt(pi1, "step1", john);
    waitForUserTaskAndExecuteIt(pi2, "step1", john);
    waitForUserTaskAndExecuteIt(pi3, "step1", john);
    System.out.println("executed step1");
    logoutOnTenant();
    final PlatformSession loginPlatform = loginOnPlatform();
    final PlatformAPI platformAPI = PlatformAPIAccessor.getPlatformAPI(loginPlatform);
    // stop node and in the same time release the semaphores to unlock works
    final Thread thread =
        new Thread(
            new Runnable() {

              @Override
              public void run() {
                try {
                  Thread.sleep(200);
                } catch (final InterruptedException e) {
                  e.printStackTrace();
                }
                System.out.println("release semaphores");
                BlockingConnector.semaphore.release();
                semaphore1.release();
                semaphore2.release();
                System.out.println("released semaphores");
              }
            });
    System.out.println("stop node");
    thread.start();
    platformAPI.stopNode();
    System.out.println("node stopped");
    // release them (work will fail, node is stopped)
    thread.join(1000);
    Thread.sleep(50);
    System.out.println("start node");
    platformAPI.startNode();
    System.out.println("node started");
    logoutOnPlatform(loginPlatform);
    loginOnDefaultTenantWithDefaultTechnicalUser();

    // during stop node some flow node can be put in failed state
    retryFailedFlowNodes();

    // check we have all task ready
    waitForPendingTasks(john.getId(), 3);

    disableAndDeleteProcess(p1.getId());
    disableAndDeleteProcess(p2.getId());
    disableAndDeleteProcess(p3.getId());
  }