use of javax.xml.stream.XMLStreamException in project spring-framework by spring-projects.
the class AbstractStaxHandler method startDocument.
@Override
public final void startDocument() throws SAXException {
removeAllNamespaceMappings();
newNamespaceMapping();
try {
startDocumentInternal();
} catch (XMLStreamException ex) {
throw new SAXException("Could not handle startDocument: " + ex.getMessage(), ex);
}
}
use of javax.xml.stream.XMLStreamException in project spring-framework by spring-projects.
the class AbstractXMLStreamReader method getElementText.
@Override
public String getElementText() throws XMLStreamException {
if (getEventType() != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException("parser must be on START_ELEMENT to read next text", getLocation());
}
int eventType = next();
StringBuilder builder = new StringBuilder();
while (eventType != XMLStreamConstants.END_ELEMENT) {
if (eventType == XMLStreamConstants.CHARACTERS || eventType == XMLStreamConstants.CDATA || eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
builder.append(getText());
} else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT) {
// skipping
} else if (eventType == XMLStreamConstants.END_DOCUMENT) {
throw new XMLStreamException("unexpected end of document when reading element text content", getLocation());
} else if (eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException("element text content may not contain START_ELEMENT", getLocation());
} else {
throw new XMLStreamException("Unexpected event type " + eventType, getLocation());
}
eventType = next();
}
return builder.toString();
}
use of javax.xml.stream.XMLStreamException in project ddf by codice.
the class AssertionConsumerService method processSoapResponse.
@POST
@Consumes({ "text/xml", "application/soap+xml" })
public Response processSoapResponse(InputStream body, @Context HttpServletRequest request) {
try {
SOAPPart soapMessage = SamlProtocol.parseSoapMessage(IOUtils.toString(body));
String relayState = getRelayState(soapMessage);
org.opensaml.saml.saml2.core.Response samlpResponse = getSamlpResponse(soapMessage);
boolean validateResponse = validateResponse(samlpResponse);
if (validateResponse) {
return processSamlResponse(samlpResponse, relayState);
}
} catch (XMLStreamException e) {
LOGGER.debug("Unable to parse SOAP message from response.", e);
} catch (IOException e) {
LOGGER.debug("Unable to get SAMLP response.", e);
} catch (SOAPException e) {
LOGGER.debug("Unable to get relay state from response.", e);
}
return Response.serverError().entity("Invalid AuthN response.").build();
}
use of javax.xml.stream.XMLStreamException in project ddf by codice.
the class DynamicSchemaResolver method addFields.
/**
* Adds the fields of the Metacard into the {@link SolrInputDocument}
*/
public void addFields(Metacard metacard, SolrInputDocument solrInputDocument) throws MetacardCreationException {
MetacardType schema = metacard.getMetacardType();
for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
if (metacard.getAttribute(ad.getName()) != null) {
List<Serializable> attributeValues = metacard.getAttribute(ad.getName()).getValues();
if (attributeValues != null && attributeValues.size() > 0 && attributeValues.get(0) != null) {
AttributeFormat format = ad.getType().getAttributeFormat();
String formatIndexName = ad.getName() + getFieldSuffix(format);
if (AttributeFormat.XML.equals(format)) {
List<String> parsedTexts = parseTextFrom(attributeValues);
// text => metadata_txt_ws
String whitespaceTokenizedIndexName = ad.getName() + getFieldSuffix(AttributeFormat.STRING) + SchemaFields.WHITESPACE_TEXT_SUFFIX;
solrInputDocument.addField(whitespaceTokenizedIndexName, parsedTexts);
// text => metadata_txt_ws_has_case
String whiteSpaceTokenizedHasCaseIndexName = ad.getName() + getFieldSuffix(AttributeFormat.STRING) + SchemaFields.WHITESPACE_TEXT_SUFFIX + SchemaFields.HAS_CASE;
solrInputDocument.addField(whiteSpaceTokenizedHasCaseIndexName, parsedTexts);
// text => metadata_txt_tokenized
String specialStringIndexName = ad.getName() + getFieldSuffix(AttributeFormat.STRING) + getSpecialIndexSuffix(AttributeFormat.STRING);
solrInputDocument.addField(specialStringIndexName, parsedTexts);
// text case sensitive
solrInputDocument.addField(specialStringIndexName + SchemaFields.HAS_CASE, parsedTexts);
} else if (AttributeFormat.OBJECT.equals(format)) {
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
List<Serializable> byteArrays = new ArrayList<>();
try (ObjectOutputStream out = new ObjectOutputStream(byteArrayOS)) {
for (Serializable serializable : attributeValues) {
out.writeObject(serializable);
byteArrays.add(byteArrayOS.toByteArray());
out.reset();
}
} catch (IOException e) {
throw new MetacardCreationException(COULD_NOT_SERIALIZE_OBJECT_MESSAGE, e);
}
attributeValues = byteArrays;
}
// Prevent adding a field already on document
if (solrInputDocument.getFieldValue(formatIndexName) == null) {
solrInputDocument.addField(formatIndexName, attributeValues);
if (AttributeFormat.GEOMETRY.equals(format)) {
solrInputDocument.addField(formatIndexName + SchemaFields.SORT_KEY_SUFFIX, createCenterPoint(attributeValues));
} else if (!(AttributeFormat.BINARY.equals(format) || AttributeFormat.OBJECT.equals(format))) {
solrInputDocument.addField(formatIndexName + SchemaFields.SORT_KEY_SUFFIX, attributeValues.get(0));
}
} else {
LOGGER.trace("Skipping adding field already found on document ({})", formatIndexName);
}
}
}
}
if (!ConfigurationStore.getInstance().isDisableTextPath()) {
if (StringUtils.isNotBlank(metacard.getMetadata())) {
try {
byte[] luxXml = createTinyBinary(metacard.getMetadata());
solrInputDocument.addField(LUX_XML_FIELD_NAME, luxXml);
} catch (XMLStreamException | SaxonApiException e) {
LOGGER.debug("Unable to parse metadata field. XPath support unavailable for metacard {}", metacard.getId());
}
}
}
/*
* Lastly the metacardType must be added to the solr document. These are internal fields
*/
String schemaName = String.format("%s#%s", schema.getName(), schema.hashCode());
solrInputDocument.addField(SchemaFields.METACARD_TYPE_FIELD_NAME, schemaName);
byte[] metacardTypeBytes = metacardTypeNameToSerialCache.getIfPresent(schemaName);
if (metacardTypeBytes == null) {
MetacardType coreMetacardType = new MetacardTypeImpl(schema.getName(), convertAttributeDescriptors(schema.getAttributeDescriptors()));
metacardTypesCache.put(schemaName, coreMetacardType);
metacardTypeBytes = serialize(coreMetacardType);
metacardTypeNameToSerialCache.put(schemaName, metacardTypeBytes);
addToFieldsCache(coreMetacardType.getAttributeDescriptors());
}
solrInputDocument.addField(SchemaFields.METACARD_TYPE_OBJECT_FIELD_NAME, metacardTypeBytes);
}
use of javax.xml.stream.XMLStreamException in project ddf by codice.
the class IdpEndpoint method determineAuthMethod.
private AuthObj determineAuthMethod(String bodyStr, AuthnRequest authnRequest) {
XMLStreamReader xmlStreamReader = null;
try {
xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(bodyStr));
} catch (XMLStreamException e) {
LOGGER.debug("Unable to parse SOAP message from client.", e);
}
SoapMessage soapMessage = new SoapMessage(Soap11.getInstance());
SAAJInInterceptor.SAAJPreInInterceptor preInInterceptor = new SAAJInInterceptor.SAAJPreInInterceptor();
soapMessage.setContent(XMLStreamReader.class, xmlStreamReader);
preInInterceptor.handleMessage(soapMessage);
SAAJInInterceptor inInterceptor = new SAAJInInterceptor();
inInterceptor.handleMessage(soapMessage);
SOAPPart soapMessageContent = (SOAPPart) soapMessage.getContent(Node.class);
AuthObj authObj = new AuthObj();
try {
Iterator soapHeaderElements = soapMessageContent.getEnvelope().getHeader().examineAllHeaderElements();
while (soapHeaderElements.hasNext()) {
SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) soapHeaderElements.next();
if (soapHeaderElement.getLocalName().equals("Security")) {
Iterator childElements = soapHeaderElement.getChildElements();
while (childElements.hasNext()) {
Object nextElement = childElements.next();
if (nextElement instanceof SOAPElement) {
SOAPElement element = (SOAPElement) nextElement;
if (element.getLocalName().equals("UsernameToken")) {
Iterator usernameTokenElements = element.getChildElements();
Object next;
while (usernameTokenElements.hasNext()) {
if ((next = usernameTokenElements.next()) instanceof Element) {
Element nextEl = (Element) next;
if (nextEl.getLocalName().equals("Username")) {
authObj.username = nextEl.getTextContent();
} else if (nextEl.getLocalName().equals("Password")) {
authObj.password = nextEl.getTextContent();
}
}
}
if (authObj.username != null && authObj.password != null) {
authObj.method = USER_PASS;
break;
}
} else if (element.getLocalName().equals("Assertion") && element.getNamespaceURI().equals("urn:oasis:names:tc:SAML:2.0:assertion")) {
authObj.assertion = new SecurityToken(element.getAttribute("ID"), element, null, null);
authObj.method = SAML;
break;
}
}
}
}
}
} catch (SOAPException e) {
LOGGER.debug("Unable to parse SOAP message.", e);
}
RequestedAuthnContext requestedAuthnContext = authnRequest.getRequestedAuthnContext();
boolean requestingPki = false;
boolean requestingUp = false;
if (requestedAuthnContext != null) {
List<AuthnContextClassRef> authnContextClassRefs = requestedAuthnContext.getAuthnContextClassRefs();
for (AuthnContextClassRef authnContextClassRef : authnContextClassRefs) {
String authnContextClassRefStr = authnContextClassRef.getAuthnContextClassRef();
if (SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SMARTCARD_PKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SOFTWARE_PKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SPKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_TLS_CLIENT.equals(authnContextClassRefStr)) {
requestingPki = true;
} else if (SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT.equals(authnContextClassRefStr)) {
requestingUp = true;
}
}
} else {
//The requested auth context isn't required so we don't know what they want... just set both to true
requestingPki = true;
requestingUp = true;
}
if (requestingUp && authObj.method != null && authObj.method.equals(USER_PASS)) {
LOGGER.trace("Found UsernameToken and correct AuthnContextClassRef");
return authObj;
} else if (requestingPki && authObj.method == null) {
LOGGER.trace("Found no token, but client requested PKI AuthnContextClassRef");
authObj.method = PKI;
return authObj;
} else if (authObj.method == null) {
LOGGER.debug("No authentication tokens found for the current request and the client did not request PKI authentication");
}
return authObj;
}
Aggregations