[java-shib-shared] branch main updated: IDP-2215 - Add additional objects to MVC-layer error view

Scott Cantor cantor.2 at osu.edu
Mon Dec 18 14:52:30 UTC 2023


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=76fd7b59bf5725ec02fd50270fd362f279a62e7f

The following commit(s) were added to refs/heads/main by this push:
     new 76fd7b59 IDP-2215 - Add additional objects to MVC-layer error view
76fd7b59 is described below

commit 76fd7b59bf5725ec02fd50270fd362f279a62e7f
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Dec 18 09:52:26 2023 -0500

    IDP-2215 - Add additional objects to MVC-layer error view
    
    https://shibboleth.atlassian.net/browse/IDP-2215
    
    Extend exception resolver class with additional setters.
---
 shib-spring/pom.xml                                |  6 +-
 .../error/ExtendedMappingExceptionResolver.java    | 67 +++++++++++++++++++++-
 2 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/shib-spring/pom.xml b/shib-spring/pom.xml
index abfe37ba..1246a8d5 100644
--- a/shib-spring/pom.xml
+++ b/shib-spring/pom.xml
@@ -26,12 +26,16 @@
 
     <dependencies>
         <!-- Compile dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>shib-security</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>shib-support</artifactId>
             <version>${project.version}</version>
         </dependency>
-        
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>shib-networking</artifactId>
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/error/ExtendedMappingExceptionResolver.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/error/ExtendedMappingExceptionResolver.java
index 9af4b545..ff9f1d71 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/error/ExtendedMappingExceptionResolver.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/error/ExtendedMappingExceptionResolver.java
@@ -28,7 +28,9 @@ import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 import net.shibboleth.shared.codec.HTMLEncoder;
+import net.shibboleth.shared.codec.StringDigester;
 import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.security.IdentifierGenerationStrategy;
 
 /**
  * Custom Spring exception to view mapper that populates the view model with data
@@ -48,15 +50,36 @@ public class ExtendedMappingExceptionResolver extends SimpleMappingExceptionReso
     /** Model attribute carrying {@link WebApplicationContext}. */
     @Nonnull private static final String MODEL_ATTR_SPRINGCONTEXT = "springContext";
 
+    /** Model attribute carrying {@link WebApplicationContext#getEnvironment()}. */
+    @Nonnull private static final String MODEL_ATTR_ENVIRONMENT = "environment";
+
     /** Model attribute carrying the {@link HTMLEncoder} class. */
     @Nonnull private static final String MODEL_ATTR_ENCODER = "encoder";
-    
+
+    /** Model attribute carrying the CSP digester. */
+    @Nonnull private static final String MODEL_ATTR_DIGESTER = "cspDigester";
+
+    /** Model attribute carrying the CSP nonce generator. */
+    @Nonnull private static final String MODEL_ATTR_NONCE = "cspNonce";
+
+    /** Model attribute carrying the custom object. */
+    @Nonnull private static final String MODEL_ATTR_CUSTOM = "custom";
+
     /** Function to obtain extensions to view model. */
     @Nullable private final Function<HttpServletRequest,Map<String,Object>> viewModelExtenderFunction;
+
+    /** CSP digester. */
+    @Nullable private StringDigester cspDigester;
+
+    /** CSP nonce generator. */
+    @Nullable private IdentifierGenerationStrategy cspNonceGenerator;
+
+    /** Slot for custom view object to inject. */
+    @Nullable private Object customObject;
     
     /** Constructor. */
     public ExtendedMappingExceptionResolver() {
-        viewModelExtenderFunction = null;
+        this(null);
     }
 
     /**
@@ -68,6 +91,39 @@ public class ExtendedMappingExceptionResolver extends SimpleMappingExceptionReso
         viewModelExtenderFunction = extender;
     }
     
+    /**
+     * Sets a CSP digester.
+     * 
+     * @param digester CSP digester
+     * 
+     * @since 9.1.0
+     */
+    public void setCSPDigester(@Nullable final StringDigester digester) {
+        cspDigester = digester;
+    }
+
+    /**
+     * Sets a CSP nonce generator.
+     * 
+     * @param generator CSP nonce generator
+     * 
+     * @since 9.1.0
+     */
+    public void setCSPNonceGenerator(@Nullable final IdentifierGenerationStrategy generator) {
+        cspNonceGenerator = generator;
+    }
+
+    /**
+     * Sets a custom object to inject into the view.
+     * 
+     * @param custom custom object
+     * 
+     * @since 9.1.0
+     */
+    public void setCustomObject(@Nullable final Object custom) {
+        customObject = custom;
+    }
+    
     /** {@inheritDoc} */
     @Override
     protected ModelAndView doResolveException(@Nonnull final HttpServletRequest request,
@@ -90,11 +146,16 @@ public class ExtendedMappingExceptionResolver extends SimpleMappingExceptionReso
         final ModelAndView view = super.getModelAndView(viewName, ex, request);
         view.addObject(MODEL_ATTR_REQUEST, request);
         view.addObject(MODEL_ATTR_ENCODER, HTMLEncoder.class);
+
+        view.addObject(MODEL_ATTR_DIGESTER, cspDigester);
+        view.addObject(MODEL_ATTR_NONCE, cspNonceGenerator);
+        view.addObject(MODEL_ATTR_CUSTOM, customObject);
         
         final WebApplicationContext context =
-                WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
+                WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
         if (context != null) {
             view.addObject(MODEL_ATTR_SPRINGCONTEXT, context);
+            view.addObject(MODEL_ATTR_ENVIRONMENT, context.getEnvironment());
         }
         
         final Function<HttpServletRequest,Map<String,Object>> local = viewModelExtenderFunction;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list