[java-plugin-shibd-oidc] branch dev/JSHIBDOIDC-31-cred-resolver updated: JSHIBDOIDC-31 - Support new CredentialResolver service

Codeberg noreply at shibboleth.net
Tue Nov 17 16:15:43 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/30bb215cc9935f6b4c3a5d51ac19c890b31be4f6

The following commit(s) were added to refs/heads/dev/JSHIBDOIDC-31-cred-resolver by this push:
     new 30bb215  JSHIBDOIDC-31 - Support new CredentialResolver service
30bb215 is described below

commit 30bb215cc9935f6b4c3a5d51ac19c890b31be4f6
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     | 44 ++++++++++++++--------
 .../net/shibboleth/sp/oidc/conf/module.properties  |  2 +-
 .../JWKSetCredentialStorageServiceResolver.java    |  1 +
 3 files changed, 31 insertions(+), 16 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..3023e58 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,34 @@ 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) {
+				// 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
+            	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/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