[java-plugin-shibd-oidc] 01/01: JSHIBDOIDC-31 - Support new CredentialResolver service
Codeberg
noreply at shibboleth.net
Tue Nov 17 17:48:59 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch dev/JSHIBDOIDC-31-cred-resolver
in repository java-plugin-shibd-oidc.
View the commit online:
https://codeberg.org/Shibboleth/java-plugin-shibd-oidc/commit/89516e618992cd774e5c818a18f49a6a105afdea
commit 89516e618992cd774e5c818a18f49a6a105afdea
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Tue Nov 17 16:15:23 2026 +0000
JSHIBDOIDC-31 - Support new CredentialResolver service
- Prevent the ClientSecretLookupStrategy from returning a key if there
is more than one matching credential. Adds some level of safety, so we
are not selecting abitrary keys from a result set. It does not gurantee
of course the secret is the correct secret for the OP. The resolvers
are responsible for that.
https://shibboleth.atlassian.net/browse/JSHIBDOIDC-31
---
.../credential/ClientSecretLookupStrategy.java | 46 +++++++++++++++-------
.../net/shibboleth/sp/oidc/conf/module.properties | 2 +-
.../impl/BasicSignatureSigningConfiguration.java | 2 +-
.../impl/ClientSecretStorageServiceResolver.java | 10 ++---
.../JWKSetCredentialStorageServiceResolver.java | 1 +
...Auth2ClientAuthenticationMethodHandlerTest.java | 37 +----------------
6 files changed, 41 insertions(+), 57 deletions(-)
diff --git a/sp-oidc-api/src/main/java/net/shibboleth/sp/jose/credential/ClientSecretLookupStrategy.java b/sp-oidc-api/src/main/java/net/shibboleth/sp/jose/credential/ClientSecretLookupStrategy.java
index 33b5f85..08fb993 100644
--- a/sp-oidc-api/src/main/java/net/shibboleth/sp/jose/credential/ClientSecretLookupStrategy.java
+++ b/sp-oidc-api/src/main/java/net/shibboleth/sp/jose/credential/ClientSecretLookupStrategy.java
@@ -14,6 +14,7 @@
package net.shibboleth.sp.jose.credential;
import java.nio.charset.StandardCharsets;
+import java.util.Iterator;
import java.util.function.Function;
import javax.annotation.Nonnull;
@@ -37,8 +38,9 @@ import net.shibboleth.shared.resolver.ResolverException;
* understand how to produce the correct credential.
*
* <p>
- * The strategy locates the first resolved credential containing a {@link javax.crypto.SecretKey} and converts the
- * secret value into a {@link ClientSecretCredential} suitable for client authentication.
+ * The strategy locates a resolved credential containing a {@link javax.crypto.SecretKey} and converts the
+ * secret value into a {@link ClientSecretCredential} suitable for client authentication. The credential must be
+ * unique, more than one credential will log an error and return {@code null}.
* </p>
*
*/
@@ -64,22 +66,36 @@ public class ClientSecretLookupStrategy implements Function<ProfileRequestContex
@Override
public ClientSecretCredential apply(final ProfileRequestContext profileReqestContex) {
try {
- // Choose the first for now
- for (final Credential cred : localCredResolver.resolve(new CriteriaSet())) {
- if (cred != null && cred.getSecretKey() != null) {
- // We know the client secret is UTF_8 encoded.
- // TODO long term there is no real benefit of converting this to a ClientSecretCredential other
- // than compatibility with the profile config interface
- final ClientSecretCredential credential = new DefaultClientSecretCredential(
- new String(cred.getSecretKey().getEncoded(), StandardCharsets.UTF_8));
- return credential;
- }
- }
+ final Iterable<Credential> credentialsItrbl = localCredResolver.resolve(new CriteriaSet());
+ final Iterator<Credential> credentialsItr = credentialsItrbl.iterator();
+
+ if (!credentialsItr.hasNext()) {
+ log.trace("Unable to resolve client secret");
+ return null;
+ }
+
+ final Credential cred = credentialsItr.next();
+
+ if (credentialsItr.hasNext()) {
+ log.error("Multiple client secret credentials resolved, check your resolver configuration");
+ return null;
+ }
+
+ if (cred != null && cred.getSecretKey() != null && cred.getSecretKey().getEncoded() != null) {
+ // OAuth/OIDC client_secrets are stored as UTF-8 strings and this strategy assumes only a client secret
+ // will be resolved.
+
+ // TODO long term there is no real benefit of converting this to a ClientSecretCredential other
+ // than compatibility with the profile config interface
+ return new DefaultClientSecretCredential(new String(cred.getSecretKey().getEncoded(),
+ StandardCharsets.UTF_8));
+ }
+
} catch (final ResolverException e) {
- log.error("Unable to resolve client password", e);
+ log.error("Unable to resolve client secret", e);
return null;
}
- log.trace("Unable to resolve client password");
+ log.trace("Unable to resolve the correct client secret, it did not contain a secret key");
return null;
}
diff --git a/sp-oidc-conf-impl/src/main/resources/net/shibboleth/sp/oidc/conf/module.properties b/sp-oidc-conf-impl/src/main/resources/net/shibboleth/sp/oidc/conf/module.properties
index 555efec..2a4130e 100644
--- a/sp-oidc-conf-impl/src/main/resources/net/shibboleth/sp/oidc/conf/module.properties
+++ b/sp-oidc-conf-impl/src/main/resources/net/shibboleth/sp/oidc/conf/module.properties
@@ -37,4 +37,4 @@ sp.OIDC.6.dest = bin/net.shibboleth.sp.oidc/lib/json-web-key-generator-0.8.2-jar
sp.OIDC.7.src = /net/shibboleth/idp/module/credentials/sp/client-secrets.txt
sp.OIDC.7.dest = credentials/sp/client-secrets.txt
-sp.OIDC.7.replace false
\ No newline at end of file
+sp.OIDC.7.replace = false
\ No newline at end of file
diff --git a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/BasicSignatureSigningConfiguration.java b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/BasicSignatureSigningConfiguration.java
index d9b0157..b48aca8 100644
--- a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/BasicSignatureSigningConfiguration.java
+++ b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/BasicSignatureSigningConfiguration.java
@@ -71,7 +71,7 @@ public class BasicSignatureSigningConfiguration
return hardwired;
}
- // Resolve if possible using: TODO
+ // Resolve if possible using:
// * UsageType = SIGNING
// * Protocol = if set
diff --git a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/credential/impl/ClientSecretStorageServiceResolver.java b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/credential/impl/ClientSecretStorageServiceResolver.java
index fc9b0f8..3267948 100644
--- a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/credential/impl/ClientSecretStorageServiceResolver.java
+++ b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/credential/impl/ClientSecretStorageServiceResolver.java
@@ -54,15 +54,15 @@ import net.shibboleth.shared.velocity.Template;
import net.shibboleth.sp.credential.AbstractStorageServiceCredentialResolver;
/**
- * A client secret credential resolver that resolves client secrets from the attached storage service into usable
+ * A client secret credential resolver that resolves client secrets from the configured storage service into usable
* cryptographic credentials.
*
* <p>This resolver has the following behaviour:</p>
* <ul>
* <li>Missing Criterion required to derive a suitable credential returns an empty list of credentials.</li>
- * <li>Asymmetric key requests, return an empty list if credentials.</li>
+ * <li>Asymmetric key requests return an empty list if credentials.</li>
* <li>Failure to derive a credential, throws an exception.</li>
- * <li>Otherwise, a suitable credential is derived for either SIGNING or ENCRYPTION use.</p>
+ * <li>Otherwise, a suitable credential is derived for either AUTHENTICATION, SIGNING, or ENCRYPTION use.</p>
* </ul>
*/
public class ClientSecretStorageServiceResolver extends AbstractStorageServiceCredentialResolver<Credential> {
@@ -194,8 +194,8 @@ public class ClientSecretStorageServiceResolver extends AbstractStorageServiceCr
}
/**
- * Use the usage type and algorithm information in the criteria to build a suitable signing or encryption
- * credential.
+ * Use the usage type and algorithm information in the criteria to build a suitable authentication, signing,
+ * or encryption credential.
*
* <p>Only supports symmetric key encryption algorithms. Request for asymmetric key encryption algorithms are
* ignored.</p>
diff --git a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/credential/impl/JWKSetCredentialStorageServiceResolver.java b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/credential/impl/JWKSetCredentialStorageServiceResolver.java
index b55b2c7..587bf9d 100644
--- a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/credential/impl/JWKSetCredentialStorageServiceResolver.java
+++ b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/credential/impl/JWKSetCredentialStorageServiceResolver.java
@@ -180,6 +180,7 @@ public class JWKSetCredentialStorageServiceResolver extends AbstractStorageServi
if (key != null) {
final BasicJWKCredentialFactoryBean factory = new BasicJWKCredentialFactoryBean();
// Need to serialize to be be compatible with the factory
+ // TODO this is a double parse. Performed by the JWKSet and the factory.
factory.setResource(new ByteArrayResource(key.toJSONString().getBytes(StandardCharsets.UTF_8)));
try {
factory.afterPropertiesSet();
diff --git a/sp-oidc-impl/src/test/java/net/shibboleth/sp/oidc/profile/impl/InitializeOAuth2ClientAuthenticationMethodHandlerTest.java b/sp-oidc-impl/src/test/java/net/shibboleth/sp/oidc/profile/impl/InitializeOAuth2ClientAuthenticationMethodHandlerTest.java
index 4c7ca67..dbc4fe0 100644
--- a/sp-oidc-impl/src/test/java/net/shibboleth/sp/oidc/profile/impl/InitializeOAuth2ClientAuthenticationMethodHandlerTest.java
+++ b/sp-oidc-impl/src/test/java/net/shibboleth/sp/oidc/profile/impl/InitializeOAuth2ClientAuthenticationMethodHandlerTest.java
@@ -18,12 +18,8 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import org.opensaml.messaging.handler.MessageHandlerException;
import org.opensaml.security.credential.BasicCredential;
-import org.opensaml.security.credential.Credential;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -38,13 +34,9 @@ import com.nimbusds.oauth2.sdk.auth.PrivateKeyJWT;
import net.shibboleth.oidc.authn.context.OAuth2ClientAuthenticationContext;
import net.shibboleth.oidc.profile.messaging.context.OIDCPeerEntityContext;
import net.shibboleth.oidc.security.credential.DefaultClientSecretCredential;
-import net.shibboleth.oidc.security.credential.JOSEObjectCredentialResolver;
import net.shibboleth.oidc.security.jose.SignatureSigningParameters;
import net.shibboleth.oidc.security.jose.context.SecurityParametersContext;
-import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
-import net.shibboleth.shared.resolver.CriteriaSet;
-import net.shibboleth.shared.resolver.ResolverException;
import net.shibboleth.sp.oidc.testing.TestConstants;
/** Tests for {@link InitializeOAuth2ClientAuthenticationMethodHandler}.*/
@@ -61,21 +53,7 @@ public class InitializeOAuth2ClientAuthenticationMethodHandlerTest extends BaseO
public void beforeMethod() throws ComponentInitializationException {
super.beforeMethod();
handler = new InitializeOAuth2ClientAuthenticationMethodHandler();
- handler.setClientSecretResolver(new JOSEObjectCredentialResolver() {
-
- @Override
- @Nullable public Credential resolveSingle(@Nullable final CriteriaSet criteria) throws ResolverException {
- final DefaultClientSecretCredential secret =
- new DefaultClientSecretCredential(CLIENT_SECRET, "client_secret_credential");
- return secret.toSigningCredential();
- }
-
- @Override
- @Nonnull public Iterable<Credential> resolve(@Nullable final CriteriaSet criteria) throws ResolverException {
- final Credential cred = resolveSingle(criteria);
- return cred != null ? CollectionSupport.singletonList(cred) : CollectionSupport.emptyList();
- }
- });
+ partyConfig.setClientCredential(new DefaultClientSecretCredential(CLIENT_SECRET, "client_secret_credential"));
}
@@ -101,18 +79,7 @@ public class InitializeOAuth2ClientAuthenticationMethodHandlerTest extends BaseO
@Test(expectedExceptions = MessageHandlerException.class)
public void testInitialiseClientSecretBasic_NoCredential() throws Exception {
- handler.setClientSecretResolver(new JOSEObjectCredentialResolver() {
-
- @Override
- @Nullable public Credential resolveSingle(@Nullable final CriteriaSet criteria) throws ResolverException {
- return null;
- }
-
- @Override
- @Nonnull public Iterable<Credential> resolve(@Nullable final CriteriaSet criteria) throws ResolverException {
- return CollectionSupport.emptyList();
- }
- });
+ partyConfig.setClientCredential(null);
partyConfig.setTokenEndpointAuthMethod("client_secret_basic");
partyConfig.setClientCredential(null);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list