[java-idp-plugin-thymeleaf] branch main updated: Initial cut factory bean and plugin wiring.

Scott Cantor cantor.2 at osu.edu
Tue Feb 6 19:25:35 UTC 2024


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-idp-plugin-thymeleaf.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-thymeleaf.git;a=commit;h=ee1d2e906ea8524cbbff8c29a4dc1ff7b8d7d10b

The following commit(s) were added to refs/heads/main by this push:
     new ee1d2e9  Initial cut factory bean and plugin wiring.
ee1d2e9 is described below

commit ee1d2e906ea8524cbbff8c29a4dc1ff7b8d7d10b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Feb 6 14:25:33 2024 -0500

    Initial cut factory bean and plugin wiring.
---
 thymeleaf-impl/pom.xml                             |  5 ++
 .../impl/TemplateResolverSetFactoryBean.java       | 92 ++++++++++++++++++++++
 .../META-INF/net.shibboleth.idp/postconfig.xml     | 16 ----
 .../META-INF/net/shibboleth/idp/mvc/postconfig.xml | 40 ++++++++++
 4 files changed, 137 insertions(+), 16 deletions(-)

diff --git a/thymeleaf-impl/pom.xml b/thymeleaf-impl/pom.xml
index ec533a8..159e4f3 100644
--- a/thymeleaf-impl/pom.xml
+++ b/thymeleaf-impl/pom.xml
@@ -46,6 +46,11 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>${shib-shared.groupId}</groupId>
+            <artifactId>shib-spring</artifactId>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>${shib-shared.groupId}</groupId>
             <artifactId>shib-support</artifactId>
diff --git a/thymeleaf-impl/src/main/java/net/shibboleth/idp/plugin/thymeleaf/spring/impl/TemplateResolverSetFactoryBean.java b/thymeleaf-impl/src/main/java/net/shibboleth/idp/plugin/thymeleaf/spring/impl/TemplateResolverSetFactoryBean.java
new file mode 100644
index 0000000..8406d95
--- /dev/null
+++ b/thymeleaf-impl/src/main/java/net/shibboleth/idp/plugin/thymeleaf/spring/impl/TemplateResolverSetFactoryBean.java
@@ -0,0 +1,92 @@
+/*
+ * 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.idp.plugin.thymeleaf.spring.impl;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.springframework.util.StringUtils;
+import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver;
+
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.ConstraintViolationException;
+import net.shibboleth.shared.primitive.StringSupport;
+import net.shibboleth.shared.spring.factory.AbstractFactoryBean;
+
+/**
+ * Factory bean that covers for the inability of Thymeleaf's resolver class to support a delimited path
+ * for resolution.
+ * 
+ * <p>A "template" object must be supplied to copy other supported properties from.</p>
+ */
+public class TemplateResolverSetFactoryBean extends AbstractFactoryBean<Set<SpringResourceTemplateResolver>> {
+
+    /** Not to be confused with a template resolver... */
+    @Nonnull private final SpringResourceTemplateResolver resolverTemplate;
+    
+    /** Array of resolution paths. */
+    @Nonnull private final String[] pathArray;
+    
+    /**
+     * Constructor.
+     *
+     * @param template a template resolver to use as a "template" for new instances
+     */
+    TemplateResolverSetFactoryBean(@Nonnull final SpringResourceTemplateResolver template) {
+        resolverTemplate = Constraint.isNotNull(template,
+                "SpringResourceTemplateResolver to use as basis for new objects cannot be null");
+        
+        pathArray = StringUtils.commaDelimitedListToStringArray(StringSupport.trimOrNull(template.getPrefix()));
+        if (pathArray.length == 0) {
+            throw new ConstraintViolationException("SpringResourceTemplateResolver prefix cannot be null or empty");
+        }
+    }
+    
+    /** {@inheritDoc} */
+    @Override
+    @SuppressWarnings("rawtypes")
+    @Nullable public Class<Set> getObjectType() {
+        return Set.class;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Nullable protected Set<SpringResourceTemplateResolver> createInstance() throws Exception {
+        final Set<SpringResourceTemplateResolver> results = new HashSet<>();
+        
+        int i = 1;
+        for (final String path : pathArray) {
+            if (path != null && !path.isBlank()) {
+                final SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
+                
+                resolver.setOrder(i);
+                resolver.setName(resolverTemplate.getName() + Integer.toString(i++));
+                resolver.setCheckExistence(resolverTemplate.getCheckExistence());
+                resolver.setCacheable(resolverTemplate.isCacheable());
+                resolver.setTemplateMode(resolverTemplate.getTemplateMode());
+                resolver.setPrefix(path);
+                resolver.setSuffix(resolverTemplate.getSuffix());
+                
+                results.add(resolver);
+            }
+        }
+        
+        return results;
+    }
+
+}
\ No newline at end of file
diff --git a/thymeleaf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml b/thymeleaf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
deleted file mode 100644
index 0fa54c3..0000000
--- a/thymeleaf-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?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">
-
-    <!-- 
-    System beans needed for extension to function, loaded after global.xml.
-    -->
-    
-</beans>
\ No newline at end of file
diff --git a/thymeleaf-impl/src/main/resources/META-INF/net/shibboleth/idp/mvc/postconfig.xml b/thymeleaf-impl/src/main/resources/META-INF/net/shibboleth/idp/mvc/postconfig.xml
new file mode 100644
index 0000000..bd88447
--- /dev/null
+++ b/thymeleaf-impl/src/main/resources/META-INF/net/shibboleth/idp/mvc/postconfig.xml
@@ -0,0 +1,40 @@
+<?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">
+
+    <!-- System beans needed by MVC context for plugin to function. -->
+    
+    <bean id="shibboleth.ThymeleafViewResolver" class="net.shibboleth.idp.plugin.thymeleaf.spring.impl.ChainingThymeleafViewResolver">
+        <property name="templateEngine" ref="thymeleafTemplateEngine" />
+        <property name="order" value="%{idp.views.thymeleaf.order:11}" />
+        <property name="contentType" value="text/html;charset=utf-8" />
+    </bean>
+    
+    <bean id="thymeleafTemplateEngine" class="org.thymeleaf.spring6.SpringTemplateEngine">
+        <property name="templateResolvers">
+            <util:set>
+                <bean class="net.shibboleth.idp.plugin.thymeleaf.spring.impl.TemplateResolverSetFactoryBean">
+                    <constructor-arg>
+                        <bean class="org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver">
+                            <property name="name" value="ThymeleafResolver" />
+                            <property name="checkExistence" value="true"/>
+                            <property name="cacheable" value="true"/>
+                            <property name="templateMode" value="HTML" />
+                            <property name="prefix" value="#{'%{idp.views:%{idp.home}/views}'.trim()},classpath:/net/shibboleth/idp/views,classpath:/META-INF/net/shibboleth/idp/views"/>
+                            <property name="suffix" value=".html"/>
+                        </bean>
+                    </constructor-arg>
+                </bean>
+            </util:set>
+        </property>
+        <property name="enableSpringELCompiler" value="true" />
+    </bean>
+    
+</beans>
\ 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