Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jans-auth-server): generate description during built-in key rotation #1790 #2068

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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