From c06f21376e084a0a7c9a9ddcdb67446ce6a7fa5c Mon Sep 17 00:00:00 2001 From: Thomas Scheffler Date: Thu, 12 Dec 2024 20:14:55 +0100 Subject: [PATCH] MIR-1416 pin glassfish jaxb-runtime to MIRAccessKeyPairTransformer use property MIR.AccessKey.JAXBContextFactory to override default --- mir-module/pom.xml | 5 +++++ .../accesskeys/MIRAccessKeyPairTransformer.java | 17 +++++++++++++---- .../main/resources/config/mir/mycore.properties | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/mir-module/pom.xml b/mir-module/pom.xml index b2ba51fdba..f55ec9c00c 100644 --- a/mir-module/pom.xml +++ b/mir-module/pom.xml @@ -242,6 +242,11 @@ + + org.glassfish.jaxb + jaxb-runtime + runtime + org.hibernate.orm hibernate-hikaricp diff --git a/mir-module/src/main/java/org/mycore/mir/authorization/accesskeys/MIRAccessKeyPairTransformer.java b/mir-module/src/main/java/org/mycore/mir/authorization/accesskeys/MIRAccessKeyPairTransformer.java index f1529be006..e00246b273 100644 --- a/mir-module/src/main/java/org/mycore/mir/authorization/accesskeys/MIRAccessKeyPairTransformer.java +++ b/mir-module/src/main/java/org/mycore/mir/authorization/accesskeys/MIRAccessKeyPairTransformer.java @@ -20,16 +20,19 @@ package org.mycore.mir.authorization.accesskeys; import java.io.IOException; +import java.util.Map; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.transform.JDOMSource; import org.mycore.common.MCRException; +import org.mycore.common.config.MCRConfiguration2; import org.mycore.common.content.MCRJAXBContent; import org.mycore.datamodel.metadata.MCRObjectID; import org.mycore.mir.authorization.accesskeys.backend.MIRAccessKeyPair; import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBContextFactory; import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Unmarshaller; @@ -54,8 +57,13 @@ private MIRAccessKeyPairTransformer() { private static JAXBContext initContext() { try { - return JAXBContext.newInstance(MIRAccessKeyPair.class.getPackage().getName(), - MIRAccessKeyPair.class.getClassLoader()); + String factoryProperty = "MIR.AccessKey.JAXBContextFactory"; + JAXBContextFactory jaxbContextFactory = + MCRConfiguration2.getInstanceOf(factoryProperty) + .orElseThrow(() -> MCRConfiguration2.createConfigurationException(factoryProperty)); + JAXBContext jaxbContext = jaxbContextFactory.createContext(MIRAccessKeyPair.class.getPackage().getName(), + MIRAccessKeyPair.class.getClassLoader(), Map.of()); + return jaxbContext; } catch (final JAXBException e) { throw new MCRException("Could not instantiate JAXBContext.", e); } @@ -121,8 +129,9 @@ public static MIRAccessKeyPair buildAccessKeyPair(final MCRObjectID mcrObjectId, } try { final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller(); - return MIRAccessKeyPair.fromServiceFlags(mcrObjectId, - (MIRAccessKeyPair.ServiceFlags) unmarshaller.unmarshal(new JDOMSource(element))); + MIRAccessKeyPair.ServiceFlags serviceFlags = + unmarshaller.unmarshal(new JDOMSource(element.clone()), MIRAccessKeyPair.ServiceFlags.class).getValue(); + return MIRAccessKeyPair.fromServiceFlags(mcrObjectId, serviceFlags); } catch (final JAXBException e) { throw new MCRException("Exception while transforming Element to MIRAccessKeyPair.", e); } diff --git a/mir-module/src/main/resources/config/mir/mycore.properties b/mir-module/src/main/resources/config/mir/mycore.properties index 426471b67b..f12ab5d90e 100644 --- a/mir-module/src/main/resources/config/mir/mycore.properties +++ b/mir-module/src/main/resources/config/mir/mycore.properties @@ -76,6 +76,7 @@ MCR.Access.AddDerivateDefaultRule=false MCR.Access.AddObjectDefaultRule=false MCR.ACL.AccessKey.Strategy.AllowedObjectTypes=mods MCR.ACL.AccessKey.Strategy.AllowedSessionPermissionTypes= +MIR.AccessKey.JAXBContextFactory=org.glassfish.jaxb.runtime.v2.JAXBContextFactory ############################################################################## # Configure new fact based ACL Checking #