[java-plugin-shibd-oidc] 18/18: WIP: JSHIBDOIDC-31 - Support new CredentialResolver service
Codeberg
noreply at shibboleth.net
Tue Nov 17 14:55:56 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/8584d2cc45a0a943ea34fb435ab23b1f5f9726e1
commit 8584d2cc45a0a943ea34fb435ab23b1f5f9726e1
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Tue Nov 17 14:53:13 2026 +0000
WIP: JSHIBDOIDC-31 - Support new CredentialResolver service
- Improve the ClientPasswordLookupStrategy to be a
ClientSecretLookupStrategy suitable for the clientAuthentication lookup
strategy on the profile.
- Switch the ClientSecretStorageServiceResolver to use the new
UsageType.AUTHENTICATION for deriving an appropriate client secret.
- Revert the InitializeOAuth2ClientAuthenticationMethodHandler to
pulling the client secret/password from the profile using the new lookup
strategy which bridges into the new resolver service
https://shibboleth.atlassian.net/browse/JSHIBDOIDC-31
---
.../credential/ClientSecretLookupStrategy.java | 86 +++++++++
.../idp/flows/sp/consumer/oidc/oidc-beans.xml | 14 +-
.../net/shibboleth/sp/service/agent/postconfig.xml | 77 ++++++---
.../idp/module/conf/sp/oidc-test-agents.xml | 2 +-
.../impl/ClientSecretCredentialResolver.java | 167 ------------------
.../impl/StaticClientSecretCredentialResolver.java | 192 ---------------------
.../impl/ClientSecretStorageServiceResolver.java | 29 +++-
...izeOAuth2ClientAuthenticationMethodHandler.java | 93 +---------
8 files changed, 181 insertions(+), 479 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
new file mode 100644
index 0000000..33b5f85
--- /dev/null
+++ b/sp-oidc-api/src/main/java/net/shibboleth/sp/jose/credential/ClientSecretLookupStrategy.java
@@ -0,0 +1,86 @@
+/*
+ * 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.credential;
+
+import java.nio.charset.StandardCharsets;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.security.credential.Credential;
+import org.slf4j.Logger;
+
+import net.shibboleth.oidc.security.credential.ClientSecretCredential;
+import net.shibboleth.oidc.security.credential.DefaultClientSecretCredential;
+import net.shibboleth.oidc.security.credential.JOSEObjectCredentialResolver;
+import net.shibboleth.shared.annotation.ParameterName;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.resolver.CriteriaSet;
+import net.shibboleth.shared.resolver.ResolverException;
+
+/**
+ * Lookup strategy which adapts credentials resolved from a {@link JOSEObjectCredentialResolver} into a
+ * {@link ClientSecretCredential}. Typically used to find Client Passwords from the resolver. The resolver should
+ * 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.
+ * </p>
+ *
+ */
+public class ClientSecretLookupStrategy implements Function<ProfileRequestContext, ClientSecretCredential> {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(ClientSecretLookupStrategy.class);
+
+ /** The resolver which is used to resolve local credentials. */
+ @Nonnull private final JOSEObjectCredentialResolver localCredResolver;
+
+ /**
+ * Constructor.
+ *
+ * @param localCredentialResolver resolver of local credentials
+ */
+ public ClientSecretLookupStrategy(@Nonnull
+ @ParameterName(name="localCredentialResolver")
+ final JOSEObjectCredentialResolver localCredentialResolver) {
+ localCredResolver = Constraint.isNotNull(localCredentialResolver, "Local credential resolver cannot be null");
+ }
+
+ @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;
+ }
+ }
+ } catch (final ResolverException e) {
+ log.error("Unable to resolve client password", e);
+ return null;
+ }
+ log.trace("Unable to resolve client password");
+ return null;
+ }
+
+}
diff --git a/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/consumer/oidc/oidc-beans.xml b/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/consumer/oidc/oidc-beans.xml
index 45d2205..599c8e5 100644
--- a/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/consumer/oidc/oidc-beans.xml
+++ b/sp-oidc-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/consumer/oidc/oidc-beans.xml
@@ -59,13 +59,13 @@
<bean id="InitializeOAuth2ClientAuthenticationContext" scope="prototype"
class="net.shibboleth.oidc.profile.impl.InitializeOAuth2ClientAuthenticationContext"
p:OAuth2ClientAuthenticationContextLookupStrategy-ref="shibboleth.ChildLookupOrCreate.OAuth2ClientAuthenticationContextFromOIDCPeer"/>
-
+
+ <!-- Is only required for client_secret_jwt and private_key_jwt -->
<bean id="PopulateJWTClientAuthenticationSignatureSigningParameters" scope="prototype"
class="net.shibboleth.oidc.profile.impl.PopulateJWTSignatureSigningParametersHandler"
p:noResultIsError="true"
p:securityParametersContextLookupStrategy-ref="shibboleth.ChildLookupOrCreate.SecurityParametersFromOAuth2ClientAuthenticationContext"
- p:providerMetadataContextLookupStrategy-ref="shibboleth.ChildLookup.OIDCProviderMetadataContextFromPeerContext">
- <!-- Is only required for client_secret_jwt and private_key_jwt -->
+ p:providerMetadataContextLookupStrategy-ref="shibboleth.ChildLookup.OIDCProviderMetadataContextFromPeerContext">
<property name="activationCondition">
<bean id="JWTBearerTokenForClientAuthenticationCondition"
class="net.shibboleth.sp.oidc.messaging.context.logic.JWTBearerTokenForClientAuthenticationPredicate"/>
@@ -90,13 +90,7 @@
class="net.shibboleth.sp.oidc.profile.impl.InitializeOAuth2ClientAuthenticationMethodHandler"
p:securityParametersContextLookupStrategy-ref="shibboleth.ChildLookupOrCreate.SecurityParametersFromOAuth2ClientAuthenticationContext"
p:jwtBearerExpiryOffset="%{sp.oidc.authenticationMethod.jwt.expiryOffset:PT30S}"
- p:issuerLookupStrategy-ref="shibboleth.ClientIdLookup.Simple">
- <property name="clientSecretResolver"> <!-- TODO remove this -->
- <bean class="net.shibboleth.sp.jose.config.impl.ClientSecretCredentialResolver"
- c:resolver-ref="shibboleth.sp.CredentialResolverService"
- scope="prototype" abstract="true"
- c:requestSupplier-ref="shibboleth.HttpServletRequestSupplier"/>
- </property>
+ p:issuerLookupStrategy-ref="shibboleth.ClientIdLookup.Simple">
</bean>
</list>
</property>
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 74e0dae..f953585 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
@@ -39,7 +39,7 @@
</bean>
<!-- Singleton JWK cache -->
- <bean id="shibboleth.oidc.RemoteJwkSetCache"
+ <bean id="shibboleth.sp.oidc.RemoteJwkSetCache"
class="net.shibboleth.oidc.jwk.RemoteJwkSetCache"
p:storage-ref="#{'%{sp.oidc.jwk.StorageService:shibboleth.StorageService}'.trim()}"
p:httpClient="#{getObject('%{sp.oidc.HttpClient:}') ?: getObject('shibboleth.InternalHttpClient')}"
@@ -49,7 +49,7 @@
<!-- Profile Beans -->
<bean id="AbstractOIDCProfile" abstract="true"
- p:securityConfiguration-ref="%{sp.oidc.security.config:shibboleth.oidc.DefaultSecurityConfiguration}" />
+ p:securityConfiguration-ref="%{sp.oidc.security.config:shibboleth.sp.oidc.DefaultSecurityConfiguration}" />
<bean id="AbstractOIDCSSOProfile" parent="AbstractOIDCProfile" abstract="true"
p:claimsValidator="#{getObject('DefaultJWTClaimsValidator')}"
@@ -62,8 +62,9 @@
<bean id="OIDC.SSO" parent="AbstractOIDCSSOProfile" lazy-init="true"
class="net.shibboleth.oidc.profile.config.impl.DefaultOIDCAuthorizationConfiguration"
p:encodedAttributes="%{sp.oidc.encodedAttributes:%{sp.oidc.embeddedAttributes:}}"
- p:resolveAttributes="%{sp.oidc.resolveAttributes:false}"
- p:httpRequestMethod="%{sp.oidc.httpRequestMethod:GET}"
+ p:resolveAttributes="%{sp.oidc.resolveAttributes:false}"
+ p:clientCredentialLookupStrategy-ref="%{sp.oidc.security.clientPasswordLookupStrategy:shibboleth.sp.oidc.DefaultClientPasswordLookupStrategy}"
+ p:httpRequestMethod="%{sp.oidc.httpRequestMethod:GET}"
p:retrieveUserInfoEndpointClaims="%{sp.oidc.userinfo.enabled:true}"
p:redirectUriOverride="%{sp.oidc.redirectURI:#{null}}"
p:encryptRequestObject="%{sp.oidc.requestobject.encrypted:false}"
@@ -99,36 +100,64 @@
<util:constant id="OIDC.SSO.FEATURE_SCOPE"
static-field="net.shibboleth.oidc.profile.config.OIDCAuthorizationConfiguration.FEATURE_SCOPE"/>
+ <!--
+ A Client Password lookup strategy that bridges into the credential resolver service. While this will resolve
+ credentials from all configured credential sources, only a single client password (client_secret) is expected
+ as an outcome of this strategy. The client password is used for client_authentication only.
+ -->
+ <bean id="shibboleth.sp.oidc.DefaultClientPasswordLookupStrategy"
+ class="net.shibboleth.sp.jose.credential.ClientSecretLookupStrategy" scope="prototype">
+ <constructor-arg>
+ <bean id="localSigningCredentialResolver" parent="shibboleth.sp.oidc.LocalCredentialResolver"
+ c:criteriaPassthrough="true">
+ <constructor-arg name="criteria">
+ <set>
+ <bean class="org.opensaml.security.criteria.UsageCriterion">
+ <constructor-arg>
+ <util:constant static-field="org.opensaml.security.credential.UsageType.AUTHENTICATION" />
+ </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>
+
<!--
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"
+ <bean id="shibboleth.sp.oidc.BasicSignatureValidationConfiguration" abstract="true"
class="net.shibboleth.oidc.security.jose.impl.BasicSignatureValidationConfiguration"
- p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedSignatureAlgorithms')}"
- p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedSignatureAlgorithms')}" />
+ p:includedAlgorithms="#{getObject('shibboleth.sp.oidc.IncludedSignatureAlgorithms')}"
+ p:excludedAlgorithms="#{getObject('shibboleth.sp.oidc.ExcludedSignatureAlgorithms')}" />
- <bean id="shibboleth.oidc.BasicSignatureSigningConfiguration" abstract="true"
+ <bean id="shibboleth.sp.oidc.BasicSignatureSigningConfiguration" abstract="true"
class="net.shibboleth.oidc.security.jose.impl.BasicSignatureSigningConfiguration"
- p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedSignatureAlgorithms')}"
- p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedSignatureAlgorithms')}" />
+ p:includedAlgorithms="#{getObject('shibboleth.sp.oidc.IncludedSignatureAlgorithms')}"
+ p:excludedAlgorithms="#{getObject('shibboleth.sp.oidc.ExcludedSignatureAlgorithms')}" />
- <bean id="shibboleth.oidc.BasicEncryptionConfiguration" abstract="true"
+ <bean id="shibboleth.sp.oidc.BasicEncryptionConfiguration" abstract="true"
class="net.shibboleth.oidc.security.jose.impl.BasicEncryptionConfiguration"
- p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedEncryptionAlgorithms')}"
- p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedEncryptionAlgorithms')}" />
+ p:includedAlgorithms="#{getObject('shibboleth.sp.oidc.IncludedEncryptionAlgorithms')}"
+ p:excludedAlgorithms="#{getObject('shibboleth.sp.oidc.ExcludedEncryptionAlgorithms')}" />
- <bean id="shibboleth.oidc.BasicDecryptionConfiguration" abstract="true"
+ <bean id="shibboleth.sp.oidc.BasicDecryptionConfiguration" abstract="true"
class="net.shibboleth.oidc.security.jose.impl.BasicDecryptionConfiguration"
- p:includedAlgorithms="#{getObject('shibboleth.oidc.IncludedEncryptionAlgorithms')}"
- p:excludedAlgorithms="#{getObject('shibboleth.oidc.ExcludedEncryptionAlgorithms')}" />
+ p:includedAlgorithms="#{getObject('shibboleth.sp.oidc.IncludedEncryptionAlgorithms')}"
+ p:excludedAlgorithms="#{getObject('shibboleth.sp.oidc.ExcludedEncryptionAlgorithms')}" />
<!--
Bridging beans to link the basic security configuration to the CredentialResolver service to acquire credentials
-->
- <bean id="shibboleth.sp.oidc.BasicSignatureSigningConfiguration" parent="shibboleth.oidc.BasicSignatureSigningConfiguration"
+ <bean id="shibboleth.sp.oidc.BasicSignatureSigningConfiguration.Bridged" parent="shibboleth.sp.oidc.BasicSignatureSigningConfiguration"
class="net.shibboleth.sp.jose.config.impl.BasicSignatureSigningConfiguration"
c:resolver-ref="shibboleth.sp.CredentialResolverBridge" />
@@ -145,7 +174,7 @@
-->
<!--TODO namespace with sp. in them? -->
- <bean id="shibboleth.oidc.DefaultSecurityConfiguration"
+ <bean id="shibboleth.sp.oidc.DefaultSecurityConfiguration"
class="net.shibboleth.oidc.profile.config.JSONSecurityConfiguration" c:clockSkew="%{sp.policy.clockSkew:PT1M}">
<constructor-arg name="idGenerator">
<bean
@@ -171,7 +200,7 @@
</bean>
<bean id="shibboleth.sp.oidc.SigningConfiguration"
- parent="shibboleth.sp.oidc.BasicSignatureSigningConfiguration">
+ parent="shibboleth.sp.oidc.BasicSignatureSigningConfiguration.Bridged">
<property name="signatureAlgorithms">
<list>
<util:constant
@@ -202,7 +231,7 @@
</property>
</bean>
- <bean id="shibboleth.sp.oidc.EncryptionConfiguration" parent="shibboleth.oidc.BasicEncryptionConfiguration"
+ <bean id="shibboleth.sp.oidc.EncryptionConfiguration" parent="shibboleth.sp.oidc.BasicEncryptionConfiguration"
p:KEKCredentialResolver-ref="defaultOIDCKeyEncryptionCredentialResolver"
p:contentEncryptionKeyCredentialResolver-ref="defaultOIDCContentEncryptionKeyCredentialResolver">
<property name="keyTransportEncryptionAlgorithms">
@@ -264,7 +293,7 @@
<bean id="OIDCProviderMetadataCredentialResolver"
class="net.shibboleth.oidc.security.credential.impl.ProviderMetadataCredentialResolver"
- c:remoteJwkSetCache-ref="shibboleth.oidc.RemoteJwkSetCache"
+ c:remoteJwkSetCache-ref="shibboleth.sp.oidc.RemoteJwkSetCache"
c:keyFetchInterval="%{sp.oidc.keyfetch.interval:PT30M}" />
<!-- A local encryption resolver for shared secret key encryption e.g. using A128KW and a client_secret -->
@@ -317,7 +346,7 @@
</bean>
<bean id="shibboleth.sp.oidc.DecryptionConfiguration"
- parent="shibboleth.oidc.BasicDecryptionConfiguration"
+ parent="shibboleth.sp.oidc.BasicDecryptionConfiguration"
p:KEKCredentialResolver-ref="defaultOIDCKeyDecryptionCredentialResolver"
p:contentEncryptionKeyCredentialResolver-ref="defaultOIDCContentDecryptionKeyCredentialResolver">
</bean>
@@ -390,7 +419,7 @@
</bean>
<bean id="shibboleth.sp.oidc.SignatureValidationConfiguration"
- parent="shibboleth.oidc.BasicSignatureValidationConfiguration"
+ parent="shibboleth.sp.oidc.BasicSignatureValidationConfiguration"
p:signatureTrustEngine-ref="ExplicitKeySignedJWTTrustEngine"/>
@@ -410,7 +439,7 @@
<list>
<bean id="OIDCProviderMetadataCredentialResolver"
class="net.shibboleth.oidc.security.credential.impl.ProviderMetadataCredentialResolver"
- c:remoteJwkSetCache-ref="shibboleth.oidc.RemoteJwkSetCache"
+ c:remoteJwkSetCache-ref="shibboleth.sp.oidc.RemoteJwkSetCache"
c:keyFetchInterval="%{sp.oidc.provider.keyfetch.interval:PT30M}"/>
<!-- A local signing key resolver for symmetric signing keys -->
diff --git a/sp-oidc-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/oidc-test-agents.xml b/sp-oidc-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/oidc-test-agents.xml
index 6c6cbbf..ef27ede 100644
--- a/sp-oidc-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/oidc-test-agents.xml
+++ b/sp-oidc-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/oidc-test-agents.xml
@@ -128,7 +128,7 @@
-->
<bean id="testSecConfig.Base"
- parent="shibboleth.oidc.DefaultSecurityConfiguration"
+ parent="shibboleth.sp.oidc.DefaultSecurityConfiguration"
abstract="true"/>
<bean id="testSecConfig"
diff --git a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/ClientSecretCredentialResolver.java b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/ClientSecretCredentialResolver.java
deleted file mode 100644
index ec563bf..0000000
--- a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/ClientSecretCredentialResolver.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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 javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import org.opensaml.core.criterion.EntityIdCriterion;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.opensaml.profile.criterion.ProfileRequestContextCriterion;
-import org.opensaml.security.credential.Credential;
-import org.opensaml.security.credential.CredentialResolver;
-import org.slf4j.Logger;
-
-import jakarta.servlet.ServletRequest;
-import net.shibboleth.oidc.security.credential.JOSEObjectCredentialResolver;
-import net.shibboleth.oidc.security.jose.SignatureSigningParametersResolver;
-import net.shibboleth.profile.context.RelyingPartyContext;
-import net.shibboleth.shared.annotation.ParameterName;
-import net.shibboleth.shared.logic.Constraint;
-import net.shibboleth.shared.primitive.LoggerFactory;
-import net.shibboleth.shared.primitive.NonnullSupplier;
-import net.shibboleth.shared.resolver.CriteriaSet;
-import net.shibboleth.shared.resolver.ResolverException;
-import net.shibboleth.shared.service.ReloadableService;
-import net.shibboleth.shared.service.ServiceableComponent;
-import net.shibboleth.sp.Agent;
-import net.shibboleth.sp.Application;
-import net.shibboleth.sp.context.AgentRequestContext;
-import net.shibboleth.sp.criteria.AgentIDCriterion;
-import net.shibboleth.sp.criteria.ApplicationIDCriterion;
-
-/**
- * A {@link JOSEObjectCredentialResolver} that extracts a client_secret credential from the {@link CredentialResolver}
- * service. This is a specialised and limited function version of a {@link SignatureSigningParametersResolver} for
- * dealing with the {@link CredentialResolver} service and client_secrets.
- *
- * <p>The client secret returned MUST be appropriate for the relying party (OpenID Provider) and Agent in question —
- * this is essential so secrets are not sent to the wrong Provider. It is left to the credential resolver service to
- * ensure appropriate credentials are returned.</p>
- */
-public class ClientSecretCredentialResolver implements JOSEObjectCredentialResolver {
-
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(ClientSecretCredentialResolver.class);
-
- /** Credential resolver service. */
- @Nonnull private final ReloadableService<CredentialResolver> credentialResolver;
-
- /** Access to servlet request. */
- @Nonnull private final NonnullSupplier<ServletRequest> servletRequestSupplier;
-
-
- /**
- * Constructor.
- *
- * @param resolver credential resolver service
- * @param requestSupplier the servlet request supplier
- */
- public ClientSecretCredentialResolver(
- @Nonnull @ParameterName(name="resolver") final ReloadableService<CredentialResolver> resolver,
- @Nonnull @ParameterName(name="requestSupplier") final NonnullSupplier<ServletRequest> requestSupplier) {
- credentialResolver = Constraint.isNotNull(resolver, "CredentialResolver cannot be null");
- servletRequestSupplier = Constraint.isNotNull(requestSupplier, "ServletRequest supplier cannot be null");
- }
-
- /** {@inheritDoc} */
- @Override
- @Nullable public Credential resolveSingle(@Nullable final CriteriaSet criteriaSet) throws ResolverException {
- final Iterable<Credential> creds = resolve(criteriaSet);
- if (creds.iterator().hasNext()) {
- return creds.iterator().next();
- }
- return null;
- }
-
-
- /** {@inheritDoc} */
- @Override
- @Nonnull public Iterable<Credential> resolve(@Nullable final CriteriaSet criteriaSet)
- throws ResolverException {
-
- final CriteriaSet finalCriteria = buildCriteriaSet(criteriaSet);
-
- try (final ServiceableComponent<CredentialResolver> component = credentialResolver.getServiceableComponent()) {
- return component.getComponent().resolve(finalCriteria);
- }
-
- }
-
- /**
- * Add or construct final {@link CriteriaSet} to supply to resolver. Importantly the agentID and relying partyID
- * (OP) are included in the crtieria set so appropriate credentials can be returned.
- *
- * @param criteria existing criteria to add to, if any
- *
- * @return the constructed criteria set
- *
- * @throws ResolverException if there is a failure to find the identifier of the OpenID Provider
- */
- @Nullable private CriteriaSet buildCriteriaSet(@Nullable final CriteriaSet criteria) throws ResolverException {
-
- final ProfileRequestContext prc = getProfileRequestContext();
- if (prc == null) {
- throw new ResolverException(
- "Client secret credential resolution requires a ProfileRequestContext");
- }
-
- final CriteriaSet finalCriteria = criteria != null ? criteria : new CriteriaSet();
- finalCriteria.add(new ProfileRequestContextCriterion(prc));
-
- // Add Agent/Application info.
- final AgentRequestContext arc = prc.getSubcontext(AgentRequestContext.class);
- if (arc != null) {
- final Agent agent = arc.getAgent();
- if (agent != null) {
- final String id = agent.getId();
- if (id != null) {
- finalCriteria.add(new AgentIDCriterion(id));
- }
- }
- final Application app = arc.getApplication();
- if (app != null) {
- finalCriteria.add(new ApplicationIDCriterion(app.getApplicationId()));
- }
- }
-
- final RelyingPartyContext rpc = prc.getSubcontext(RelyingPartyContext.class);
- if (rpc != null) {
- final String rpid = rpc.getRelyingPartyId();
- if (rpid != null) {
- finalCriteria.add(new EntityIdCriterion(rpid));
- }
- }
-
- //TODO: do we need to specify a 'secret' type here. e.g. via another criterion
-
- return finalCriteria;
- }
-
- /**
- * Get the current {@link ProfileRequestContext}.
- *
- * @return current profile request context or null
- */
- @Nullable private ProfileRequestContext getProfileRequestContext() {
- if (servletRequestSupplier.get().getAttribute(ProfileRequestContext.BINDING_KEY)
- instanceof final ProfileRequestContext prc) {
- return prc;
- }
- return null;
- }
-
-
-}
\ No newline at end of file
diff --git a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/StaticClientSecretCredentialResolver.java b/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/StaticClientSecretCredentialResolver.java
deleted file mode 100644
index 21de7cf..0000000
--- a/sp-oidc-impl/src/main/java/net/shibboleth/sp/jose/config/impl/StaticClientSecretCredentialResolver.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * 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 javax.annotation.Nullable;
-
-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 com.nimbusds.jose.EncryptionMethod;
-import com.nimbusds.jose.JOSEException;
-import com.nimbusds.jose.JWEAlgorithm;
-
-import net.shibboleth.oidc.security.credential.ClientSecretCredential;
-import net.shibboleth.oidc.security.credential.impl.DataEncryptionAlgorithmCriterion;
-import net.shibboleth.oidc.security.credential.impl.KeyManagmentAlgorithmCriterion;
-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;
-import net.shibboleth.sp.credential.AbstractOrderedCredentialResolver;
-
-/**
- * A {@link CredentialResolver} that holds {@link ClientSecretCredential}s when instantiated, and derives the
- * appropriate {@link Credential} at runtime based on the supplied criteria.
- *
- * <p>A different key credential is derived for different usage types. MAC ('signing') keys are generated directly off
- * the UTF-8 octets of the client_secret. Encryption credentials are derived using the key management and content
- * encryption algorithms supplied in the criteria set. Requests for encryption credentials therefore require both
- * algorithm criteria to be present.</p>
- */
-public class StaticClientSecretCredentialResolver extends AbstractOrderedCredentialResolver {
-
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(StaticClientSecretCredentialResolver.class);
-
- /** List of credentials held by this resolver. */
- @Nonnull private final List<ClientSecretCredential> creds;
-
- /**
- * Constructor.
- *
- * @param credentials static credentials
- */
- public StaticClientSecretCredentialResolver(
- @Nonnull @ParameterName(name="credentials") final List<ClientSecretCredential> credentials) {
- Constraint.isNotNull(credentials, "Input credentials list cannot be null");
-
- creds = CollectionSupport.copyToList(credentials);
- }
-
- /** {@inheritDoc} */
- @Override
- @Nonnull @NotLive @Unmodifiable public Iterable<Credential> doResolve(@Nullable final CriteriaSet criteria)
- throws ResolverException {
-
- if (!creds.isEmpty()) {
-
- verifyCriteria(criteria);
-
- final List<Credential> credentials = new ArrayList<>(creds.size());
- for (final ClientSecretCredential cred : creds) {
- try {
- final Credential derivedCredential = deriveClientSecretCredential(cred, criteria);
- credentials.add(derivedCredential);
- } catch (final ResolverException e) {
- log.trace("Unable to create suitable credential from client_secret: ",e);
- // Ignore and try next
- }
- }
- return credentials;
- }
- return CollectionSupport.emptyList();
- }
-
- /**
- * Verify the criteria set has the required criterion to correctly process the client secret credential.
- *
- * @param criteriaSet the criteria set to check
- *
- * @throws ResolverException if the required criterion are not present
- */
- private void verifyCriteria(@Nullable final CriteriaSet criteriaSet) throws ResolverException {
-
- if (criteriaSet == null) {
- throw new ResolverException("No criteria set found, can not process client secrets");
- }
-
- final UsageCriterion usageTypeCriterion = criteriaSet.get(UsageCriterion.class);
- if (usageTypeCriterion == null) {
- throw new ResolverException("No usage type criterion supplied, unable to derive client_secret credential");
- }
-
- if (usageTypeCriterion.getUsage() == UsageType.ENCRYPTION) {
-
- final KeyManagmentAlgorithmCriterion alg = criteriaSet.get(KeyManagmentAlgorithmCriterion.class);
- if (alg == null) {
- throw new ResolverException(
- "Credential criteria set did not contain an instance of KeyManagmentAlgorithmCriterion");
- }
- // Technically the encryption method is only relevant to key derivation for the Direct Encryption mode
- final DataEncryptionAlgorithmCriterion enc = criteriaSet.get(DataEncryptionAlgorithmCriterion.class);
- if (enc == null) {
- throw new ResolverException(
- "Credential criteria set did not contain an instance of DataEncryptionAlgorithmCriterion");
- }
- }
- }
-
- /**
- * Use the usage type and algorithm information in the criteria to build a suitable signing or encryption
- * credential.
- *
- * <p>Only supports symmetric key encryption algorithms. Request for asymmetric key encryption algorithms are
- * ignored.</p>
- *
- * @param secretCred the raw client_secret credential
- * @param criteriaSet the criteria set used to find algorithm details for encryption keys
- *
- * @return a suitable credential
- *
- * @throws ResolverException if there is an error deriving the key
- */
- @Nonnull protected Credential deriveClientSecretCredential(@Nonnull final ClientSecretCredential secretCred,
- @Nonnull final CriteriaSet criteriaSet) throws ResolverException {
-
- // Already verified that the criterion exist
- final UsageCriterion usageTypeCriterion = criteriaSet.get(UsageCriterion.class);
- final UsageType usageType = usageTypeCriterion.getUsage();
-
- if (usageType == UsageType.SIGNING) {
- // Create a signing credential
- final Credential signingCred = secretCred.toSigningCredential();
- log.debug("Derived signing credential '{}'", signingCred.getKeyNames());
- return signingCred;
-
- } else if (usageType == UsageType.ENCRYPTION) {
- // Create an encryption credential suitable for the algorithms specified
- final KeyManagmentAlgorithmCriterion alg = criteriaSet.get(KeyManagmentAlgorithmCriterion.class);
-
- // Technically the encryption method is only relevant to key derivation for the Direct Encryption mode
- final DataEncryptionAlgorithmCriterion enc = criteriaSet.get(DataEncryptionAlgorithmCriterion.class);
-
- // Can only derive symmetric key credentials, ignore if not
- if (JWEAlgorithm.Family.SYMMETRIC.contains(JWEAlgorithm.parse(alg.getAlgorithm()))) {
- try {
- final JWEAlgorithm jweAlgorithm = JWEAlgorithm.parse(alg.getAlgorithm());
- final EncryptionMethod encryptionMethod = EncryptionMethod.parse(enc.getEncAlgorithm());
- final Credential derivedCred = secretCred.toEncryptionCredential(
- jweAlgorithm, encryptionMethod);
-
- log.debug("Derived encryption credential '{}' from 'alg={}' and 'enc={}'", derivedCred.getKeyNames()
- ,alg.getAlgorithm(), enc.getEncAlgorithm());
- return derivedCred;
-
- } catch (final JOSEException e) {
- log.trace("Unable to derive symmetric encryption key from client_secret using 'alg={}' "
- + "and 'enc={}'", alg.getAlgorithm(), enc.getEncAlgorithm());
- throw new ResolverException("Unable to create encryption key from client_secret", e);
- }
- } else {
- throw new ResolverException("Asymmetric key requested, client_secret not appropriate");
- }
- } else {
- throw new ResolverException("Unable to create key from client_secret, incompatible usage type");
- }
-
- }
-}
\ No newline at end of file
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 05c40da..fc9b0f8 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
@@ -1,3 +1,16 @@
+/*
+ * 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.credential.impl;
@@ -6,6 +19,7 @@ import java.nio.charset.StandardCharsets;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import javax.crypto.spec.SecretKeySpec;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.exception.VelocityException;
@@ -20,6 +34,7 @@ import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWEAlgorithm;
import net.shibboleth.oidc.security.CredentialConversionUtil;
+import net.shibboleth.oidc.security.credential.BasicExpiringJWKCredential;
import net.shibboleth.oidc.security.credential.ClientSecretCredential;
import net.shibboleth.oidc.security.credential.DefaultClientSecretCredential;
import net.shibboleth.oidc.security.credential.impl.DataEncryptionAlgorithmCriterion;
@@ -205,7 +220,19 @@ public class ClientSecretStorageServiceResolver extends AbstractStorageServiceCr
log.debug("CredentialResolver {}: Derived signing credential '{}'",getId(), signingCred.getKeyNames());
return signingCred;
- } else if (usageType == UsageType.ENCRYPTION) {
+ } else if (usageType == UsageType.AUTHENTICATION) {
+ // TODO here we derive the correct credential inline, we could do this for the other types and look to
+ // remove the specific ClientSecretCredential
+ log.debug("CredentialResolver {}: Derived authentication credential '{}'", getId(),
+ secretCred.getKeyName());
+ final BasicExpiringJWKCredential jwkCredential = new BasicExpiringJWKCredential();
+ jwkCredential.getKeyNames().add(secretCred.getKeyName());
+ jwkCredential.setKid(secretCred.getKeyName());
+ jwkCredential.setSecretKey(new SecretKeySpec(secretCred.getSecretAsBytes(), "NONE"));
+ jwkCredential.setUsageType(UsageType.AUTHENTICATION);
+ return jwkCredential;
+
+ } else if (usageType == UsageType.ENCRYPTION) {
// Create an encryption credential suitable for the algorithms specified
final KeyManagmentAlgorithmCriterion alg = criteriaSet.get(KeyManagmentAlgorithmCriterion.class);
diff --git a/sp-oidc-impl/src/main/java/net/shibboleth/sp/oidc/profile/impl/InitializeOAuth2ClientAuthenticationMethodHandler.java b/sp-oidc-impl/src/main/java/net/shibboleth/sp/oidc/profile/impl/InitializeOAuth2ClientAuthenticationMethodHandler.java
index 250f6c2..32ddd16 100644
--- a/sp-oidc-impl/src/main/java/net/shibboleth/sp/oidc/profile/impl/InitializeOAuth2ClientAuthenticationMethodHandler.java
+++ b/sp-oidc-impl/src/main/java/net/shibboleth/sp/oidc/profile/impl/InitializeOAuth2ClientAuthenticationMethodHandler.java
@@ -14,7 +14,6 @@
package net.shibboleth.sp.oidc.profile.impl;
-import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
@@ -30,10 +29,6 @@ import org.opensaml.messaging.handler.MessageHandlerException;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.context.navigate.ParentProfileRequestContextLookup;
-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 com.nimbusds.jose.Algorithm;
@@ -56,21 +51,17 @@ import net.shibboleth.oidc.authn.context.OAuth2ClientAuthenticationContext;
import net.shibboleth.oidc.metadata.context.OIDCProviderMetadataContext;
import net.shibboleth.oidc.profile.config.OIDCAuthenticationRelyingPartyProfileConfiguration;
import net.shibboleth.oidc.profile.messaging.context.OIDCPeerEntityContext;
-import net.shibboleth.oidc.security.credential.JOSEObjectCredentialResolver;
+import net.shibboleth.oidc.security.credential.ClientSecretCredential;
import net.shibboleth.oidc.security.impl.JWSTokenSigner;
import net.shibboleth.oidc.security.jose.SignatureException;
import net.shibboleth.oidc.security.jose.SignatureSigningParameters;
import net.shibboleth.oidc.security.jose.context.SecurityParametersContext;
import net.shibboleth.profile.context.RelyingPartyContext;
import net.shibboleth.profile.context.navigate.IssuerLookupFunction;
-import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
-import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.primitive.StringSupport;
-import net.shibboleth.shared.resolver.CriteriaSet;
-import net.shibboleth.shared.resolver.ResolverException;
import net.shibboleth.sp.oidc.profile.OIDCSupport;
/**
@@ -147,9 +138,6 @@ public class InitializeOAuth2ClientAuthenticationMethodHandler extends AbstractM
/** The stashed peer entity context.*/
@Nullable private OIDCPeerEntityContext peerEntityContext;
-
- /** The resolver used to resolve client secrets for client_secret based authentication.*/
- @NonnullAfterInit private JOSEObjectCredentialResolver clientSecretResolver;
/** Constructor.*/
public InitializeOAuth2ClientAuthenticationMethodHandler() {
@@ -254,26 +242,6 @@ public class InitializeOAuth2ClientAuthenticationMethodHandler extends AbstractM
issuerLookupStrategy = Constraint.isNotNull(strategy, "IssuerLookupStrategy lookup strategy cannot be null");
}
- /**
- * Set the {@link CredentialResolver} used to determine the client_secret to use for client_secret based
- * authentication methods.
- *
- * @param resolver the resolver used to find the client_secret
- */
- public void setClientSecretResolver(@Nonnull final JOSEObjectCredentialResolver resolver) {
- checkSetterPreconditions();
- clientSecretResolver = Constraint.isNotNull(resolver, "Client secret resolver can not be null");
- }
-
- @Override
- protected void doInitialize() throws ComponentInitializationException {
- super.doInitialize();
- if (clientSecretResolver == null) {
- throw new ComponentInitializationException("Client secret resolver can not be null");
- }
- }
-
-
/** {@inheritDoc} */
@Override
protected boolean doPreInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
@@ -343,12 +311,14 @@ public class InitializeOAuth2ClientAuthenticationMethodHandler extends AbstractM
if (method.equals(ClientAuthenticationMethod.CLIENT_SECRET_BASIC) ||
method.equals(ClientAuthenticationMethod.CLIENT_SECRET_POST)) {
- final Secret secret = resolveClientSecret();
- // TODO redundent check for now, as the secret can not expire. Add back?
- if (secret.expired()) {
- log.warn("{} Client secret has expired for client '{}'", getLogPrefix(), clientId);
- throw new MessageHandlerException("Client secret has expired");
- }
+ final ClientSecretCredential clientPassword =
+ profileConfiguration.getClientCredential(PRC_LOOKUP.apply(messageContext));
+ if (clientPassword == null) {
+ throw new MessageHandlerException("No Client Password (client_secret) credential found from profile "
+ + "configuration, can not construct client authenticaton");
+ }
+
+ final Secret secret = new Secret(clientPassword.getSecret());
if (method.equals(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)) {
clientAuthentication = new ClientSecretBasic(new ClientID(clientId), secret);
} else {
@@ -374,51 +344,6 @@ public class InitializeOAuth2ClientAuthenticationMethodHandler extends AbstractM
}
- /**
- * Resolve a client_secret credential using the provided resolver.
- *
- * <p>The secret is defined to be a SIGNING type in the absence of another suitable type. This should give back
- * the raw secret, and not derive it into a different sequence.</p>
- *
- * <p>The credential is checked to ensure it is appropriate for the target OpenID Provider, and it is a
- * secret and not a public key. These checks may also happen in the resolver, so this serves to guarantee that
- * behaviour.</p>
- *
- * TODO: When we have a way to signal a 'PASSWORD' usage type, the resolvers will know not to
- * return assymmetric keys.
- *
- * @return the secret if found
- *
- * @throws MessageHandlerException if a suitable secret can not be resolved
- */
- @Nonnull private Secret resolveClientSecret() throws MessageHandlerException {
-
- try {
- final CriteriaSet criteria = new CriteriaSet();
- // Use the SIGNING type, to ensure direct key usage.
- // TODO: if another type is specified, we can just say RAW etc. This is a hack. It is
- // really a 'PASSWORD'.
- criteria.add(new UsageCriterion(UsageType.SIGNING));
- // Return the first that fits
- for (final Credential secret : clientSecretResolver.resolve(criteria)) {
- // Guard we have a secret for the correct provider (even if filtered by the resolver), and is
- // a secret
- // TODO: Maybe we guard on entityId, but for now that is not possible for the client_secret
-// if (providerMetadata.getIssuer().getValue().equals(secret.getEntityId()) &&
-// secret.getSecretKey() != null){
- if (secret.getSecretKey() != null){
- final byte[] encodedKey = secret.getSecretKey().getEncoded();
- if (encodedKey != null) {
- return new Secret(new String(encodedKey, StandardCharsets.UTF_8));
- }
- }
- }
- throw new MessageHandlerException("Unable to find a suitable client_secret");
- } catch (final ResolverException e) {
- throw new MessageHandlerException("Unable to resolve client secret", e);
- }
- }
-
/**
* Check the populated security context is using the correct algorithm family for client_secret_jwt client
* authentication.
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list