我正在尝试生成用于授权API的jwt令牌。首先,我无法从JIRA找到任何令牌生成器api。经过大量搜索后,我找到了一个生成jwt令牌的java代码,但在导入zephyr库时出错。
错误:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script4.groovy: 18: unable to resolve class com.thed.zephyr.cloud.rest.ZFJCloudRestClient @ line 18, column 1. import com.thed.zephyr.cloud.rest.ZFJCloudRestClient;
Java代码:
https://github.com/zephyrdeveloper/zapi-cloud/blob/master/Samples/src/com/thed/zapi/cloud/sample/sampleJwtGenerator.java
答案 0 :(得分:0)
我使用SoapUI Groovy脚本为ZAPI生成JWT令牌。
注意:
图书馆版本应该是' commons-lang-2.6.jar'和' commons-codec-1.11.jar'在lib文件夹中。
添加&jwt-generator.jar'和' zfj-cloud-rest-client-3.0.jar'在垃圾箱里 - > ext文件夹。 jwt generator
将创建特定于输入的API网址的JWT令牌。 例如:
String createCycleUri = zephyrBaseUrl +" /public/rest/api/1.0/cycle" ;;
在生成jwt标记之前提及api HTTP方法类型。
String jwt = jwtGenerator.generateJWT(" POST",uri,expirationInSec);
网站始终针对任何ZAPI API进行修复。这将采用JWT令牌。
文件中提到了这一点。
例如:
Groovy:
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.thed.zephyr.cloud.rest.ZFJCloudRestClient;
import com.thed.zephyr.cloud.rest.client.JwtGenerator;
def site = context.expand( '${#Project#Site}' )
def zapiAccessKey = context.expand( '${#Project#zapiAccessKey}' )
def secretID = context.expand( '${#Project#secretID}' )
def user = context.expand( '${#Project#user}' )
// Replace Zephyr BaseUrl with the <ZAPI_CLOUD_URL> shared with ZAPI Cloud Installation
String zephyrBaseUrl = site;
// zephyr accessKey , we can get from Addons >> zapi section
String accessKey = zapiAccessKey;
// zephyr secretKey , we can get from Addons >> zapi section
String secretKey = secretID;
// Jira UserName
String userName = user;
ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName).build();
JwtGenerator jwtGenerator = client.getJwtGenerator();
// API to which the JWT token has to be generated
String createCycleUri = zephyrBaseUrl + "/public/rest/api/1.0/cycle";
URI uri = new URI(createCycleUri);
int expirationInSec = 3600;
String jwt = jwtGenerator.generateJWT("POST", uri, expirationInSec);
log.info "JWT Token : " + jwt
//Store token in property.
context.testCase.testSuite.project.setPropertyValue('JWT_Token', jwt)
答案 1 :(得分:0)
我认为,对于Cloud Jira,标记的答案是正确的。但是,服务器ZAPI用作内部Jira API。因此,您只需要对Jira进行基本身份验证即可。
your_jira_base_url / rest / zapi / latest / zql / executeSearch?zqlQuery =(project ='25221')&maxRecords = 3654
这是获取ZQL请求的示例。