[java-plugin-shibd-oidc] 01/07: JSHIBDOIDC-31 - Support new CredentialResolver service

Codeberg noreply at shibboleth.net
Tue Nov 17 15:26:07 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/f767029a5ede294935ec9bde1b2ae3099fcb1bac

commit f767029a5ede294935ec9bde1b2ae3099fcb1bac
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed Jul 29 17:32:33 2026 +0100

    JSHIBDOIDC-31 - Support new CredentialResolver service
    
     - Use the CredentialResolver via the signing config bridge
     - No change yet to pulling the client_secret from the profile config.
    this only replaces the assymetric keys.
     - this works, but the StaticFilteringCriterionCredentialResolver needs
    more explaining, and there is criterion filtering happening at a number
    of overlapping levels e.g. StaticFilteringCriterionCredentialResolver
    and LocalJOSEObjectCredentialResolver which needs to be cleaned up.
    
    https://shibboleth.atlassian.net/browse/JSHIBDOIDC-31
---
 pom.xml                                            |   5 +
 .../net/shibboleth/sp/oidc/testing/TestHelper.java |  38 ++++++-
 sp-oidc-conf-impl/pom.xml                          |   5 +
 .../META-INF/net.shibboleth.idp/postconfig.xml     |   2 +-
 .../net/shibboleth/sp/service/agent/postconfig.xml | 123 +++++++++++++--------
 .../sp/service/credentials/postconfig.xml          |  46 ++++++++
 .../flows/AbstractOIDCTokenConsumerFlowTest.java   |   7 +-
 .../oidc/flows/OIDCSessionInitiatorFlowTest.java   |  10 +-
 .../sp/oidc/flows/OIDCTokenConsumerFlowTest.java   |  68 +++++++++++-
 .../src/test/resources/logback-flow-test.xml       |   4 +
 .../idp/module/conf/sp/oidc-credentials.xml        |   2 +
 .../net/shibboleth/sp/oidc-test-beans.xml          |   1 +
 sp-oidc-impl/pom.xml                               |   5 +
 .../impl/BasicSignatureSigningConfiguration.java   |  95 ++++++++++++++++
 ...StaticFilteringCriterionCredentialResolver.java | 119 ++++++++++++++++++++
 15 files changed, 475 insertions(+), 55 deletions(-)

diff --git a/pom.xml b/pom.xml
index 687fd02..a957931 100644
--- a/pom.xml
+++ b/pom.xml
@@ -163,6 +163,11 @@ copyright/license information. -->
                 <groupId>${oidc-common.groupId}</groupId>
                 <artifactId>oidc-common-profile-impl</artifactId>
                 <version>${oidc-common.version}</version>
+            </dependency>            
+            <dependency>
+                <groupId>${oidc-common.groupId}</groupId>
+                <artifactId>oidc-common-saml-api</artifactId>
+                <version>${oidc-common.version}</version>
             </dependency>
             <!-- Import Dependencies: Shib-Metadata/Attribute/Profile -->
             <dependency>
