[java-plugin-shibd-oidc] 01/01: JSHIBDOIDC-31 - Support new CredentialResolver service
Codeberg
noreply at shibboleth.net
Tue Nov 17 17:43:19 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/233faf03a8df80404313cea39e44c088ddb0dbf3
commit 233faf03a8df80404313cea39e44c088ddb0dbf3
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 +
5 files changed, 39 insertions(+), 22 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();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list