我已经在本地主机上部署了jbpm-cosole,并且创建了一个Java应用程序来为流程事务进行REST调用.所以,我的问题是.
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.
由于jbpm-console使用spring-security,如何将身份验证请求发送到JBPM?
As jbpm-console uses spring-security, how to send authentication request to JBPM?
成功进行身份验证后,我想将身份验证令牌存储为java对象,以进行进一步的事务而无需登录.
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.
推荐答案这是返回用户任务列表的示例代码.您只需要在请求标头中设置身份验证详细信息,如此代码所示.这适用于 jbpm-6.1.0.Final .
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 = "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); } } }更多推荐
JBPM控制台通过Java进行远程认证
发布评论