Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,627
Community Members
 
Community Events
184
Community Groups

Using PluginSettings in Scriptrunner Jobs

Edited

Hello everyone,
i want to store some Data in PluginSettings and want to access it in my own Plugin. I can't seem to save my HashMap and ending in an StackOverflow.


import ...


public class XXX {
private static PluginSettingsFactory pluginSettingsFactory = null;

public XXX () {
this.pluginSettingsFactory = pluginSettingsFactory;
}

public void set(Object value){
pluginSettingsFactory.createGlobalSettings().put("xxx", value);
}

public static HashMap<String, List> readTrustedIsser(List<String> validIssuerEndpoints){
HashMap<String, List> validations = new HashMap<>();
List<PublicKey> validKeys = new ArrayList<>();
List<String> validIssuers = new ArrayList<>();
List<String> validKids = new ArrayList<>();
for(String issuer : validIssuerEndpoints)
{
JSONObject openIdConfig = getJSONHttp(issuer);
String jwks_uri = openIdConfig.getString("jwks_uri");
validIssuers.add(openIdConfig.getString("issuer"));
JSONArray jwks_keys = getJSONHttp(jwks_uri).getJSONArray("keys");
for(Object jwks_key : jwks_keys)
{
JSONObject jsonkey = (JSONObject) jwks_key;
PublicKey pub = getPublicKey(jsonkey.getString("n"), jsonkey.getString("e"));
validKeys.add(pub);
validKids.add(jsonkey.getString("kid"));
}
}
validations.put("keys", validKeys);
validations.put("issuers", validIssuers);
validations.put("kids", validKids);
return validations;
}

public static JSONObject getJSONHttp(String uri) throws Exception
{
JSONObject json = new JSONObject();
CloseableHttpResponse responseGet = HttpClients.createDefault().execute(new HttpGet(uri));
if(responseGet.getStatusLine().getStatusCode() == 200)
{
String reponseStr = EntityUtils.toString(responseGet.getEntity());
json = new JSONObject(reponseStr);
}
return json;
}

public static PublicKey getPublicKey(String MODULUS, String EXPONENT) throws Exception
{
byte[] nb = base64UrlDecodeToBytes(MODULUS);
byte[] eb = base64UrlDecodeToBytes(EXPONENT);
BigInteger n = new BigInteger(1, nb);
BigInteger e = new BigInteger(1, eb);
RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(n, e);
PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(rsaPublicKeySpec);
return publicKey;
}

public static byte[] base64UrlDecodeToBytes(String input)
{
Base64 decoder = new Base64(-1, null, true);
return decoder.decode(input);
}

public static HashMap<String, List> doIt(){
final List<String> validIssuerEndpoints = Arrays.asList(
"link1",
"link2",
"link3",
"link4");
return readTrustedIsser(validIssuerEndpoints);
}

public static void main(String[] args) {
XXX x = new XXX();
HashMap<String, List> aa = x.doIt();
x.set(aa);
}
}

My HashMap has the correct data in it, my problem is the PluginSettingsFactory.

I think it's a simple problem, but I can't seem to find the root cause. Anyone with an idea? Thanks!

1 answer

1 accepted

1 vote
Answer accepted

For anyone with that problem, i found the solution.

@WithPlugin('com.atlassian.confluence.plugins.confluence-sal-plugin')
@PluginModule
PluginSettingsFactory pluginSettingsFactory;
PluginSettings pluginSettings = pluginSettingsFactory.createGlobalSettings();


Important to use the lines with @, needed some tome to find that out.

Yves Martin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 24, 2021 • edited

For Jira Server, replace with

@WithPlugin('com.atlassian.sal.jira')

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events