diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/form/NumericField.java b/guacamole-ext/src/main/java/org/apache/guacamole/form/NumericField.java index cc2e2a548..ce2dba496 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/form/NumericField.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/form/NumericField.java @@ -76,7 +76,7 @@ public class NumericField extends Field { return null; // Parse as integer - return new Integer(str); + return Integer.valueOf(str); } diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/IntegerGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/IntegerGuacamoleProperty.java index a9d3686c4..2228e2ea2 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/IntegerGuacamoleProperty.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/IntegerGuacamoleProperty.java @@ -35,8 +35,7 @@ public abstract class IntegerGuacamoleProperty implements GuacamoleProperty { return null; try { - Long longValue = new Long(value); - return longValue; + return Long.valueOf(value); } catch (NumberFormatException e) { throw new GuacamoleServerException("Property \"" + getName() + "\" must be an long.", e); diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java b/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java index eb9bf5dec..ed55290cf 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java @@ -84,6 +84,10 @@ public class DocumentHandler extends DefaultHandler { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + // If the SAX implementation does not provide the local name, the + // qualified name should be used instead + String name = localName.isEmpty() ? qName : localName; + // Get current state DocumentHandlerState current = getCurrentState(); @@ -94,7 +98,7 @@ public class DocumentHandler extends DefaultHandler { if (current == null) { // Validate element name - if (!localName.equals(rootElementName)) + if (!name.equals(rootElementName)) throw new SAXException("Root element must be '" + rootElementName + "'"); handler = root; @@ -103,12 +107,12 @@ public class DocumentHandler extends DefaultHandler { // Otherwise, get handler from parent else { TagHandler parent_handler = current.getTagHandler(); - handler = parent_handler.childElement(localName); + handler = parent_handler.childElement(name); } // If no handler returned, the element was not expected if (handler == null) - throw new SAXException("Unexpected element: '" + localName + "'"); + throw new SAXException("Unexpected element: '" + name + "'"); // Initialize handler handler.init(attributes); diff --git a/guacamole/src/main/java/org/apache/guacamole/auth/file/FileAuthenticationProvider.java b/guacamole/src/main/java/org/apache/guacamole/auth/file/FileAuthenticationProvider.java index 5f0bbdab2..53ae7ebe9 100644 --- a/guacamole/src/main/java/org/apache/guacamole/auth/file/FileAuthenticationProvider.java +++ b/guacamole/src/main/java/org/apache/guacamole/auth/file/FileAuthenticationProvider.java @@ -19,12 +19,12 @@ package org.apache.guacamole.auth.file; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.util.Map; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.environment.Environment; import org.apache.guacamole.environment.LocalEnvironment; @@ -34,10 +34,7 @@ import org.apache.guacamole.xml.DocumentHandler; import org.apache.guacamole.protocol.GuacamoleConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; /** * Authenticates users against a static list of username/password pairs. @@ -115,6 +112,22 @@ public class FileAuthenticationProvider extends SimpleAuthenticationProvider { logger.debug("Reading user mapping file: \"{}\"", userMappingFile); + // Set up XML parser + SAXParser parser; + try { + parser = SAXParserFactory.newInstance().newSAXParser(); + } + catch (ParserConfigurationException e) { + logger.error("Unable to create XML parser for reading \"{}\": {}", USER_MAPPING_FILENAME, e.getMessage()); + logger.debug("An instance of SAXParser could not be created.", e); + return null; + } + catch (SAXException e) { + logger.error("Unable to create XML parser for reading \"{}\": {}", USER_MAPPING_FILENAME, e.getMessage()); + logger.debug("An instance of SAXParser could not be created.", e); + return null; + } + // Parse document try { @@ -126,14 +139,8 @@ public class FileAuthenticationProvider extends SimpleAuthenticationProvider { DocumentHandler contentHandler = new DocumentHandler( "user-mapping", userMappingHandler); - // Set up XML parser - XMLReader parser = XMLReaderFactory.createXMLReader(); - parser.setContentHandler(contentHandler); - // Read and parse file - InputStream input = new BufferedInputStream(new FileInputStream(userMappingFile)); - parser.parse(new InputSource(input)); - input.close(); + parser.parse(userMappingFile, contentHandler); // Store mod time and user mapping lastModified = userMappingFile.lastModified();