diff --git a/sp-oidc-api/src/test/java/net/shibboleth/sp/oidc/testing/TestHelper.java b/sp-oidc-api/src/test/java/net/shibboleth/sp/oidc/testing/TestHelper.java
index 2cdc89b..28290c8 100644
--- a/sp-oidc-api/src/test/java/net/shibboleth/sp/oidc/testing/TestHelper.java
+++ b/sp-oidc-api/src/test/java/net/shibboleth/sp/oidc/testing/TestHelper.java
@@ -273,6 +273,31 @@ public final class TestHelper {
     @Nonnull public static JWT createJWT(@Nonnull final JWTClaimsSet payload, @Nullable final JWSAlgorithm sigAlg, 
             @Nullable final JWEAlgorithm jweAlg, @Nullable final EncryptionMethod enc, 
             @Nullable final Credential sigKey, @Nullable final Credential encKey) throws JOSEException, ParseException {
+    	return createJWT(payload, sigAlg, jweAlg, enc, sigKey, encKey, null);
+    }
+    
+    /**
+     * Create a JWT from the given payload. The JWT can either be plain, or signed and encrypted. If encrypted, it must
+     * be signed. 
+     * 
+     * @param payload the payload to create the JWT from
+     * @param sigAlg the signature alg to use. {@code Null} if the JWT is not going to be signed and/or encrypted.
+     * @param jweAlg the encryption alg to use. {@code Null} if the JWT is not going to be encrypted. Note, if encrypted
+     *                  the signature algorithm must also be supplied, otherwise a plain JWT will be returned.
+     * @param enc the content encryption algorithm to use.
+     * @param sigKey the key to use for signing
+     * @param encKey the key to use for encryption
+     * @param encKeyKid the keyID for the encryption key to add to the header.
+     * 
+     * @return and plain JWT, JWS, or JWE.
+     * 
+     * @throws JOSEException on error.
+     * @throws ParseException on error.
+     */
+    @Nonnull public static JWT createJWT(@Nonnull final JWTClaimsSet payload, @Nullable final JWSAlgorithm sigAlg, 
+            @Nullable final JWEAlgorithm jweAlg, @Nullable final EncryptionMethod enc, 
+            @Nullable final Credential sigKey, @Nullable final Credential encKey, @Nullable final String encKeyKid) 
+            		throws JOSEException, ParseException {
         
         // Sign first.
         if (sigAlg != null && sigKey != null) {
@@ -290,11 +315,22 @@ public final class TestHelper {
             }
             
             if (jweAlg != null && encKey != null) {
-                final JWEObject jweObject = 
+            	JWEObject jweObject = null;
+            	if (encKeyKid != null) {
+            		jweObject = 
+                            new JWEObject(new JWEHeader.Builder(jweAlg, enc)
+                            .contentType("JWT")
+                            .keyID(encKeyKid)
+                            .build(),
+                            new Payload(signedJWT));
+            	}
+            	else{
+            		jweObject = 
                         new JWEObject(new JWEHeader.Builder(jweAlg, enc)
                         .contentType("JWT")
                         .build(),
                         new Payload(signedJWT));
+            	}
                 
                 if (JWEAlgorithm.Family.RSA.contains(jweAlg)) {                    
                     jweObject.encrypt(new RSAEncrypter((RSAPublicKey)encKey.getPublicKey()));                    
diff --git a/sp-oidc-conf-impl/pom.xml b/sp-oidc-conf-impl/pom.xml
index fcfd3f5..13f2fce 100644
--- a/sp-oidc-conf-impl/pom.xml
+++ b/sp-oidc-conf-impl/pom.xml
@@ -118,6 +118,11 @@
             <artifactId>oidc-common-profile-impl</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>${oidc-common.groupId}</groupId>
+            <artifactId>oidc-common-saml-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
         
         <dependency>
             <groupId>${opensaml.groupId}</groupId>
diff --git a/sp-oidc-conf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml b/sp-oidc-conf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
index 31b28c5..85f8262 100644
--- a/sp-oidc-conf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
+++ b/sp-oidc-conf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
@@ -102,7 +102,7 @@
         c:_0="token" c:_1="SAML:" /> -->
     
     <bean p:id="sp/logout/consumer/oidc/redirect" class="net.shibboleth.sp.profile.BasicLogoutConsumerFlowDescriptor">
-       <!--  <property name="activationCondition">
+       <!-- TODO  <property name="activationCondition">
             <bean parent="shibboleth.Conditions.OR">
                 <constructor-arg>
                     <list>
diff --git a/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/agent/postconfig.xml b/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/agent/postconfig.xml
index b532471..4d6af18 100644
--- a/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/agent/postconfig.xml
+++ b/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/agent/postconfig.xml
@@ -52,32 +52,11 @@
         p:httpClient="#{getObject('%{sp.oidc.HttpClient:}') ?: getObject('shibboleth.InternalHttpClient')}"
         p:httpClientSecurityParameters="#{getObject('%{sp.oidc.httpClientSecurityParameters:}')}" />
     
-    <!-- 
-        Security Configuration Defaults. These settings establish the default security configurations for 
-        signatures and loads the default credentials used. 
-    --> 
-   <bean id="shibboleth.oidc.BasicSignatureValidationConfiguration" abstract="true"
-        class="net.shibboleth.oidc.security.jose.impl.BasicSignatureValidationConfiguration"
-        p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedSignatureAlgorithms')}"
-        p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedSignatureAlgorithms')}" />
-    
-    <bean id="shibboleth.oidc.BasicSignatureSigningConfiguration" abstract="true"
-        class="net.shibboleth.oidc.security.jose.impl.BasicSignatureSigningConfiguration"
-        p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedSignatureAlgorithms')}"
-        p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedSignatureAlgorithms')}" />
-    
-    <bean id="shibboleth.oidc.BasicEncryptionConfiguration" abstract="true"
-        class="net.shibboleth.oidc.security.jose.impl.BasicEncryptionConfiguration"
-        p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedEncryptionAlgorithms')}"
-        p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedEncryptionAlgorithms')}" />
-
-    <bean id="shibboleth.oidc.BasicDecryptionConfiguration" abstract="true"
-        class="net.shibboleth.oidc.security.jose.impl.BasicDecryptionConfiguration"
-        p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedEncryptionAlgorithms')}"
-        p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedEncryptionAlgorithms')}" />
+        
+    <!--  Profile Beans -->
     
     <bean id="AbstractOIDCProfile" abstract="true"
-        p:securityConfiguration-ref="%{sp.security.oidc.config:shibboleth.oidc.DefaultSecurityConfiguration}" />
+        p:securityConfiguration-ref="%{sp.oidc.security.config:shibboleth.oidc.DefaultSecurityConfiguration}" />
 
     <bean id="AbstractOIDCSSOProfile" parent="AbstractOIDCProfile" abstract="true" 
         p:issuer="#{getObject('shibboleth.oidc.issuer')}"        
@@ -128,6 +107,43 @@
         
     <util:constant id="OIDC.SSO.FEATURE_SCOPE"
         static-field="net.shibboleth.oidc.profile.config.OIDCAuthorizationConfiguration.FEATURE_SCOPE"/>
+        
+    <!-- 
+        Security Configuration Defaults. These settings establish the default security configurations for 
+        signatures and loads the default credentials used. 
+    --> 
+   <bean id="shibboleth.oidc.BasicSignatureValidationConfiguration" abstract="true"
+        class="net.shibboleth.oidc.security.jose.impl.BasicSignatureValidationConfiguration"
+        p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedSignatureAlgorithms')}"
+        p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedSignatureAlgorithms')}" />
+    
+    <bean id="shibboleth.oidc.BasicSignatureSigningConfiguration" abstract="true"
+        class="net.shibboleth.oidc.security.jose.impl.BasicSignatureSigningConfiguration"
+        p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedSignatureAlgorithms')}"
+        p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedSignatureAlgorithms')}" />
+    
+    <bean id="shibboleth.oidc.BasicEncryptionConfiguration" abstract="true"
+        class="net.shibboleth.oidc.security.jose.impl.BasicEncryptionConfiguration"
+        p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedEncryptionAlgorithms')}"
+        p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedEncryptionAlgorithms')}" />
+
+    <bean id="shibboleth.oidc.BasicDecryptionConfiguration" abstract="true"
+        class="net.shibboleth.oidc.security.jose.impl.BasicDecryptionConfiguration"
+        p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedEncryptionAlgorithms')}"
+        p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedEncryptionAlgorithms')}" />
+        
+   
+    <!-- 
+        Bridging beans to link the basic security configuration to the CredentialResolver service to aquire credentials 
+    -->
+   
+    <bean id="shibboleth.sp.oidc.BasicSignatureSigningConfiguration" parent="shibboleth.oidc.BasicSignatureSigningConfiguration"
+        class="net.shibboleth.sp.jose.config.impl.BasicSignatureSigningConfiguration"
+        c:resolver-ref="shibboleth.sp.CredentialResolverBridge" />
+        
+   <!-- 
+        Security configuration beans.
+    -->
     
     <bean id="shibboleth.oidc.DefaultSecurityConfiguration"
         class="net.shibboleth.oidc.profile.config.JSONSecurityConfiguration" c:clockSkew="%{sp.policy.clockSkew:PT1M}">
@@ -141,22 +157,21 @@
                 </bean>
         </constructor-arg>
         <property name="jwtSignatureSigningConfiguration">
-            <ref bean="#{'%{sp.oidc.signing.config:shibboleth.oidc.SigningConfiguration}'.trim()}" />
+            <ref bean="#{'%{sp.oidc.signing.config:shibboleth.sp.oidc.SigningConfiguration}'.trim()}" />
         </property>
         <property name="jwtEncryptionConfiguration">
-            <ref bean="#{'%{sp.oidc.encryption.config:shibboleth.oidc.EncryptionConfiguration}'.trim()}" />
+            <ref bean="#{'%{sp.oidc.encryption.config:shibboleth.sp.oidc.EncryptionConfiguration}'.trim()}" />
         </property>
         <property name="jwtDecryptionConfiguration">
-            <ref bean="#{'%{sp.oidc.decryption.config:shibboleth.oidc.DecryptionConfiguration}'.trim()}" />
+            <ref bean="#{'%{sp.oidc.decryption.config:shibboleth.sp.oidc.DecryptionConfiguration}'.trim()}" />
         </property>
         <property name="jwtSignatureValidationConfiguration">
-            <ref bean="#{'%{sp.oidc.validation.config:shibboleth.oidc.SignatureValidationConfiguration}'.trim()}" />
+            <ref bean="#{'%{sp.oidc.validation.config:shibboleth.sp.oidc.SignatureValidationConfiguration}'.trim()}" />
         </property>
     </bean>
     
-    <bean id="shibboleth.oidc.SigningConfiguration"
-        parent="shibboleth.oidc.BasicSignatureSigningConfiguration"
-        p:signingCredentials-ref="shibboleth.oidc.SigningCredentialsFactory">
+    <bean id="shibboleth.sp.oidc.SigningConfiguration"
+        parent="shibboleth.sp.oidc.BasicSignatureSigningConfiguration">
         <property name="signatureAlgorithms">
             <list>
                 <util:constant
@@ -187,7 +202,7 @@
         </property>
     </bean>
 
-    <bean id="shibboleth.oidc.EncryptionConfiguration" parent="shibboleth.oidc.BasicEncryptionConfiguration"
+    <bean id="shibboleth.sp.oidc.EncryptionConfiguration" parent="shibboleth.oidc.BasicEncryptionConfiguration"
         p:KEKCredentialResolver-ref="defaultOIDCKeyEncryptionCredentialResolver"
         p:contentEncryptionKeyCredentialResolver-ref="defaultOIDCContentEncryptionKeyCredentialResolver">
         <property name="keyTransportEncryptionAlgorithms">
@@ -241,16 +256,11 @@
             </list>
         </property>
     </bean>
-    
-    <bean id="shibboleth.oidc.SigningCredentialsFactory"
-        class="net.shibboleth.oidc.profile.config.CredentialsListFactory"
-        c:_0="#{getObject('shibboleth.oidc.SigningCredentials')}" />
         
     <bean id="defaultOIDCKeyEncryptionCredentialResolver"
         class="net.shibboleth.oidc.security.credential.impl.ChainingJOSEObjectCredentialResolver">
         <constructor-arg>
             <list>
-                <!--  Used by the RP -->
                 <bean id="OIDCProviderMetadataCredentialResolver"
                     class="net.shibboleth.oidc.security.credential.impl.ProviderMetadataCredentialResolver"
                     c:remoteJwkSetCache-ref="shibboleth.oidc.RemoteJwkSetCache"
@@ -265,14 +275,13 @@
         class="net.shibboleth.oidc.security.credential.impl.ChainingJOSEObjectCredentialResolver">
         <constructor-arg>
             <list>
-                <!--  Used by the RP -->
                 <bean id="ClientSecretCriterionCredentialResolver"
                     class="net.shibboleth.oidc.security.credential.impl.ClientSecretCriterionCredentialResolver"/>
             </list>
         </constructor-arg>
     </bean>   
     
-    <bean id="shibboleth.oidc.DecryptionConfiguration"
+    <bean id="shibboleth.sp.oidc.DecryptionConfiguration"
         parent="shibboleth.oidc.BasicDecryptionConfiguration"
         p:KEKCredentialResolver-ref="defaultOIDCKeyDecryptionCredentialResolver"
         p:contentEncryptionKeyCredentialResolver-ref="defaultOIDCContentDecryptionKeyCredentialResolver">
@@ -281,18 +290,41 @@
     <!-- 
         A resolver to public/private key encryption keys global to the RP 
     -->
+    
+    
+    
     <bean id="defaultOIDCKeyDecryptionCredentialResolver"
         class="net.shibboleth.oidc.security.credential.impl.ChainingJOSEObjectCredentialResolver">
         <constructor-arg>
             <list>
-                <bean class="net.shibboleth.oidc.security.credential.impl.LocalJOSEObjectCredentialResolver">
+            <!-- 
+                This resolver pulls out keys from JWT headers and matches them to local credentials. In addition, 
+                it adds local credentials if none are present in the headers, using the keyId, if present, for 
+                credential resolvers to use in matching local keys.
+             -->
+                <bean id="localDecryptionCredentialResolver" 
+                    class="net.shibboleth.oidc.security.credential.impl.LocalJOSEObjectCredentialResolver">
                     <constructor-arg name="localCredentialResolver">
-                        <bean
-                            class="net.shibboleth.oidc.security.credential.impl.CollectionJOSEObjectCredentialResolver"
-                            c:credentials-ref="shibboleth.oidc.EncryptionCredentials" />
+                            <!-- This bridge resolves decryption keys using the CredentialResolver service while adding needed criteria. -->
+						    <bean id="localDecryptionKEKResolver" class="net.shibboleth.sp.jose.config.impl.StaticFilteringCriterionCredentialResolver"
+						            c:resolver-ref="shibboleth.sp.CredentialResolverBridge">
+						        <constructor-arg name="criteria">
+						            <set>
+						                <bean class="org.opensaml.security.criteria.UsageCriterion">
+						                    <constructor-arg>
+						                        <util:constant static-field="org.opensaml.security.credential.UsageType.ENCRYPTION" />
+						                    </constructor-arg>
+						                </bean>
+						                <bean class="org.opensaml.saml.criterion.ProtocolCriterion">
+						                    <constructor-arg>
+						                        <util:constant static-field="net.shibboleth.oidc.saml.xmlobject.Constants.OIDC_PROTOCOL_URI" />
+						                    </constructor-arg>
+						                </bean>
+						            </set>
+						        </constructor-arg>
+						    </bean>
                     </constructor-arg>
                 </bean>
-                <!--  Used by the RP -->
                 <bean id="CriterionCredentialResolver"
                     class="net.shibboleth.oidc.security.credential.impl.ClientSecretCriterionCredentialResolver"/>
             </list>
@@ -310,7 +342,7 @@
         </constructor-arg>
     </bean>    
     
-    <bean id="shibboleth.oidc.SignatureValidationConfiguration" 
+    <bean id="shibboleth.sp.oidc.SignatureValidationConfiguration" 
         parent="shibboleth.oidc.BasicSignatureValidationConfiguration"
         p:signatureTrustEngine-ref="ExplicitKeySignedJWTTrustEngine"/>
         
@@ -325,6 +357,7 @@
         class="net.shibboleth.oidc.security.credential.impl.BasicJOSEObjectCredentialResolver" />
     
      <!-- A resolver for resolving trusted credentials to match against those resolved from the JWT -->
+     <!-- TODO the client_secret credential should come from the new credential resolver -->
     <bean id="defaultSignedJWTTrustedCredentialResolver"
         class="net.shibboleth.oidc.security.credential.impl.ChainingJOSEObjectCredentialResolver">
         <constructor-arg>
diff --git a/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/credentials/postconfig.xml b/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/credentials/postconfig.xml
new file mode 100644
index 0000000..67eab5f
--- /dev/null
+++ b/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/sp/service/credentials/postconfig.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xmlns:p="http://www.springframework.org/schema/p"
+       xmlns:c="http://www.springframework.org/schema/c"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+                           
+       default-init-method="initialize"
+       default-destroy-method="destroy">
+
+    <!-- Installs a "default" set of OIDC credentials into the resolver service. -->
+    
+    <bean id="shibboleth.sp.oidc.DefaultCredentialResolver" class="net.shibboleth.sp.credential.impl.StaticCredentialResolver"
+            c:_0="#{getObject('shibboleth.sp.oidc.DefaultCredentials') ?: getObject('DefaultCredentials')}">
+        <property name="protocols">
+            <util:constant static-field="net.shibboleth.oidc.saml.xmlobject.Constants.OIDC_PROTOCOL_URI" />
+        </property>
+    </bean>
+    
+    <bean id="DefaultCredentials" class="org.springframework.beans.factory.config.ListFactoryBean" lazy-init="true">
+        <property name="sourceList">
+            <list>
+                    
+                 <!-- TODO p:usageType comes from the JWK use, not that specified, maybe this should be overriden if specified -->
+                <bean id="shibboleth.oidc.DefaultRSSigningCredential" 
+					parent="shibboleth.oidc.JWKCredential"
+					p:resource="%{sp.oidc.signing.rs.key:#{null}}" 
+					p:throwIfNull="false" />
+
+			    <bean id="shibboleth.oidc.DefaultESSigningCredential" 
+					parent="shibboleth.oidc.JWKCredential"
+					p:resource="%{sp.oidc.signing.es.key:#{null}}" 
+					p:throwIfNull="false" />
+
+			    <bean id="shibboleth.oidc.DefaultRSAEncryptionCredential" 
+					parent="shibboleth.oidc.JWKCredential"
+					p:resource="%{sp.oidc.encryption.rsa.key:#{null}}" p:throwIfNull="false" />
+            </list>
+        </property>
+    </bean>
+
+</beans>
\ No newline at end of file
diff --git a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/AbstractOIDCTokenConsumerFlowTest.java b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/AbstractOIDCTokenConsumerFlowTest.java
index 6a75ad2..fd136a5 100644
--- a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/AbstractOIDCTokenConsumerFlowTest.java
+++ b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/AbstractOIDCTokenConsumerFlowTest.java
@@ -200,13 +200,16 @@ public abstract class AbstractOIDCTokenConsumerFlowTest extends AbstractSPFlowTe
      * @param expiry expiry time
      * @param issuedAt issue time
      * @param nonce the nonce
+     * @param additionalClaims any additional claims
+     * @param encKeyId the KeyID of the encryption key to add to the headers
+     * 
      * @return the tokens
      * @throws ParseException 
      * @throws JOSEException 
      */
     protected OIDCTokenResponse constructSuccessfulTokenResponseSignedAndEncrypted(
             @Nonnull final Instant expiry, @Nonnull final Instant issuedAt, @Nullable final String nonce,
-            @Nullable final Map<String, Object> additionalClaims) 
+            @Nullable final Map<String, Object> additionalClaims, @Nullable final String encKeyId) 
                     throws JOSEException, ParseException {
 
          final JWTClaimsSet.Builder claimsSetBuilder = new JWTClaimsSet.Builder()
@@ -228,7 +231,7 @@ public abstract class AbstractOIDCTokenConsumerFlowTest extends AbstractSPFlowTe
          
          final JWT encryptedIdToken = 
                  TestHelper.createJWT(claimsSet, JWSAlgorithm.RS256, JWEAlgorithm.RSA_OAEP_256, 
-                         EncryptionMethod.A128CBC_HS256, opSigningCredential, rpEncryptionCredential);
+                         EncryptionMethod.A128CBC_HS256, opSigningCredential, rpEncryptionCredential, encKeyId);
          
          final AccessToken accessToken = new BearerAccessToken("fake-access-token-value", 3600, null);
          final RefreshToken refreshToken = new RefreshToken("fake-refresh-token-value");
diff --git a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCSessionInitiatorFlowTest.java b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCSessionInitiatorFlowTest.java
index 5cac87e..cd68a20 100644
--- a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCSessionInitiatorFlowTest.java
+++ b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCSessionInitiatorFlowTest.java
@@ -228,7 +228,7 @@ public class OIDCSessionInitiatorFlowTest extends AbstractSPFlowTest {
      * @throws MessageDecodingException 
      */
     @Test
-    public void testFlowWithState() throws IOException, MessageDecodingException {
+    public void testFlowWithState_WithRO() throws IOException, MessageDecodingException {
         setDefaultAuth();
         
         final DDF input = new DDF(null).structure();
@@ -251,7 +251,7 @@ public class OIDCSessionInitiatorFlowTest extends AbstractSPFlowTest {
      * @throws Exception on error
      */
     @Test
-    public void testForceAuthnFromAgent() throws Exception {
+    public void testForceAuthnFromAgent_WithRO() throws Exception {
         setDefaultAuth();
         
         final DDF input = new DDF(null).structure();
@@ -276,7 +276,7 @@ public class OIDCSessionInitiatorFlowTest extends AbstractSPFlowTest {
      * @throws Exception on error
      */
     @Test
-    public void testMaxAgeFromAgent() throws Exception {
+    public void testMaxAgeFromAgent_WithRO() throws Exception {
         setDefaultAuth();
         
         final DDF input = new DDF(null).structure();
@@ -300,7 +300,7 @@ public class OIDCSessionInitiatorFlowTest extends AbstractSPFlowTest {
      * @throws Exception on error 
      */
     @Test
-    public void testPromptFromAgent() throws Exception {
+    public void testPromptFromAgent_WithRO() throws Exception {
         setDefaultAuth();
         
         final DDF input = new DDF(null).structure();
@@ -324,7 +324,7 @@ public class OIDCSessionInitiatorFlowTest extends AbstractSPFlowTest {
      * @throws Exception on error
      */
     @Test
-    public void testACRFromAgent() throws Exception {
+    public void testACRFromAgent_WithRO() throws Exception {
         setDefaultAuth();
         
         final DDF input = new DDF(null).structure();
diff --git a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCTokenConsumerFlowTest.java b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCTokenConsumerFlowTest.java
index eb7a858..1fa394c 100644
--- a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCTokenConsumerFlowTest.java
+++ b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCTokenConsumerFlowTest.java
@@ -260,7 +260,7 @@ public class OIDCTokenConsumerFlowTest extends AbstractOIDCTokenConsumerFlowTest
     public void testSuccess_SignedEncryptedIDToken_PlainUserInfo() throws Exception {
         
         mockOIDCEndpoints(constructSuccessfulTokenResponseSignedAndEncrypted(Instant.now().plusSeconds(3600), 
-                Instant.now(), null, null), constructJSONUserInfoResponse());
+                Instant.now(), null, null, null), constructJSONUserInfoResponse());
 
         final AuthenticationSuccessResponse response = 
                 TestHelper.buildOIDCAuthorizationCodeResponse(TestConstants.RESPONSE_URL, ResponseMode.QUERY, 
@@ -285,6 +285,72 @@ public class OIDCTokenConsumerFlowTest extends AbstractOIDCTokenConsumerFlowTest
                 TestConstants.RESOURCE_URL);
     }
     
+    /**
+     * Test successful flow with a signed and encrypted id_token and a plain user info response. The kid of the key 
+     * used to encrypt the IDToken is in the Headers.
+     * 
+     * @throws IOException on error
+     */
+    @Test
+    public void testSuccess_SignedEncryptedIDToken_WithDecryptionKID_PlainUserInfo() throws Exception {
+        
+        mockOIDCEndpoints(constructSuccessfulTokenResponseSignedAndEncrypted(Instant.now().plusSeconds(3600), 
+                Instant.now(), null, null, rpEncryptionCredential.getKid()), constructJSONUserInfoResponse());
+
+        final AuthenticationSuccessResponse response = 
+                TestHelper.buildOIDCAuthorizationCodeResponse(TestConstants.RESPONSE_URL, ResponseMode.QUERY, 
+                        TestConstants.STATE_TOKEN);         
+        final DDF input = buildRemotedQueryStringResponse(response);
+        
+        // Add cookies
+        input.addmember("http.headers.Cookie").unsafe_string(TestHelper.buildCookieHeader(
+                TestConstants.STATE_TOKEN, 
+                TestConstants.APPLICATION_ID_REQUEST_OBJECT,
+                TestHelper.buildAuthenticationState(null, false, null), true));
+        
+        setApplicationRequest(TestConstants.APPLICATION_ID_REQUEST_OBJECT, input);
+
+        final FlowExecutionResult result = flowExecutor.launchExecution(TestConstants.FLOW_ID, null, externalContext);
+        assertFlowExecutionResult(result, TestConstants.FLOW_ID);
+        assertFlowExecutionOutcome(result.getOutcome());
+        final DDF output = assertOutputMessageSuccess(result);
+        assert output != null;
+        System.out.println("test output: " + output.toString());
+        validateOutputMessage(result, CollectionSupport.setOf("sub","mail","displayName","eduPersonScopedAffiliation"),
+                TestConstants.RESOURCE_URL);
+    }
+    
+    /**
+     * Test failure flow with a signed and encrypted id_token and a plain user info response. The kid of the key 
+     * used to encrypt the IDToken is not one that matches to a local key defined.
+     * 
+     * @throws IOException on error
+     */
+    @Test
+    public void testFail_SignedEncryptedIDToken_WithDifferentDecryptionKID_PlainUserInfo() throws Exception {
+        
+        mockOIDCEndpoints(constructSuccessfulTokenResponseSignedAndEncrypted(Instant.now().plusSeconds(3600), 
+                Instant.now(), null, null, "wrong-encryption-keyid"), constructJSONUserInfoResponse());
+
+        final AuthenticationSuccessResponse response = 
+                TestHelper.buildOIDCAuthorizationCodeResponse(TestConstants.RESPONSE_URL, ResponseMode.QUERY, 
+                        TestConstants.STATE_TOKEN);         
+        final DDF input = buildRemotedQueryStringResponse(response);
+        
+        // Add cookies
+        input.addmember("http.headers.Cookie").unsafe_string(TestHelper.buildCookieHeader(
+                TestConstants.STATE_TOKEN, 
+                TestConstants.APPLICATION_ID_REQUEST_OBJECT,
+                TestHelper.buildAuthenticationState(null, false, null), true));
+        
+        setApplicationRequest(TestConstants.APPLICATION_ID_REQUEST_OBJECT, input);
+
+        final FlowExecutionResult result = flowExecutor.launchExecution(TestConstants.FLOW_ID, null, externalContext);
+        assertFlowExecutionResult(result, TestConstants.FLOW_ID);
+        assertFlowExecutionOutcome(result.getOutcome());
+        assertOutputMessageEvent(result, EventIds.MESSAGE_PROC_ERROR);
+    }
+    
     /**
      * Test successful flow with a signed id_token and a JWT user info response.
      * 
diff --git a/sp-oidc-conf-impl/src/test/resources/logback-flow-test.xml b/sp-oidc-conf-impl/src/test/resources/logback-flow-test.xml
index a89c91c..fedae41 100644
--- a/sp-oidc-conf-impl/src/test/resources/logback-flow-test.xml
+++ b/sp-oidc-conf-impl/src/test/resources/logback-flow-test.xml
@@ -18,6 +18,10 @@
         <appender-ref ref="STDOUT" />
     </logger>
     
+    <logger name="org.opensaml.security" level="DEBUG" additivity="false">
+        <appender-ref ref="STDOUT" />
+    </logger>
+    
     <logger name="net.shibboleth.idp" level="DEBUG" additivity="false">
         <appender-ref ref="STDOUT" />
     </logger>
diff --git a/sp-oidc-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/oidc-credentials.xml b/sp-oidc-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/oidc-credentials.xml
index 4a26085..955a893 100644
--- a/sp-oidc-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/oidc-credentials.xml
+++ b/sp-oidc-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/oidc-credentials.xml
@@ -11,6 +11,8 @@
                            
        default-init-method="initialize"
        default-destroy-method="destroy">
+       
+       <!--  TODO: with changes to credential resolver, remove this!! -->
     
      <!--
     This file contains default OIDC signing and encryption credentials. This file should be imported into agents.xml.
diff --git a/sp-oidc-conf-impl/src/test/resources/net/shibboleth/sp/oidc-test-beans.xml b/sp-oidc-conf-impl/src/test/resources/net/shibboleth/sp/oidc-test-beans.xml
index 32ee7bf..084a430 100644
--- a/sp-oidc-conf-impl/src/test/resources/net/shibboleth/sp/oidc-test-beans.xml
+++ b/sp-oidc-conf-impl/src/test/resources/net/shibboleth/sp/oidc-test-beans.xml
@@ -28,6 +28,7 @@
     <bean id="shibboleth.oidc.JWKCredential" abstract="true"
         class="net.shibboleth.oidc.security.credential.BasicJWKCredentialFactoryBean" />
 
+    <!-- These need to be the same as those resolvable by the security configuration used -->
     <bean id="dummy.op.signing.Credential" parent="shibboleth.oidc.JWKCredential"
         p:resource="%{idp.home}/credentials/op/op-signing-rsa.jwk" p:throwIfNull="false" />
         
diff --git a/sp-oidc-impl/pom.xml b/sp-oidc-impl/pom.xml
index 6b60be6..2678da7 100644
--- a/sp-oidc-impl/pom.xml
+++ b/sp-oidc-impl/pom.xml
@@ -91,6 +91,11 @@
             <artifactId>oidc-common-profile-impl</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>${oidc-common.groupId}</groupId>
+            <artifactId>oidc-common-saml-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
 
         <dependency>
             <groupId>${shib-profile.groupId}</groupId>
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
new file mode 100644
index 0000000..c7448b4
--- /dev/null
+++ b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/BasicSignatureSigningConfiguration.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.sp.jose.config.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.saml.criterion.ProtocolCriterion;
+import org.opensaml.security.credential.Credential;
+import org.opensaml.security.credential.CredentialResolver;
+import org.opensaml.security.credential.UsageType;
+import org.opensaml.security.criteria.UsageCriterion;
+import org.slf4j.Logger;
+
+import net.shibboleth.oidc.saml.xmlobject.Constants;
+import net.shibboleth.shared.annotation.ParameterName;
+import net.shibboleth.shared.annotation.constraint.NotLive;
+import net.shibboleth.shared.annotation.constraint.Unmodifiable;
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.resolver.CriteriaSet;
+import net.shibboleth.shared.resolver.ResolverException;
+
+/**
+ * Subclass of the JOSE version to provide support for CredentialResolver service
+ * through a bridging class.
+ * 
+ * <p>This class currently assumes OIDC protocol usage when resolving credentials.</p>
+ * 
+ * TODO: given the changes in oidc-commons, we could add something appropriate there. 
+ */
+public class BasicSignatureSigningConfiguration 
+	extends net.shibboleth.oidc.security.jose.impl.BasicSignatureSigningConfiguration {
+
+    /** Class logger. */
+    @Nonnull private final Logger log = LoggerFactory.getLogger(BasicSignatureSigningConfiguration.class);
+    
+    /** Bridge to resolve credentials. */
+    @Nonnull private final CredentialResolver credentialResolver;
+
+    /**
+     * Constructor.
+     *
+     * @param resolver a credential resolver service to use
+     */
+    public BasicSignatureSigningConfiguration(
+            @Nonnull @ParameterName(name="resolver") final CredentialResolver resolver) {
+        credentialResolver = Constraint.isNotNull(resolver, "CredentialResolver cannot be null");
+    }
+    
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull @Unmodifiable @NotLive public List<Credential> getSigningCredentials() {
+        final List<Credential> hardwired = super.getSigningCredentials();
+        if (!hardwired.isEmpty()) {
+            return hardwired;
+        }
+        
+        // Resolve if possible using: TODO
+        //  * UsageType = SIGNING
+        //  * Protocol = if set
+        
+        final CriteriaSet criteria = new CriteriaSet(new UsageCriterion(UsageType.SIGNING),
+                new ProtocolCriterion(Constants.OIDC_PROTOCOL_URI));
+        
+        try {
+            final Iterable<Credential> creds = credentialResolver.resolve(criteria);
+            final ArrayList<Credential> accumulator = new ArrayList<>();
+            creds.forEach(accumulator::add);
+            log.debug("Resolved {} signing key(s)", accumulator.size());
+            return accumulator;
+        } catch (final ResolverException e) {
+            log.error("Exception resolving signing credentials", e);
+        }
+        
+        log.debug("Resolved 0 signing key(s)");
+        return CollectionSupport.emptyList();
+    }
+
+}
\ No newline at end of file
diff --git a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/StaticFilteringCriterionCredentialResolver.java b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/StaticFilteringCriterionCredentialResolver.java
new file mode 100644
index 0000000..66d2eb9
--- /dev/null
+++ b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/StaticFilteringCriterionCredentialResolver.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.sp.jose.config.impl;
+
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.security.credential.Credential;
+import org.opensaml.security.credential.CredentialResolver;
+import org.opensaml.security.credential.criteria.impl.EvaluableCredentialCriterion;
+import org.opensaml.security.credential.impl.AbstractCriteriaFilteringCredentialResolver;
+
+import net.shibboleth.oidc.security.credential.JOSEObjectCredentialResolver;
+import net.shibboleth.shared.annotation.ParameterName;
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.resolver.CriteriaSet;
+import net.shibboleth.shared.resolver.Criterion;
+import net.shibboleth.shared.resolver.ResolverException;
+
+/**
+ * A filtering resolver that adds statically-defined {@link Criterion} objects to a new {@link CriteriaSet}
+ * fed into a wrapped, delegated, resolver. 
+ * 
+ * <p>The new criteria set may optionally include the criteria supplied by the caller. The caller's input 
+ * {@link CriteriaSet} instance is never passed directly to the wrapped resolver.</p>
+ * 
+ * <p>After credential resolution has been performed by the wrapped resolver, the filtering behaviour from 
+ * {@link AbstractCriteriaFilteringCredentialResolver} is applied using any {@link EvaluableCredentialCriterion} 
+ * instances present in the input criteria set (not including the static criteria, or anything from the underlying
+ * resolver). Technically these filters are added as an additional filter-view layer on top of whatever is produced
+ * by the wrapped resolver.</p>
+ * 
+ * <p>Restated, the statically-defined criteria (and, optionally, the caller-supplied criteria) are passed to the 
+ * wrapped credential resolver, which may use them as it sees fit during credential resolution. Once the wrapped
+ * resolver has finished its resolution, this resolver adds another filter layer to the resulting credential iterable 
+ * using only those {@link EvaluableCredentialCriterion} instances present in the input criteria set.</p>
+ * 
+ * <p>It exports the additional {@link JOSEObjectCredentialResolver} interface so it can be used for JOSE credential
+ * resolution. Effectively bridging between JOSE credential use cases, and an underlying, generic, 
+ * CredentialResolver.</p>
+ * 
+ */
+public class StaticFilteringCriterionCredentialResolver extends AbstractCriteriaFilteringCredentialResolver 
+							implements JOSEObjectCredentialResolver {
+
+    /** List of credentials held by this resolver. */
+    @Nonnull private final CredentialResolver credentialResolver;
+    
+    /** Static criteria to add. */
+    @Nonnull private final Collection<Criterion> staticCriteria;
+    
+    /** 
+     * If the {@link CriteriaSet} from the caller should be copied into the {@link CriteriaSet} passed into the 
+     * credential resolver. Defaults to false if not set, where only the staticCriteria are passed through.
+     */
+    private final boolean enableCriteriaPassthrough;
+    
+    /**
+     * Constructor.
+     *
+     * @param resolver underlying resolver
+     * @param criteria static criteria to add to all resolutions
+     * @param passthrough If the {@link CriteriaSet} from the caller should be copied into the 
+     * 								{@link CriteriaSet} passed into the credential resolver
+     */
+    public StaticFilteringCriterionCredentialResolver(
+    		@Nonnull @ParameterName(name="resolver") final CredentialResolver resolver,
+            @Nullable @ParameterName(name="criteria") final Collection<Criterion> criteria,
+            @ParameterName(name="criteriaPassthrough") final boolean passthrough) {
+        credentialResolver = Constraint.isNotNull(resolver, "CredentialResolver cannot be null");
+        if (criteria != null) {
+            staticCriteria = CollectionSupport.copyToSet(criteria);
+        } else {
+            staticCriteria = CollectionSupport.emptySet();
+        }
+        enableCriteriaPassthrough = passthrough;
+    }
+    
+    /**
+     * Constructor.
+     *
+     * @param resolver underlying resolver
+     * @param criteria static criteria to add to all resolutions
+     */
+    public StaticFilteringCriterionCredentialResolver(
+    		@Nonnull @ParameterName(name="resolver") final CredentialResolver resolver,
+            @Nullable @ParameterName(name="criteria") final Collection<Criterion> criteria) {
+    	this(resolver, criteria, false);
+    }
+    
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull @NonnullElements public Iterable<Credential> resolveFromSource(
+            @Nullable final CriteriaSet criteriaSet) throws ResolverException {
+    	final CriteriaSet finalCriteria = new CriteriaSet();
+    	if (enableCriteriaPassthrough && criteriaSet != null) {
+    		finalCriteria.addAll(criteriaSet);
+    	}
+        finalCriteria.addAll(staticCriteria);
+        return credentialResolver.resolve(finalCriteria);
+    }
+    
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list