[java-identity-provider] branch main updated: Allow for absent profile configuration, fix some tests.
Scott Cantor
cantor.2 at osu.edu
Mon Feb 7 15:10:36 UTC 2022
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=751abfda4530734bd39eadf8b8ae0f74e427a89e
The following commit(s) were added to refs/heads/main by this push:
new 751abfda4 Allow for absent profile configuration, fix some tests.
751abfda4 is described below
commit 751abfda4530734bd39eadf8b8ae0f74e427a89e
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Feb 7 10:10:29 2022 -0500
Allow for absent profile configuration, fix some tests.
---
.../profile/impl/SelectProfileConfiguration.java | 43 ++++++++++++++++++----
.../impl/SelectRelyingPartyConfiguration.java | 6 ++-
.../impl/SelectProfileConfigurationTest.java | 25 +++++++++++++
3 files changed, 65 insertions(+), 9 deletions(-)
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
index 2ac6dbfd1..cc3d9f38d 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
@@ -45,8 +45,6 @@ import org.slf4j.LoggerFactory;
* @event {@link IdPEventIds#INVALID_RELYING_PARTY_CTX}
* @event {@link IdPEventIds#INVALID_RELYING_PARTY_CONFIG}
* @event {@link IdPEventIds#INVALID_PROFILE_CONFIG}
- *
- * @post ProfileRequestContext.getSubcontext(RelyingPartyContext.class).getProfileConfiguration() != null
*/
public class SelectProfileConfiguration extends AbstractProfileAction {
@@ -61,9 +59,13 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
/** The RelyingPartyContext to operate on. */
@Nullable private RelyingPartyContext rpCtx;
+ /** Fail if no profile configuration is found. */
+ private boolean failIfMissing;
+
/** Constructor. */
public SelectProfileConfiguration() {
relyingPartyContextLookupStrategy = new ChildContextLookup<>(RelyingPartyContext.class);
+ failIfMissing = true;
}
/**
@@ -80,6 +82,21 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
relyingPartyContextLookupStrategy = Constraint.isNotNull(strategy,
"RelyingPartyContext lookup strategy cannot be null");
}
+
+ /**
+ * Set whether a missing profile configuration should result in an error event.
+ *
+ * <p>Defaults to true.</p>
+ *
+ * @param flag flag to set
+ *
+ * @since 4.2.0
+ */
+ public void setFailIfMissing(final boolean flag) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
+ failIfMissing = flag;
+ }
/** {@inheritDoc} */
@Override
@@ -124,15 +141,25 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
}
if (profileConfiguration == null) {
- log.warn("{} Profile {} is not available for RP configuration {} (RPID {})",
- new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
- ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+ if (failIfMissing) {
+ log.warn("{} Profile {} is not available for RP configuration {} (RPID {})",
+ new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+ ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+ } else {
+ log.debug("{} Profile {} is not available for RP configuration {} (RPID {})",
+ new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+ }
} else if (profileConfiguration instanceof ConditionalProfileConfiguration
&& !((ConditionalProfileConfiguration) profileConfiguration).getActivationCondition().test(
profileRequestContext)) {
- log.warn("{} Profile {} is not active for RP configuration {} (RPID {})",
- new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
- ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+ if (failIfMissing) {
+ log.warn("{} Profile {} is not active for RP configuration {} (RPID {})",
+ new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+ ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+ } else {
+ log.debug("{} Profile {} is not active for RP configuration {} (RPID {})",
+ new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+ }
} else {
rpCtx.setProfileConfig(profileConfiguration);
}
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectRelyingPartyConfiguration.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectRelyingPartyConfiguration.java
index ef122cdd9..5f49309ac 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectRelyingPartyConfiguration.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectRelyingPartyConfiguration.java
@@ -111,6 +111,10 @@ public final class SelectRelyingPartyConfiguration extends AbstractProfileAction
/** {@inheritDoc} */
@Override
public boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ if (!super.doPreExecute(profileRequestContext)) {
+ return false;
+ }
+
relyingPartyCtx = relyingPartyContextLookupStrategy.apply(profileRequestContext);
if (relyingPartyCtx == null) {
log.debug("{} No relying party context available", getLogPrefix());
@@ -118,7 +122,7 @@ public final class SelectRelyingPartyConfiguration extends AbstractProfileAction
return false;
}
- return super.doPreExecute(profileRequestContext);
+ return true;
}
/** {@inheritDoc} */
diff --git a/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SelectProfileConfigurationTest.java b/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SelectProfileConfigurationTest.java
index 9c9e293ed..0a7d5c35a 100644
--- a/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SelectProfileConfigurationTest.java
+++ b/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SelectProfileConfigurationTest.java
@@ -55,6 +55,7 @@ public class SelectProfileConfigurationTest {
public void setUp() throws ComponentInitializationException {
src = new RequestContextBuilder().buildRequestContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
+ prc.getSubcontext(RelyingPartyContext.class).setProfileConfig(null);
action = new SelectProfileConfiguration();
action.initialize();
@@ -93,11 +94,33 @@ public class SelectProfileConfigurationTest {
src = new RequestContextBuilder().setRelyingPartyProfileConfigurations(
Collections.<ProfileConfiguration>singleton(new MockProfileConfiguration("mock"))).buildRequestContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
+ prc.getSubcontext(RelyingPartyContext.class).setProfileConfig(null);
final Event event = action.execute(src);
ActionTestingSupport.assertEvent(event, IdPEventIds.INVALID_PROFILE_CONFIG);
+ Assert.assertNull(prc.getSubcontext(RelyingPartyContext.class).getProfileConfig());
}
+ /**
+ * Test that the action proceeds properly if the desired profile configuration is not configured.
+ *
+ * @throws Exception if something goes wrong
+ */
+ @Test public void testInvalidProfileConfigurationNoFail() throws Exception {
+ action = new SelectProfileConfiguration();
+ action.setFailIfMissing(false);
+ action.initialize();
+
+ src = new RequestContextBuilder().setRelyingPartyProfileConfigurations(
+ Collections.<ProfileConfiguration>singleton(new MockProfileConfiguration("mock"))).buildRequestContext();
+ prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
+ prc.getSubcontext(RelyingPartyContext.class).setProfileConfig(null);
+
+ final Event event = action.execute(src);
+ ActionTestingSupport.assertProceedEvent(event);
+ Assert.assertNull(prc.getSubcontext(RelyingPartyContext.class).getProfileConfig());
+ }
+
/**
* Test that the action selects the appropriate profile configuration and proceeds properly.
*
@@ -107,6 +130,7 @@ public class SelectProfileConfigurationTest {
src = new RequestContextBuilder().setRelyingPartyProfileConfigurations(
Collections.<ProfileConfiguration>singleton(new MockProfileConfiguration("mock"))).buildRequestContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
+ prc.getSubcontext(RelyingPartyContext.class).setProfileConfig(null);
prc.setProfileId("mock");
@@ -126,6 +150,7 @@ public class SelectProfileConfigurationTest {
src = new RequestContextBuilder().setRelyingPartyProfileConfigurations(
Collections.<ProfileConfiguration>singleton(new MockProfileConfiguration("mock"))).buildRequestContext();
prc = new WebflowRequestContextProfileRequestContextLookup().apply(src);
+ prc.getSubcontext(RelyingPartyContext.class).setProfileConfig(null);
prc.setProfileId("new");
prc.setLegacyProfileId("mock");
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list