JBPM Console Remote authetication through java

房东的猫 提交于 2019-12-23 02:49:21

问题


I have deployed jbpm-cosole on my localhost, and I have created a java application to make REST calls for process transaction. So, my question is.

  1. As jbpm-console uses spring-security, how to send authentication request to JBPM?

  2. After successful authentication I want to store authentication token as a java object to make further transactions without login.

or is there any another way to do that please let me know.


回答1:


This is a sample code which returns the tasks list of a user. You just need to set the authentication details in request header as shown in this code. This works with jbpm-6.1.0.Final.

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

public class JBPMRest {
  public static void getTaskSummaryList() throws Exception {
    String status = "Reserved";
    String actor = "krisv";

    String addr = "http://localhost:8080/jbpm-console/rest/task/query?status=" + status + "&potentialOwner=" + actor;
    try {
      HttpClient client = HttpClientBuilder.create().build();
      HttpGet get = new HttpGet(addr);

      String authData = "krisv" + ":" + "krisv";
      String encoded = new sun.misc.BASE64Encoder().encode(authData.getBytes());
      get.setHeader("Content-Type", "application/json");
      get.setHeader("Authorization", "Basic " + encoded);
      get.setHeader("ACCEPT", "application/xml");

      HttpResponse cgResponse = client.execute(get);
      String content = EntityUtils.toString(cgResponse.getEntity());
      System.out.println(content);
    } catch (Exception e) {
      throw new Exception("Error consuming service.", e);
    }
  }
}



回答2:


You can send basic authentication information (username + password) in the header of your REST call. The remote Java client implementation for example does this as well. If you use the remote Java client, you can reuse the same engine for subsequent calls as well.



来源:https://stackoverflow.com/questions/27656151/jbpm-console-remote-authetication-through-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!