[java-idp-oidc] 01/02: Reduced dependency on ValidateGrantTest in building test tokens.
Henri Mikkonen
henri.mikkonen at iki.fi
Fri Apr 28 13:41:40 UTC 2023
This is an automated email from the git hooks/post-receive script.
hjmikkon pushed a commit to branch main
in repository java-idp-oidc.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=dfbb9f239fac8c1bef7bcff2bfe89b57d9a92563
commit dfbb9f239fac8c1bef7bcff2bfe89b57d9a92563
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Apr 28 13:49:24 2023 +0300
Reduced dependency on ValidateGrantTest in building test tokens.
---
.../plugin/oidc/op/profile/flow/TokenFlowTest.java | 57 +++++++++++++++++-----
1 file changed, 45 insertions(+), 12 deletions(-)
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
index d150cd21..1abf72c6 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
@@ -566,10 +566,26 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
return new RefreshToken(getDataSealer().wrap(json, Instant.now().plusSeconds(30))).getValue();
}
+ protected TokenClaimsSet buildDefaultClaimsSet(final String clientId, final Collection<String> aud)
+ throws Exception {
+ final Instant now = Instant.now();
+ final AuthorizeCodeClaimsSet.Builder builder = new AuthorizeCodeClaimsSet.Builder();
+ builder.setJWTID(new SecureRandomIdentifierGenerationStrategy())
+ .setClientID(new ClientID(clientId))
+ .setIssuer(issuer)
+ .setPrincipal("jdoe")
+ .setSubject("mock")
+ .setIssuedAt(now)
+ .setExpiresAt(now.plusSeconds(100))
+ .setAuthenticationTime(now)
+ .setRedirectURI(new URI(redirectUri))
+ .setAudience(aud)
+ .setScope(scope == null ? new Scope() : scope);
+ return builder.build();
+ }
protected String buildRefreshToken(final String clientId, final String id, final String rootId,
final Collection<String> aud, final String... consentedClaims) throws Exception {
- final TokenClaimsSet acClaims = ValidateGrantTest.buildTokenClaimsSet(clientId, "https://op.example.org", "jdoe", "mock", redirectUri,
- null, null, null, null, scope.toString(), aud);
+ final TokenClaimsSet acClaims = buildDefaultClaimsSet(clientId, aud);
final RefreshTokenClaimsSet rtClaims = new RefreshTokenClaimsSet.Builder(acClaims, Instant.now(),
Instant.now().plus(Duration.ofHours(1)))
.setRootTokenIdentifier(rootId)
@@ -580,8 +596,7 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
protected String buildRefreshTokenWithSid(final String clientId, final String id, final String rootId,
final Collection<String> aud, final String sid, final String... consentedClaims) throws Exception {
- final TokenClaimsSet acClaims = ValidateGrantTest.buildTokenClaimsSet(clientId, "https://op.example.org", "jdoe", "mock", redirectUri,
- null, null, null, null, scope.toString(), aud);
+ final TokenClaimsSet acClaims = buildDefaultClaimsSet(clientId, aud);
final RefreshTokenClaimsSet rtClaims = new RefreshTokenClaimsSet.Builder(acClaims, Instant.now(),
Instant.now().plus(Duration.ofHours(1)))
.setRootTokenIdentifier(rootId)
@@ -985,12 +1000,31 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
return launchWithJwtAuthentication(authnMethod, algorithm, null);
}
+ protected static String buildAuthorizationCode(final String clientId, final String issuer,
+ final String userPrincipal, final String sub, final String callbackUrl, final String scope,
+ final Collection<String> aud) throws Exception {
+ final Instant now = Instant.now();
+ final AuthorizeCodeClaimsSet.Builder builder = new AuthorizeCodeClaimsSet.Builder();
+ builder.setJWTID(new SecureRandomIdentifierGenerationStrategy())
+ .setClientID(new ClientID(clientId))
+ .setIssuer(issuer)
+ .setPrincipal(userPrincipal)
+ .setSubject(sub)
+ .setIssuedAt(now)
+ .setExpiresAt(now.plusSeconds(100))
+ .setAuthenticationTime(now)
+ .setRedirectURI(new URI(callbackUrl))
+ .setAudience(aud)
+ .setScope(scope == null ? new Scope() : Scope.parse(scope));
+ final TokenClaimsSet acClaims = builder.build();
+ return new AuthorizationCode(acClaims.serialize(new ValidateGrantTest().getDataSealer())).getValue();
+ }
+
protected FlowExecutionResult launchWithJwtAuthentication(final JWTAuthentication authnMethod, final JWSAlgorithm algorithm,
final String requestedScope)
throws Exception {
- final String code = ValidateGrantTest.buildAuthorizationCode(clientId, "https://op.example.org", "jdoe"
- , "mock",
- redirectUri, scope.toString()).toString();
+ final String code = buildAuthorizationCode(clientId, "https://op.example.org", "jdoe", "mock",
+ redirectUri, scope.toString(), null).toString();
storeMetadata(storageService, clientId, clientSecret, scope, JWSAlgorithm.HS256,
ClientAuthenticationMethod.CLIENT_SECRET_JWT);
final Map<String, String> requestParameters =
@@ -1024,9 +1058,8 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
final OIDCClientMetadata metadata, final String clientSecret, final StorageService storageService)
throws Exception {
final String clientId = authnMethod.getClientID().getValue();
- final String code = ValidateGrantTest.buildAuthorizationCode(clientId, "https://op.example.org", "jdoe"
- , "mock",
- redirectUri, scope.toString()).toString();
+ final String code = buildAuthorizationCode(clientId, "https://op.example.org", "jdoe", "mock",
+ redirectUri, scope.toString(), null).toString();
storeMetadataObject(storageService, clientId, clientSecret, metadata);
final Map<String, String> requestParameters =
createRequestParameters(redirectUri, "authorization_code", code, clientId);
@@ -1038,8 +1071,8 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
protected FlowExecutionResult launchWithJwtAuthentication(final JWT jwt, final JWSAlgorithm algorithm,
final ClientAuthenticationMethod method, final PublicKey publicKey) throws Exception {
- final String code = ValidateGrantTest.buildAuthorizationCode(clientId, "https://op.example.org", "jdoe", "mock",
- redirectUri, scope.toString()).toString();
+ final String code = buildAuthorizationCode(clientId, "https://op.example.org", "jdoe", "mock",
+ redirectUri, scope.toString(), null).toString();
if (publicKey == null) {
storeMetadata(storageService, clientId, clientSecret, scope, algorithm, method);
} else {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list