[java-idp-plugin-oidc-rp] branch main updated: JOIDCRP-26 - Save Access Token and Refresh Token to credential set
Phil Smart
philip.smart at jisc.ac.uk
Wed May 3 13:39:37 UTC 2023
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch main
in repository java-idp-plugin-oidc-rp.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-oidc-rp.git;a=commit;h=db4b43e738394b868333c1ce0acbbd0e6e6f9b7e
The following commit(s) were added to refs/heads/main by this push:
new db4b43e JOIDCRP-26 - Save Access Token and Refresh Token to credential set
db4b43e is described below
commit db4b43e738394b868333c1ce0acbbd0e6e6f9b7e
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed May 3 14:39:34 2023 +0100
JOIDCRP-26 - Save Access Token and Refresh Token to credential set
- Add a customisable function hook to the validation action that can
create Principals for inclusion in the returned Subject's private
credentials.
- Add a function that returns both the access_token and refresh_token
to as Principals. Not used by default.
- Add an access token and refresh token principal type. Not used by
default.
https://shibboleth.atlassian.net/browse/JOIDCRP-26
---
.../rp/principal/OAuth2AccessTokenPrincipal.java | 127 ++++++++++++++++++
.../rp/principal/OAuth2RefreshTokenPrincipal.java | 91 +++++++++++++
.../impl/DefaultAccessTokenResponseDecoder.java | 7 +-
...ssTokenToPrivateCredentialsMappingStrategy.java | 98 ++++++++++++++
.../oidc/rp/impl/ValidateOIDCAuthentication.java | 40 +++++-
.../impl/AddForceAuthenticationHandler.java | 2 +-
.../oidc-relying-party-authn-beans.xml | 7 +-
.../authn/oidc/rp/conf/authn/oidc-rp.properties | 1 +
...kenToPrivateCredentialsMappingStrategyTest.java | 144 +++++++++++++++++++++
.../rp/impl/ValidateOIDCAuthenticationTest.java | 44 ++++++-
10 files changed, 551 insertions(+), 10 deletions(-)
diff --git a/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/principal/OAuth2AccessTokenPrincipal.java b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/principal/OAuth2AccessTokenPrincipal.java
new file mode 100644
index 0000000..f59032f
--- /dev/null
+++ b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/principal/OAuth2AccessTokenPrincipal.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.idp.plugin.authn.oidc.rp.principal;
+
+import java.time.Duration;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.MoreObjects;
+
+import net.shibboleth.idp.authn.principal.CloneablePrincipal;
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/** Principal based on an OAuth 2.0 access token.*/
+public class OAuth2AccessTokenPrincipal implements CloneablePrincipal {
+
+ /** The access_token. */
+ @Nonnull @NotEmpty private String accessToken;
+
+ /** The token_type. */
+ @Nonnull @NotEmpty private String accessTokenType;
+
+ /** The duration in seconds when the access token expires.*/
+ @Nullable private Duration expiresIn;
+
+ /**
+ * Constructor.
+ *
+ * @param token the access_token
+ * @param tokenType the token_type
+ * @param expiresInDuration the expires_in in seconds since the response was generated
+ */
+ public OAuth2AccessTokenPrincipal(@Nonnull @NotEmpty @ParameterName(name="accessToken") final String token,
+ @Nonnull @NotEmpty @ParameterName(name="accessToken") final String tokenType,
+ @Nullable @ParameterName(name="expiresIn") final Duration expiresInDuration) {
+ accessToken = Constraint.isNotNull(StringSupport.trimOrNull(token), "Access Token cannot be null or empty");
+ accessTokenType = Constraint.isNotNull(StringSupport.trimOrNull(tokenType),
+ "Access Token Type cannot be null or empty");
+ expiresIn = expiresInDuration;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Nonnull @NotEmpty public String getName() {
+ return accessToken;
+ }
+
+ /**
+ * Get the token_type.
+ *
+ * @return the token_type
+ */
+ @Nonnull public String getAccessTokenType() {
+ return accessTokenType;
+ }
+
+ /**
+ * Get the number of seconds since the response was generated the access_token expires.
+ *
+ * @return the expires_in
+ */
+ @Nullable public Duration getExpiresIn() {
+ return expiresIn;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int hashCode() {
+ return accessToken.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (this == other) {
+ return true;
+ }
+
+ if (other instanceof OAuth2AccessTokenPrincipal) {
+ return accessToken.equals(((OAuth2AccessTokenPrincipal) other).getName());
+ }
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this).add("access_token", accessToken).add("token_type", accessTokenType)
+ .add("expires_in", expiresIn).toString();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public OAuth2AccessTokenPrincipal clone() throws CloneNotSupportedException {
+ final OAuth2AccessTokenPrincipal copy = (OAuth2AccessTokenPrincipal) super.clone();
+ copy.accessToken = accessToken;
+ copy.accessTokenType = accessTokenType;
+ copy.expiresIn = expiresIn;
+ return copy;
+ }
+
+
+}
diff --git a/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/principal/OAuth2RefreshTokenPrincipal.java b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/principal/OAuth2RefreshTokenPrincipal.java
new file mode 100644
index 0000000..3a99d5b
--- /dev/null
+++ b/idp-oidc-rp-api/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/principal/OAuth2RefreshTokenPrincipal.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.idp.plugin.authn.oidc.rp.principal;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.base.MoreObjects;
+
+import net.shibboleth.idp.authn.principal.CloneablePrincipal;
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/** Principal based on an OAuth 2.0 refresh token.*/
+public class OAuth2RefreshTokenPrincipal implements CloneablePrincipal {
+
+ /** The access_token. */
+ @Nonnull @NotEmpty private String refreshToken;
+
+ /**
+ * Constructor.
+ *
+ * @param token the refresh_token
+ */
+ public OAuth2RefreshTokenPrincipal(@Nonnull @NotEmpty @ParameterName(name="refreshToken") final String token) {
+ refreshToken = Constraint.isNotNull(StringSupport.trimOrNull(token), "Refresh Token cannot be null or empty");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Nonnull @NotEmpty public String getName() {
+ return refreshToken;
+ }
+
+
+ /** {@inheritDoc} */
+ @Override
+ public int hashCode() {
+ return refreshToken.hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (this == other) {
+ return true;
+ }
+
+ if (other instanceof OAuth2RefreshTokenPrincipal) {
+ return refreshToken.equals(((OAuth2RefreshTokenPrincipal) other).getName());
+ }
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this).add("refresh_token", refreshToken).toString();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public OAuth2RefreshTokenPrincipal clone() throws CloneNotSupportedException {
+ final OAuth2RefreshTokenPrincipal copy = (OAuth2RefreshTokenPrincipal) super.clone();
+ copy.refreshToken = refreshToken;
+ return copy;
+ }
+
+
+}
diff --git a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/decoding/impl/DefaultAccessTokenResponseDecoder.java b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/decoding/impl/DefaultAccessTokenResponseDecoder.java
index ee692e0..565f6a2 100644
--- a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/decoding/impl/DefaultAccessTokenResponseDecoder.java
+++ b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/decoding/impl/DefaultAccessTokenResponseDecoder.java
@@ -72,7 +72,9 @@ public class DefaultAccessTokenResponseDecoder extends AbstractJSONResponseDecod
try (InputStream input = httpResponse.getEntity().getContent()) {
final Map<String, Object> tokenResponseAsMap = getObjectMapper().readValue(
input, new TypeReference<Map<String, Object>>() {});
-
+ if (log.isTraceEnabled()) {
+ log.trace("Token Response: {}", tokenResponseAsMap);
+ }
final int httpStatusCode = httpResponse.getStatusLine().getStatusCode();
if (httpStatusCode != HttpStatus.SC_OK) {
@@ -81,7 +83,8 @@ public class DefaultAccessTokenResponseDecoder extends AbstractJSONResponseDecod
log.warn("HTTP response does not contain a message entity, nothing to decode, status '{}'",
httpStatusCode);
return null;
- }
+ }
+
return OIDCTokenResponse.parse(new JSONObject(tokenResponseAsMap));
}
diff --git a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AccessTokenToPrivateCredentialsMappingStrategy.java b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AccessTokenToPrivateCredentialsMappingStrategy.java
new file mode 100644
index 0000000..415e1bc
--- /dev/null
+++ b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AccessTokenToPrivateCredentialsMappingStrategy.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.idp.plugin.authn.oidc.rp.impl;
+
+import java.security.Principal;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.profile.context.navigate.InboundMessageContextLookup;
+
+import com.nimbusds.oauth2.sdk.token.AccessToken;
+import com.nimbusds.oauth2.sdk.token.RefreshToken;
+
+import net.shibboleth.idp.plugin.authn.oidc.rp.context.AccessTokenResponseContext;
+import net.shibboleth.idp.plugin.authn.oidc.rp.principal.OAuth2AccessTokenPrincipal;
+import net.shibboleth.idp.plugin.authn.oidc.rp.principal.OAuth2RefreshTokenPrincipal;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/**
+ * A mapping strategy that locates the {@link AccessTokenResponseContext} from the {@link ProfileRequestContext} and
+ * constructs and returns an {@link OAuth2AccessTokenPrincipal} from the access_token, token_type, and expires_in. A
+ * {@link OAuth2RefreshTokenPrincipal} will also be returned in the principal collection if a refresh_token is present
+ * in the context.
+ */
+public class AccessTokenToPrivateCredentialsMappingStrategy
+ implements Function<ProfileRequestContext, Collection<Principal>> {
+
+ /** Strategy used to look up the {@link AccessTokenResponseContext} to set the parameters for. */
+ @Nonnull private final Function<ProfileRequestContext, AccessTokenResponseContext>
+ tokenResponseContextLookupStrategy;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param strategy the strategy to use to lookup the {@link AccessTokenResponseContext}
+ */
+ public AccessTokenToPrivateCredentialsMappingStrategy(
+ @Nonnull final Function<ProfileRequestContext, AccessTokenResponseContext> strategy) {
+ tokenResponseContextLookupStrategy = Constraint.isNotNull(strategy,
+ "TokenResponseContext Lookup Strategy can not be null");
+ }
+
+ /** Constructor.*/
+ public AccessTokenToPrivateCredentialsMappingStrategy() {
+ tokenResponseContextLookupStrategy =
+ new ChildContextLookup<>(AccessTokenResponseContext.class, true).compose(
+ new InboundMessageContextLookup());
+ }
+
+ @Override
+ public Collection<Principal> apply(final ProfileRequestContext input) {
+ final AccessTokenResponseContext context = tokenResponseContextLookupStrategy.apply(input);
+ if (context != null && context.getTokenResponse() != null) {
+ final List<Principal> principals = new ArrayList<>();
+ final AccessToken accessToken = context.getTokenResponse().getTokens().getAccessToken();
+ final RefreshToken refreshToken = context.getTokenResponse().getTokens().getRefreshToken();
+
+ final OAuth2AccessTokenPrincipal accessTokenPrincipal = new OAuth2AccessTokenPrincipal(accessToken.getValue(),
+ accessToken.getType().getValue(),
+ accessToken.getLifetime() == 0 ? null : Duration.ofSeconds(accessToken.getLifetime()));
+ principals.add(accessTokenPrincipal);
+
+ if (refreshToken != null) {
+ final OAuth2RefreshTokenPrincipal refreshTokenPrincipal =
+ new OAuth2RefreshTokenPrincipal(refreshToken.getValue());
+ principals.add(refreshTokenPrincipal);
+ }
+
+ return principals;
+ }
+ return Collections.emptyList();
+ }
+
+}
diff --git a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/ValidateOIDCAuthentication.java b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/ValidateOIDCAuthentication.java
index 02733d0..031fc81 100644
--- a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/ValidateOIDCAuthentication.java
+++ b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/ValidateOIDCAuthentication.java
@@ -119,6 +119,10 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
/** Strategy used to look up a {@link RelyingPartyContext} for configuration options. */
@Nonnull private Function<ProfileRequestContext,RelyingPartyContext> relyingPartyContextLookupStrategy;
+ /** A hook to map context information to private credentials. */
+ @Nullable
+ private Function<ProfileRequestContext, Collection<Principal>> contextToPrivateCredentialsMappingStrategy;
+
/** Store off profile config. */
@Nullable private OIDCAuthenticationRelyingPartyProfileConfiguration profileConfiguration;
@@ -141,6 +145,9 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
/** Pluggable strategy function for generalized extraction of data. */
@Nullable private Function<ProfileRequestContext,Collection<IdPAttribute>> attributeExtractionStrategy;
+ /** The profile request context.*/
+ @Nullable private ProfileRequestContext prc;
+
/** Constructor.*/
public ValidateOIDCAuthentication() {
setMetricName(DEFAULT_METRIC_NAME);
@@ -151,6 +158,20 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
new InboundMessageContextLookup());
}
+ /**
+ * Set the context to principal mapping strategy for mapping context information into principal collections
+ * to place in the private credentials set of the subject.
+ *
+ * @param strategy the strategy to use
+ */
+ public void setContextToPrivateCredentialsMappingStrategy(
+ @Nullable final Function<ProfileRequestContext, Collection<Principal>> strategy) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+
+ contextToPrivateCredentialsMappingStrategy = strategy;
+ }
+
/**
* Sets the filter service to use for inbound attributes.
*
@@ -158,6 +179,7 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
*/
public void setAttributeFilter(@Nullable final ReloadableService<AttributeFilter> filterService) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
attributeFilterService = filterService;
}
@@ -170,6 +192,7 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
*/
public void setTranscoderRegistry(@Nonnull final ReloadableService<AttributeTranscoderRegistry> registry) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
transcoderRegistry = Constraint.isNotNull(registry, "AttributeTranscoderRegistry cannot be null");
}
@@ -181,6 +204,7 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
*/
public void setMetadataResolver(@Nullable final MetadataResolver resolver) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
metadataResolver = resolver;
}
@@ -193,6 +217,7 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
public void setRelyingPartyContextLookupStrategy(
@Nonnull final Function<ProfileRequestContext,RelyingPartyContext> strategy) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
relyingPartyContextLookupStrategy =
Constraint.isNotNull(strategy, "RelyingPartyContext lookup strategy cannot be null");
@@ -208,6 +233,7 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
public void setAttributeExtractionStrategy(
@Nullable final Function<ProfileRequestContext,Collection<IdPAttribute>> strategy) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
attributeExtractionStrategy = strategy;
}
@@ -228,6 +254,9 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
return false;
}
+ //stash the profile request context for later.
+ prc = profileRequestContext;
+
if (authenticationContext.getAttemptedFlow() == null) {
log.debug("{} No attempted flow within authentication context", getLogPrefix());
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
@@ -302,7 +331,7 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
recordSuccess(profileRequestContext);
- log.trace("{} Validating OIDC proxy authentication", getLogPrefix());
+ log.debug("{} Validating OIDC proxy authentication", getLogPrefix());
if (transcoderRegistry != null) {
processAttributes(profileRequestContext);
@@ -406,6 +435,15 @@ public class ValidateOIDCAuthentication extends AbstractValidationAction {
.map(IdPAttributePrincipal::new)
.collect(Collectors.toUnmodifiableList()));
}
+
+ if (contextToPrivateCredentialsMappingStrategy != null) {
+ final Collection<Principal> privateCredentials = contextToPrivateCredentialsMappingStrategy.apply(prc);
+ if (privateCredentials != null) {
+ subject.getPrivateCredentials().addAll(privateCredentials);
+ log.trace("{} Added '{}' private credential(s) from mapping strategy",
+ getLogPrefix(), privateCredentials.size());
+ }
+ }
return subject;
}
diff --git a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddForceAuthenticationHandler.java b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddForceAuthenticationHandler.java
index 4e0c704..16b8c30 100644
--- a/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddForceAuthenticationHandler.java
+++ b/idp-oidc-rp-impl/src/main/java/net/shibboleth/idp/plugin/authn/oidc/rp/messaging/impl/AddForceAuthenticationHandler.java
@@ -52,7 +52,7 @@ public class AddForceAuthenticationHandler extends AbstractOIDCAuthenticationReq
+ "setting prompt to force-login as failed", e);
}
} else {
- log.trace("{} No ForceAuthn requirement, so no prompt set", getLogPrefix());
+ log.trace("{} No ForceAuthn requirement, so no prompt or max_age set", getLogPrefix());
}
}
diff --git a/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/authn/OIDCRelyingParty/oidc-relying-party-authn-beans.xml b/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/authn/OIDCRelyingParty/oidc-relying-party-authn-beans.xml
index d8b4e5b..afeb02b 100644
--- a/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/authn/OIDCRelyingParty/oidc-relying-party-authn-beans.xml
+++ b/idp-oidc-rp-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/authn/OIDCRelyingParty/oidc-relying-party-authn-beans.xml
@@ -467,8 +467,7 @@
class="net.shibboleth.idp.plugin.authn.oidc.rp.impl.ValidateTokenClaims"
p:profileContextLookupStrategy-ref="shibboleth.ChildLookup.ProxyProfileRequestContext"
p:authenticationContextLookupStrategy-ref="ParentAuthenticiationContextLookup"
- p:cleanupHook="#{getObject('shibboleth.authn.oidc.rp.idtoken.jwt.claims.CleanUpHook')
- ?: getObject('DefaultCleanupHook')}"
+ p:cleanupHook="#{getObject('shibboleth.authn.oidc.rp.idtoken.jwt.claims.CleanUpHook')}"
p:claimsValidator="#{getObject('shibboleth.authn.oidc.rp.idtoken.IDTokenClaimsValidator')
?: getObject('DefaultIDTokenClaimsValidator')}"
p:jwtLookupStrategy="#{getObject('shibboleth.authn.oidc.rp.idtoken.IDTokenLookupStrategy')
@@ -809,7 +808,9 @@
p:addDefaultPrincipals="#{getObject('idp.oidc.rp.supportedPrincipals.addDefaultPrincipals') ?: %{idp.oidc.rp.addDefaultPrincipals:false}}"
p:responderLookupStrategy-ref="shibboleth.RelyingPartyIdLookup.Simple"
p:requesterLookupStrategy-ref="shibboleth.ResponderIdLookup.Simple"
- p:attributeExtractionStrategy="#{getObject('shibboleth.authn.oidc.rp.attributeExtractionStrategy')}"
+ p:cleanupHook="#{getObject('shibboleth.authn.oidc.rp.CleanUpHook')}"
+ p:contextToPrivateCredentialsMappingStrategy="#{getObject('shibboleth.authn.oidc.rp.ContextToPrivateCredentialsMappingStrategy')}"
+ p:attributeExtractionStrategy="#{getObject('shibboleth.authn.oidc.rp.AttributeExtractionStrategy')}"
p:attributeFilter-ref="shibboleth.AttributeFilterService"
p:transcoderRegistry-ref="shibboleth.AttributeRegistryService" />
diff --git a/idp-oidc-rp-impl/src/main/resources/net/shibboleth/idp/plugin/authn/oidc/rp/conf/authn/oidc-rp.properties b/idp-oidc-rp-impl/src/main/resources/net/shibboleth/idp/plugin/authn/oidc/rp/conf/authn/oidc-rp.properties
index f6b0bf8..4fa0e0d 100644
--- a/idp-oidc-rp-impl/src/main/resources/net/shibboleth/idp/plugin/authn/oidc/rp/conf/authn/oidc-rp.properties
+++ b/idp-oidc-rp-impl/src/main/resources/net/shibboleth/idp/plugin/authn/oidc/rp/conf/authn/oidc-rp.properties
@@ -13,6 +13,7 @@ idp.oidc.rp.client.redirecturl.allowedOrigins = https://localhost:8443
## Override the default response_mode for the given response_type
#idp.oidc.rp.client.responseMode = query
+## Client authentication method. Currently client_secret_basic and client_secret_post
#idp.oidc.rp.client.authenticationMethod = client_secret_basic
## Comma seperated list of additional scopes e.g. profile or email. The openid scope is added by default
#idp.oidc.rp.client.scopes =
diff --git a/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AccessTokenToPrivateCredentialsMappingStrategyTest.java b/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AccessTokenToPrivateCredentialsMappingStrategyTest.java
new file mode 100644
index 0000000..d607226
--- /dev/null
+++ b/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/AccessTokenToPrivateCredentialsMappingStrategyTest.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.idp.plugin.authn.oidc.rp.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.security.Principal;
+import java.time.Duration;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.testng.annotations.Test;
+
+import com.nimbusds.oauth2.sdk.ParseException;
+import com.nimbusds.openid.connect.sdk.OIDCTokenResponse;
+
+import net.minidev.json.JSONObject;
+import net.shibboleth.idp.plugin.authn.oidc.rp.context.AccessTokenResponseContext;
+import net.shibboleth.idp.plugin.authn.oidc.rp.principal.OAuth2AccessTokenPrincipal;
+import net.shibboleth.idp.plugin.authn.oidc.rp.principal.OAuth2RefreshTokenPrincipal;
+
+public class AccessTokenToPrivateCredentialsMappingStrategyTest {
+
+ private AccessTokenToPrivateCredentialsMappingStrategy strategy;
+
+ @Test
+ public void testSuccess_AccessTokenAndRefreshToken() throws Exception {
+ strategy = new AccessTokenToPrivateCredentialsMappingStrategy(prc -> {
+ final AccessTokenResponseContext accessTokenContext = new AccessTokenResponseContext();
+ final JSONObject json = new JSONObject();
+ json.put("access_token", "access-token-value");
+ json.put("refresh_token", "refresh-token-value");
+ json.put("token_type", "Bearer");
+ json.put("expires_in", 3600);
+
+ try {
+ accessTokenContext.setTokenResponse(OIDCTokenResponse.parse(json));
+ } catch (final ParseException e) {
+ fail(e.getMessage());
+ }
+ return accessTokenContext;
+ });
+ final Collection<Principal> principals = strategy.apply(new ProfileRequestContext());
+ assertNotNull(principals);
+ assertEquals(principals.size(), 2);
+
+ final Iterator<Principal> it = principals.iterator();
+
+ final var principalOne = it.next();
+ assertTrue(principalOne instanceof OAuth2AccessTokenPrincipal);
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getName(), "access-token-value");
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getAccessTokenType(), "Bearer");
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getExpiresIn(), Duration.ofSeconds(3600));
+
+ final var principalTwo = it.next();
+ assertTrue(principalTwo instanceof OAuth2RefreshTokenPrincipal);
+ assertEquals(((OAuth2RefreshTokenPrincipal)principalTwo).getName(), "refresh-token-value");
+ }
+
+ @Test
+ public void testSuccess_AccessTokenOnly() throws Exception {
+ strategy = new AccessTokenToPrivateCredentialsMappingStrategy(prc -> {
+ final AccessTokenResponseContext accessTokenContext = new AccessTokenResponseContext();
+ final JSONObject json = new JSONObject();
+ json.put("access_token", "access-token-value");
+ json.put("token_type", "Bearer");
+ json.put("expires_in", 3600);
+
+ try {
+ accessTokenContext.setTokenResponse(OIDCTokenResponse.parse(json));
+ } catch (final ParseException e) {
+ fail(e.getMessage());
+ }
+ return accessTokenContext;
+ });
+ final Collection<Principal> principals = strategy.apply(new ProfileRequestContext());
+ assertNotNull(principals);
+ assertEquals(principals.size(), 1);
+
+ final Iterator<Principal> it = principals.iterator();
+
+ final var principalOne = it.next();
+ assertTrue(principalOne instanceof OAuth2AccessTokenPrincipal);
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getName(), "access-token-value");
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getAccessTokenType(), "Bearer");
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getExpiresIn(), Duration.ofSeconds(3600));
+
+ }
+
+ @Test
+ public void testSuccess_AccessTokenNoExpiryAndRefreshToken() throws Exception {
+ strategy = new AccessTokenToPrivateCredentialsMappingStrategy(prc -> {
+ final AccessTokenResponseContext accessTokenContext = new AccessTokenResponseContext();
+ final JSONObject json = new JSONObject();
+ json.put("access_token", "access-token-value");
+ json.put("refresh_token", "refresh-token-value");
+ json.put("token_type", "Bearer");
+
+ try {
+ accessTokenContext.setTokenResponse(OIDCTokenResponse.parse(json));
+ } catch (final ParseException e) {
+ fail(e.getMessage());
+ }
+ return accessTokenContext;
+ });
+ final Collection<Principal> principals = strategy.apply(new ProfileRequestContext());
+ assertNotNull(principals);
+ assertEquals(principals.size(), 2);
+
+ final Iterator<Principal> it = principals.iterator();
+
+ final var principalOne = it.next();
+ assertTrue(principalOne instanceof OAuth2AccessTokenPrincipal);
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getName(), "access-token-value");
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getAccessTokenType(), "Bearer");
+ assertEquals(((OAuth2AccessTokenPrincipal)principalOne).getExpiresIn(),null);
+
+ final var principalTwo = it.next();
+ assertTrue(principalTwo instanceof OAuth2RefreshTokenPrincipal);
+ assertEquals(((OAuth2RefreshTokenPrincipal)principalTwo).getName(), "refresh-token-value");
+ }
+
+
+}
diff --git a/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/ValidateOIDCAuthenticationTest.java b/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/ValidateOIDCAuthenticationTest.java
index 091d6e5..998cf97 100644
--- a/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/ValidateOIDCAuthenticationTest.java
+++ b/idp-oidc-rp-impl/src/test/java/net/shibboleth/idp/plugin/authn/oidc/rp/impl/ValidateOIDCAuthenticationTest.java
@@ -45,7 +45,6 @@ import com.nimbusds.jwt.PlainJWT;
import com.nimbusds.openid.connect.sdk.claims.ClaimsSet;
import net.shibboleth.idp.attribute.IdPAttribute;
-import net.shibboleth.idp.attribute.filter.AttributeFilter;
import net.shibboleth.idp.attribute.filter.AttributeFilterPolicy;
import net.shibboleth.idp.attribute.filter.AttributeRule;
import net.shibboleth.idp.attribute.filter.PolicyRequirementRule;
@@ -109,7 +108,7 @@ public class ValidateOIDCAuthenticationTest extends AbstractOIDCTest {
assertEquals(registry.getDisplayNames(new IdPAttribute("givenName")).size(), 1);
- action.setTranscoderRegistry(new MockReloadableService<AttributeTranscoderRegistry>(registry));
+ action.setTranscoderRegistry(new MockReloadableService<>(registry));
}
/* Setup a simple filter policy for givenName.*/
@@ -132,7 +131,7 @@ public class ValidateOIDCAuthenticationTest extends AbstractOIDCTest {
final AttributeFilterImpl filter = new AttributeFilterImpl("engine", Collections.singletonList(policy));
filter.setApplicationContext(new MockApplicationContext());
filter.initialize();
- action.setAttributeFilter(new MockReloadableService<AttributeFilter>(filter));
+ action.setAttributeFilter(new MockReloadableService<>(filter));
}
@Override
@@ -229,4 +228,43 @@ public class ValidateOIDCAuthenticationTest extends AbstractOIDCTest {
}
+
+ @Test
+ public void testSuccess_WithPrivateCredentials() throws ComponentInitializationException {
+
+ action.setContextToPrivateCredentialsMappingStrategy(prc -> {
+ final List<Principal> principals = new ArrayList<>();
+ principals.add(new MockPrincipal("mockOne"));
+ return principals;
+ });
+ action.initialize();
+ final Event result = action.execute(src);
+
+ assertNull(result);
+ assertNotNull(ac.getAuthenticationResult());
+ assertNotNull(ac.getAuthenticationResult().getSubject());
+ final var subject = ac.getAuthenticationResult().getSubject();
+ assertEquals(subject.getPrincipals(OIDCSubjectIdentifierPrincipal.class).size(), 1);
+ assertEquals(subject.getPrincipals(IdPAttributePrincipal.class).size(), 1);
+ assertEquals(subject.getPrincipals(IdPAttributePrincipal.class)
+ .iterator().next().getName(),"givenName");
+ //assert new principals added
+ assertEquals(subject.getPrivateCredentials().size(), 1);
+
+
+ }
+
+ private class MockPrincipal implements Principal {
+ private final String name;
+
+ private MockPrincipal(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ }
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list