[java-identity-provider] branch main updated: IDP-2310 - DumpConfig is causing a Jackson nesting violation

Scott Cantor cantor.2 at osu.edu
Mon Aug 5 20:06:18 UTC 2024


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=96c8e68d782829c1c88789352c3fc731e6d113bd

The following commit(s) were added to refs/heads/main by this push:
     new 96c8e68d7 IDP-2310 - DumpConfig is causing a Jackson nesting violation
96c8e68d7 is described below

commit 96c8e68d782829c1c88789352c3fc731e6d113bd
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Aug 5 16:05:56 2024 -0400

    IDP-2310 - DumpConfig is causing a Jackson nesting violation
    
    https://shibboleth.atlassian.net/browse/IDP-2310
    
    Add custom serializer for Principal to mapper.
---
 .../shibboleth/idp/admin/impl/OutputConfig.java    | 36 +++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/OutputConfig.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/OutputConfig.java
index f9e09c83d..2f136adeb 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/OutputConfig.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/OutputConfig.java
@@ -17,6 +17,7 @@ package net.shibboleth.idp.admin.impl;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.security.Principal;
 import java.time.Duration;
 import java.time.Instant;
 import java.util.Map;
@@ -34,8 +35,12 @@ import org.opensaml.profile.context.ProfileRequestContext;
 import org.slf4j.Logger;
 import org.springframework.core.annotation.AnnotationUtils;
 
+import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
 import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
 
 import net.shibboleth.idp.profile.AbstractProfileAction;
@@ -171,8 +176,11 @@ public class OutputConfig extends AbstractProfileAction {
             }
             
             final ObjectMapper mapper = new ObjectMapper();
-            
             mapper.registerModule(new JavaTimeModule());
+            final SimpleModule principalModule = new SimpleModule();
+            principalModule.addSerializer(new PrincipalSerializer());
+            mapper.registerModule(principalModule);
+            
             // These don't do much of anything, except the first one I think.
             mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, false);
             mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
@@ -285,4 +293,30 @@ public class OutputConfig extends AbstractProfileAction {
                 || o instanceof Instant;
     }
     
+    /**
+     * Custom serializer for {@link Principal} objects in config.
+     */
+    private static class PrincipalSerializer extends StdSerializer<Principal> {
+
+        private static final long serialVersionUID = 8948390099419865058L;
+
+        /**
+         * Constructor.
+         */
+        protected PrincipalSerializer() {
+            super(Principal.class);
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public void serialize(final Principal value, final JsonGenerator gen, final SerializerProvider provider)
+                throws IOException {
+            gen.writeStartObject();
+            gen.writeStringField("type", value.getClass().getName());
+            gen.writeStringField("value", value.getName());
+            gen.writeEndObject();
+            
+        }
+    }
+    
 }
\ 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