public class TestJwt {
public static void main(String[] args) throws MalformedURLException, ProtocolException, UnsupportedEncodingException, NoSuchAlgorithmException, IOException {
new TestJwt().sendPut(createUriWithJwt(), "{\"update\":{\"customfield_10116\":[{\"set\":\"2016-7-1\"}]}}", "PUT");
}
private static final String USER_AGENT = "Mozilla/5.0";
public static String createUriWithJwt()
throws UnsupportedEncodingException, NoSuchAlgorithmException {
long issuedAt = System.currentTimeMillis() / 1000L;
long expiresAt = issuedAt + 180L;
String key = "com.redmoon.customfields.jira"; //the key from the add-on descriptor
String sharedSecret = "*******************************************************************************"; //the sharedsecret key received
//during the add-on installation handshake
String method = "PUT";
String baseUrl = "https://redmoondev.atlassian.net/";
String contextPath = "/";
String apiPath = "/rest/api/2/issue/TEST-1";
JwtJsonBuilder jwtBuilder = new JsonSmartJwtJsonBuilder()
.issuedAt(issuedAt)
.expirationTime(expiresAt)
.issuer(key);
CanonicalHttpUriRequest canonical = new CanonicalHttpUriRequest(method, apiPath, contextPath, new HashMap());
JwtClaimsBuilder.appendHttpRequestClaims(jwtBuilder, canonical);
JwtWriterFactory jwtWriterFactory = new NimbusJwtWriterFactory();
String jwtbuilt = jwtBuilder.build();
String jwtToken = jwtWriterFactory.macSigningWriter(SigningAlgorithm.HS256, sharedSecret).jsonToJwt(jwtbuilt);
String apiUrl = baseUrl + apiPath + "?jwt=" + jwtToken+"&overrideScreenSecurity=true";
return apiUrl;
}
public String sendPut(String url, String data, String sendType) throws MalformedURLException, IOException, ProtocolException {
boolean success = false;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setConnectTimeout(120000);
//add request header
con.setRequestMethod(sendType);
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
con.setRequestProperty("Content-Type", "application/json");
// Send post request
con.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(data);
wr.flush();
wr.close();
con.connect();
int responseCode = con.getResponseCode();
success = responseCode >= 200 && responseCode <= 204;
BufferedReader in;
if(success){
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else {
in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("URL: "+url);
System.out.println("Success: "+success);
System.out.println("Response: "+response.toString());
String responseMessage = response.toString();
return responseMessage;
}
}--
You received this message because you are subscribed to the Google Groups "Atlassian Connect Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connect-dev+unsub...@googlegroups.com.
--Seb RuizAtlassian
Map<String, String[]> parameters = new HashMap<>();paramters.put("overrideScreenSecurity", new String[] {true});CanonicalHttpUriRequest canonical = new CanonicalHttpUriRequest(method, apiPath, contextPath, parameters);
public static String createUriWithJwt()
throws UnsupportedEncodingException, NoSuchAlgorithmException {
long issuedAt = System.currentTimeMillis() / 1000L;
long expiresAt = issuedAt + 180L;
String key = "com.redmoon.customfields.jira"; //the key from the add-on descriptor
String sharedSecret = "**************************************************************************************"; //the sharedsecret key received
//during the add-on installation handshake
String method = "PUT";
String baseUrl = "https://redmoondev.atlassian.net/";
String contextPath = "/";
String apiPath = "/rest/api/2/issue/TEST-1";
JwtJsonBuilder jwtBuilder = new JsonSmartJwtJsonBuilder()
.issuedAt(issuedAt)
.expirationTime(expiresAt)
.issuer(key);
Map<String, String[]> parameters = new HashMap();
parameters.put("overrideScreenSecurity", new String[] {"true"});
CanonicalHttpUriRequest canonical = new CanonicalHttpUriRequest(method, apiPath, contextPath, parameters);