Updated SAML config
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
package net.gepafin.tendermanagement.config;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -13,6 +18,8 @@ import org.springframework.security.saml2.provider.service.authentication.Saml2A
|
||||
import org.springframework.security.saml2.provider.service.authentication.Saml2Authentication;
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -62,6 +69,27 @@ public class SamlSuccessHandler implements AuthenticationSuccessHandler {
|
||||
samlResponseLogEntity.setToken(token);
|
||||
samlResponseLogRepository.save(samlResponseLogEntity);
|
||||
|
||||
|
||||
// Extracting raw SAML response
|
||||
String samlResponse = samlAuth.getSaml2Response();
|
||||
logger.info("Raw SAML Response: " + samlResponse);
|
||||
|
||||
// Parsing the SAML response as XML
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.parse(new ByteArrayInputStream(Base64.getDecoder().decode(samlResponse)));
|
||||
|
||||
// Extracting ID, InResponseTo, and IssueInstant from the Response element
|
||||
Element responseElement = (Element) document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "Response").item(0);
|
||||
String responseId = responseElement.getAttribute("ID");
|
||||
String inResponseTo = responseElement.getAttribute("InResponseTo");
|
||||
String issueInstant = responseElement.getAttribute("IssueInstant");
|
||||
|
||||
logger.info("SAML Response ID: " + responseId);
|
||||
logger.info("InResponseTo: " + inResponseTo);
|
||||
logger.info("IssueInstant: " + issueInstant);
|
||||
|
||||
String redirectUrl = feBaseUrl;
|
||||
|
||||
logger.info("SAML login successful for user: " + principal.getName());
|
||||
|
||||
Reference in New Issue
Block a user