From d9c428262add4a251ede02333f444a6c8f1696b6 Mon Sep 17 00:00:00 2001 From: rajesh Date: Mon, 23 Sep 2024 21:37:03 -0700 Subject: [PATCH] Updated config --- .../config/SamlRequestLogger.java | 22 +++++++++++++++++++ .../config/SecurityConfig.java | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/gepafin/tendermanagement/config/SamlRequestLogger.java diff --git a/src/main/java/net/gepafin/tendermanagement/config/SamlRequestLogger.java b/src/main/java/net/gepafin/tendermanagement/config/SamlRequestLogger.java new file mode 100644 index 00000000..fd4d6561 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/config/SamlRequestLogger.java @@ -0,0 +1,22 @@ +package net.gepafin.tendermanagement.config; + +import org.opensaml.core.xml.io.MarshallingException; +import org.opensaml.core.xml.util.XMLObjectSupport; +import org.opensaml.saml.saml2.core.AuthnRequest; +import org.w3c.dom.Element; + +import net.shibboleth.utilities.java.support.xml.SerializeSupport; + +public class SamlRequestLogger { + + public static String convertSAMLObjectToString(AuthnRequest authnRequest) { + try { + Element element = XMLObjectSupport.marshall(authnRequest); + return SerializeSupport.prettyPrintXML(element); // Pretty print XML using SerializeSupport + } catch (MarshallingException e) { + e.printStackTrace(); + return "Error converting SAML object to XML"; + } + } +} + diff --git a/src/main/java/net/gepafin/tendermanagement/config/SecurityConfig.java b/src/main/java/net/gepafin/tendermanagement/config/SecurityConfig.java index 409a4bb8..d9285b8d 100644 --- a/src/main/java/net/gepafin/tendermanagement/config/SecurityConfig.java +++ b/src/main/java/net/gepafin/tendermanagement/config/SecurityConfig.java @@ -266,8 +266,8 @@ public class SecurityConfig { context.getAuthnRequest().setRequestedAuthnContext(buildRequestedAuthnContext()); // Log the SAML AuthnRequest after setting the authentication context - String samlRequest = context.getAuthnRequest().toString(); // Get the updated AuthnRequest - logger.info("SAML AuthnRequest after setting context: " + samlRequest); // Log the updated SAML request + String samlRequest = SamlRequestLogger.convertSAMLObjectToString(context.getAuthnRequest()); + logger.info("SAML AuthnRequest after setting context: " + samlRequest); }); return authenticationRequestResolver;