[java-shib-shared] branch main updated: IDP-2239 - Property-based control of view resolver order and activation
Scott Cantor
cantor.2 at osu.edu
Mon Feb 5 16:55:56 UTC 2024
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=266f872e7e980441020696e4becea4b78a744de2
The following commit(s) were added to refs/heads/main by this push:
new 266f872e IDP-2239 - Property-based control of view resolver order and activation
266f872e is described below
commit 266f872e7e980441020696e4becea4b78a744de2
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Feb 5 11:55:53 2024 -0500
IDP-2239 - Property-based control of view resolver order and activation
https://shibboleth.atlassian.net/browse/IDP-2239
Add activation condition hook for Velocity view resolver.
---
.../spring/velocity/VelocityViewResolver.java | 37 ++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/shib-velocity-spring/src/main/java/net/shibboleth/shared/spring/velocity/VelocityViewResolver.java b/shib-velocity-spring/src/main/java/net/shibboleth/shared/spring/velocity/VelocityViewResolver.java
index b14a2684..577d73ee 100644
--- a/shib-velocity-spring/src/main/java/net/shibboleth/shared/spring/velocity/VelocityViewResolver.java
+++ b/shib-velocity-spring/src/main/java/net/shibboleth/shared/spring/velocity/VelocityViewResolver.java
@@ -14,15 +14,26 @@
package net.shibboleth.shared.spring.velocity;
+import java.util.Locale;
+import java.util.function.Predicate;
+
+import javax.annotation.Nonnull;
+
+import org.springframework.lang.Nullable;
+import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
+import net.shibboleth.shared.annotation.ParameterName;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.PredicateSupport;
+
/**
* Convenience subclass of {@link org.springframework.web.servlet.view.UrlBasedViewResolver}
* that supports {@link VelocityView} (i.e. Velocity templates) and custom subclasses of it.
*
* <p><b>Note:</b> When chaining ViewResolvers, a VelocityViewResolver will
* check for the existence of the specified template resources and only return
- * a non-null View object if the template was actually found.
+ * a non-null View object if the template was actually found.</p>
*
* @author Juergen Hoeller
*
@@ -30,9 +41,31 @@ import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
*/
public class VelocityViewResolver extends AbstractTemplateViewResolver {
+ /** Activation condition for view resolver. */
+ @Nonnull private final Predicate<String> activationCondition;
+
/** Constructor. */
public VelocityViewResolver() {
+ this(PredicateSupport.alwaysTrue());
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param condition activation condition
+ *
+ * @since 9.1.0
+ */
+ public VelocityViewResolver(@Nonnull @ParameterName(name="condition") final Predicate<String> condition) {
setViewClass(VelocityView.class);
+ activationCondition = Constraint.isNotNull(condition, "Activation condition cannot be null");
}
-
+
+ /** {@inheritDoc} */
+ @Override
+ @Nullable public View resolveViewName(@Nonnull final String viewName, @Nonnull final Locale locale)
+ throws Exception {
+ return activationCondition.test(viewName) ? super.resolveViewName(viewName, locale) : null;
+ }
+
}
\ 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