Skip to content

Commit

Permalink
fix(jans-auth-server): generate description during built-in key rotat…
Browse files Browse the repository at this point in the history
…ion #1790

docs: no docs

#1790
  • Loading branch information
yuriyz committed Aug 9, 2022
1 parent a8b8d76 commit 1d26e1b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,9 @@ private JSONObject getJson(final Algorithm algorithm, final KeyPairGenerator key

JSONObject jsonObject = new JSONObject();

jsonObject.put(JWKParameter.KEY_TYPE, algorithm.getFamily());
algorithm.fill(jsonObject);

jsonObject.put(JWKParameter.KEY_ID, alias);
jsonObject.put(JWKParameter.KEY_USE, algorithm.getUse().getParamName());
jsonObject.put(JWKParameter.ALGORITHM, algorithm.getParamName());
jsonObject.put(JWKParameter.EXPIRATION_TIME, expirationTime);
if (publicKey instanceof RSAPublicKey) {
RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.jans.as.model.crypto.signature.AlgorithmFamily;
import io.jans.as.model.util.StringUtils;
import io.jans.as.model.crypto.signature.RSAKeyFactory;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -135,6 +136,14 @@ public boolean canGenerateKeys() { // based on currently supported generator, se
return family == AlgorithmFamily.RSA || family == AlgorithmFamily.EC || family == AlgorithmFamily.ED;
}

public void fill(JSONObject jsonObject) {
jsonObject.put(JWKParameter.NAME, getOutName());
jsonObject.put(JWKParameter.DESCRIPTION, getDescription());
jsonObject.put(JWKParameter.KEY_TYPE, getFamily());
jsonObject.put(JWKParameter.KEY_USE, getUse().getParamName());
jsonObject.put(JWKParameter.ALGORITHM, getParamName());
}

/**
* Returns the corresponding {@link Algorithm} for a parameter.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.jans.as.model.jwk;

import org.json.JSONObject;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

/**
* @author Yuriy Zabrovarnyy
*/
public class AlgorithmTest {

@Test
public void fill_whenCalled_shouldPutCorrectClaims() {
JSONObject jsonObject = new JSONObject();

Algorithm.RS256.fill(jsonObject);

assertEquals(Algorithm.RS256.getOutName(), jsonObject.getString("name"));
assertEquals(Algorithm.RS256.getDescription(), jsonObject.getString("descr"));
assertEquals(Algorithm.RS256.getUse().getParamName(), jsonObject.getString("use"));
assertEquals(Algorithm.RS256.getParamName(), jsonObject.getString("alg"));
}
}
5 changes: 5 additions & 0 deletions jans-auth-server/model/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="oxAuthModel" parallel="false">
<test name="Unit Tests" enabled="true">
<classes>
<class name="io.jans.as.model.jwk.AlgorithmTest"/>
</classes>
</test>
<test name="Code Verifier (PKCE)" enabled="true">
<classes>
<class name="io.jans.as.model.authorize.CodeVerifierTest"/>
Expand Down

0 comments on commit 1d26e1b

Please sign in to comment.