use of javax.xml.stream.XMLStreamException in project ddf by codice.
the class IdpEndpoint method processPostLogout.
@Override
@POST
@Path("/logout")
public Response processPostLogout(@FormParam(SAML_REQ) final String samlRequest, @FormParam(SAML_RESPONSE) final String samlResponse, @FormParam(RELAY_STATE) final String relayState, @Context final HttpServletRequest request) throws WSSecurityException, IdpException {
LogoutState logoutState = getLogoutState(request);
Cookie cookie = getCookie(request);
try {
if (samlRequest != null) {
LogoutRequest logoutRequest = logoutMessage.extractSamlLogoutRequest(RestSecurity.inflateBase64(samlRequest));
validatePost(request, logoutRequest);
return handleLogoutRequest(cookie, logoutState, logoutRequest, SamlProtocol.Binding.HTTP_POST, relayState);
} else if (samlResponse != null) {
LogoutResponse logoutResponse = logoutMessage.extractSamlLogoutResponse(RestSecurity.inflateBase64(samlResponse));
String requestId = logoutState != null ? logoutState.getCurrentRequestId() : null;
validatePost(request, logoutResponse, requestId);
return handleLogoutResponse(cookie, logoutState, logoutResponse, SamlProtocol.Binding.HTTP_POST);
}
} catch (IOException | XMLStreamException e) {
throw new IdpException("Unable to inflate Saml Object", e);
} catch (ValidationException e) {
throw new IdpException("Unable to validate Saml Object", e);
}
throw new IdpException("Unable to process logout");
}
use of javax.xml.stream.XMLStreamException in project ddf by codice.
the class SoapRequestDecoder method decodeRelayState.
public String decodeRelayState(String samlRequest) {
String relayState = null;
try {
SOAPPart soapMessage = SamlProtocol.parseSoapMessage(samlRequest);
SOAPEnvelope envelope = soapMessage.getEnvelope();
SOAPHeader header = envelope.getHeader();
Iterator iterator = header.examineAllHeaderElements();
while (iterator.hasNext()) {
SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) iterator.next();
if ("RelayState".equals(soapHeaderElement.getLocalName())) {
relayState = soapHeaderElement.getValue();
break;
}
}
} catch (XMLStreamException e) {
throw new IllegalArgumentException("Unable to convert parse SOAP request.");
} catch (SOAPException e) {
throw new IllegalArgumentException("Unable to get SOAP envelope.");
}
return relayState;
}
use of javax.xml.stream.XMLStreamException in project ddf by codice.
the class CswResponseExceptionMapper method fromResponse.
@Override
public CswException fromResponse(Response response) {
CswException cswException = null;
if (response != null) {
if (response.getEntity() instanceof InputStream) {
String msg = null;
try {
InputStream is = (InputStream) response.getEntity();
if (is.markSupported()) {
is.reset();
}
msg = IOUtils.toString(is);
} catch (IOException e) {
cswException = new CswException("Error received from remote Csw server" + (msg != null ? ": " + msg : ""));
LOGGER.info("Unable to parse exception report: {}", e.getMessage());
LOGGER.debug("Unable to parse exception report: {}", e);
}
if (msg != null) {
try {
JAXBElementProvider<ExceptionReport> provider = new JAXBElementProvider<ExceptionReport>();
Unmarshaller um = provider.getJAXBContext(ExceptionReport.class, ExceptionReport.class).createUnmarshaller();
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(msg));
ExceptionReport report = (ExceptionReport) um.unmarshal(xmlStreamReader);
cswException = convertToCswException(report);
} catch (JAXBException | XMLStreamException e) {
cswException = new CswException("Error received from remote Csw server: " + msg, e);
LOGGER.info("Error parsing the exception report: {}", e.getMessage());
LOGGER.debug("Error parsing the exception report", e);
}
}
} else {
cswException = new CswException("Error reading response, entity type not understood: " + response.getEntity().getClass().getName());
}
cswException.setHttpStatus(response.getStatus());
} else {
cswException = new CswException("Error handling response, response is null");
}
return cswException;
}
use of javax.xml.stream.XMLStreamException in project ddf by codice.
the class AbstractStsRealm method createClaimsElement.
/**
* Create the claims element with the claims provided in the STS client configuration in the
* admin console.
*/
protected Element createClaimsElement() {
Element claimsElement = null;
List<String> claims = new ArrayList<>();
claims.addAll(getClaims());
if (contextPolicyManager != null) {
Collection<ContextPolicy> contextPolicies = contextPolicyManager.getAllContextPolicies();
Set<String> attributes = new LinkedHashSet<>();
if (contextPolicies != null && contextPolicies.size() > 0) {
for (ContextPolicy contextPolicy : contextPolicies) {
attributes.addAll(contextPolicy.getAllowedAttributeNames());
}
}
if (attributes.size() > 0) {
claims.addAll(attributes);
}
}
if (claims.size() != 0) {
W3CDOMStreamWriter writer = null;
try {
writer = new W3CDOMStreamWriter();
writer.writeStartElement("wst", "Claims", STSUtils.WST_NS_05_12);
writer.writeNamespace("wst", STSUtils.WST_NS_05_12);
writer.writeNamespace("ic", "http://schemas.xmlsoap.org/ws/2005/05/identity");
writer.writeAttribute("Dialect", "http://schemas.xmlsoap.org/ws/2005/05/identity");
for (String claim : claims) {
LOGGER.trace("Claim: {}", claim);
writer.writeStartElement("ic", "ClaimType", "http://schemas.xmlsoap.org/ws/2005/05/identity");
writer.writeAttribute("Uri", claim);
writer.writeAttribute("Optional", "true");
writer.writeEndElement();
}
writer.writeEndElement();
claimsElement = writer.getDocument().getDocumentElement();
} catch (XMLStreamException e) {
String msg = "Unable to create claims. Subjects will not have any attributes. Check STS Client configuration.";
LOGGER.warn(msg, e);
claimsElement = null;
} finally {
if (writer != null) {
try {
writer.close();
} catch (XMLStreamException ignore) {
//ignore
}
}
}
if (LOGGER.isDebugEnabled()) {
if (claimsElement != null) {
LOGGER.debug("Claims: {}", getFormattedXml(claimsElement));
}
}
} else {
LOGGER.debug("There are no claims to process.");
claimsElement = null;
}
return claimsElement;
}
use of javax.xml.stream.XMLStreamException in project galley by Commonjava.
the class XMLInfrastructure method fallbackParseDocument.
private Document fallbackParseDocument(String xml, final Object docSource, final Exception e) throws GalleyMavenXMLException {
logger.debug("Failed to parse: {}. DOM error: {}. Trying STaX parse with IS_REPLACING_ENTITY_REFERENCES == false...", e, docSource, e.getMessage());
try {
Source source;
if (safeInputFactory != null) {
xml = repairXmlDeclaration(xml);
final XMLEventReader eventReader = safeInputFactory.createXMLEventReader(new StringReader(xml));
source = new StAXSource(eventReader);
} else {
// Deal with ø and other undeclared entities...
xml = escapeNonXMLEntityRefs(xml);
final XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://xml.org/sax/features/validation", false);
source = new SAXSource(reader, new InputSource(new StringReader(xml)));
}
final DOMResult result = new DOMResult();
final Transformer transformer = newTransformer();
transformer.transform(source, result);
return (Document) result.getNode();
} catch (final TransformerException e1) {
throw new GalleyMavenXMLException("Failed to parse: %s. Transformer error: %s.\nOriginal DOM error: %s", e1, docSource, e1.getMessage(), e.getMessage());
} catch (final SAXException e1) {
throw new GalleyMavenXMLException("Failed to parse: %s. SAX error: %s.\nOriginal DOM error: %s", e1, docSource, e1.getMessage(), e.getMessage());
} catch (final XMLStreamException e1) {
throw new GalleyMavenXMLException("Failed to parse: %s. STaX error: %s.\nOriginal DOM error: %s", e1, docSource, e1.getMessage(), e.getMessage());
}
}
Aggregations