Skip to content

Commit

Permalink
feat(jans-auth-server): improve client assertion creation code (Clien…
Browse files Browse the repository at this point in the history
…tAuthnRequest) #1182
  • Loading branch information
yuriyz committed Jul 5, 2022
1 parent b3b3d22 commit 81946b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text.
*
* Copyright (c) 2020, Janssen Project
* Copyright (c) 2022, Janssen Project
*/

package io.jans.as.client;
Expand Down Expand Up @@ -86,14 +86,18 @@ public void appendClientAuthnToQuery(QueryBuilder builder) {
}
}

public SignatureAlgorithm getFallbackAlgorithm() {
return StringUtils.isBlank(keyId) ? SignatureAlgorithm.HS256 : SignatureAlgorithm.RS256;
}

public String getClientAssertion() {
if (cryptoProvider == null) {
LOG.error("Crypto provider is not specified");
return null;
}

if (algorithm == null) {
algorithm = SignatureAlgorithm.HS256;
algorithm = getFallbackAlgorithm();
}

GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.jans.as.client;

import io.jans.as.model.crypto.signature.SignatureAlgorithm;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

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

@Test
public void getFallbackAlgorithm_whenKidIsBlank_shouldReturnHS256() {
ClientAuthnRequest request = new TestClientAuthnRequest();
assertEquals(request.getFallbackAlgorithm(), SignatureAlgorithm.HS256);
}

@Test
public void getFallbackAlgorithm_whenKidIsNotBlank_shouldReturnRS256() {
ClientAuthnRequest request = new TestClientAuthnRequest();
request.setKeyId("testKid");
assertEquals(request.getFallbackAlgorithm(), SignatureAlgorithm.RS256);
}

public static class TestClientAuthnRequest extends ClientAuthnRequest {
@Override
public String getQueryString() {
return "";
}
}
}

0 comments on commit 81946b2

Please sign in to comment.