[java-oidc-common] branch main updated: Add default JSON string to Java Map parsing strategy

Phil Smart philip.smart at jisc.ac.uk
Thu Oct 21 15:48:20 UTC 2021


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

philsmart pushed a commit to branch main
in repository java-oidc-common.

View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=626f456418948032b2dc5dc8d8498439bfb2d4d6

The following commit(s) were added to refs/heads/main by this push:
     new 626f456  Add default JSON string to Java Map parsing strategy
626f456 is described below

commit 626f456418948032b2dc5dc8d8498439bfb2d4d6
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Thu Oct 21 16:48:18 2021 +0100

    Add default JSON string to Java Map parsing strategy
---
 .../cache/impl/DefaultJSONMapParsingStrategy.java  | 72 ++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultJSONMapParsingStrategy.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultJSONMapParsingStrategy.java
new file mode 100644
index 0000000..0b96004
--- /dev/null
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/DefaultJSONMapParsingStrategy.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.oidc.metadata.cache.impl;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/** Deserializes a UTF-8 JSON string into a Map.*/
+public class DefaultJSONMapParsingStrategy implements Function<byte[], List<Map<String, Object>>> {
+    
+    /** Class logger. */
+    @Nonnull private final Logger log = LoggerFactory.getLogger(DefaultJSONMapParsingStrategy.class);
+    
+    /** JSON object mapper. */
+    @Nonnull private final ObjectMapper objectMapper;
+    
+    /**
+     * 
+     * Constructor.
+     *
+     * @param mapper the object mapper to use.
+     */
+    public DefaultJSONMapParsingStrategy(@Nonnull final ObjectMapper mapper) {
+        objectMapper = Constraint.isNotNull(mapper, "Object mapper can not be null");
+    }
+
+    @Override
+    public List<Map<String, Object>> apply(byte[] rawMetadata) {
+        try {
+            Map<String, Object> parsed = 
+                    objectMapper.readValue(new String(rawMetadata, StandardCharsets.UTF_8), 
+                            new TypeReference<Map<String,Object>>(){});
+            if (parsed != null) {
+                return List.of(parsed);
+            }
+            return Collections.emptyList();
+        } catch (final JsonProcessingException e) {
+            log.error("Could not parse input raw metadata to a map");
+            return Collections.emptyList();
+        }
+    }
+
+}

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


More information about the commits mailing list