GUACAMOLE-1372: Throw fatal exception if files are specified but unreadable.

This commit is contained in:
James Muehlner
2022-07-05 20:37:05 +00:00
parent 025e831b3d
commit 616cb39682

View File

@@ -41,8 +41,6 @@ import org.apache.guacamole.properties.FileGuacamoleProperty;
import org.apache.guacamole.properties.IntegerGuacamoleProperty; import org.apache.guacamole.properties.IntegerGuacamoleProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty; import org.apache.guacamole.properties.StringGuacamoleProperty;
import org.apache.guacamole.properties.URIGuacamoleProperty; import org.apache.guacamole.properties.URIGuacamoleProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Service for retrieving configuration information regarding the SAML * Service for retrieving configuration information regarding the SAML
@@ -50,11 +48,6 @@ import org.slf4j.LoggerFactory;
*/ */
public class ConfigurationService { public class ConfigurationService {
/**
* Logger for this class.
*/
private static final Logger logger = LoggerFactory.getLogger(ConfigurationService.class);
/** /**
* The URI of the file containing the XML Metadata associated with the * The URI of the file containing the XML Metadata associated with the
* SAML IdP. * SAML IdP.
@@ -400,8 +393,8 @@ public class ConfigurationService {
/** /**
* Returns the contents of a small file, such as a private key or certificate into * Returns the contents of a small file, such as a private key or certificate into
* a String. If the file does not exist, or cannot be read for any reason, a warning * a String. If the file does not exist, or cannot be read for any reason, an exception
* will be logged and null will be returned. * will be thrown with the details of the failure.
* *
* @param file * @param file
* The file to read into a string. * The file to read into a string.
@@ -410,10 +403,12 @@ public class ConfigurationService {
* A human-readable name for the file, to be used when formatting log messages. * A human-readable name for the file, to be used when formatting log messages.
* *
* @return * @return
* The contents of the file having the given path, or null if the file does not * The contents of the file having the given path.
* exist or cannot be read. *
* @throws GuacamoleException
* If the provided file does not exist, or cannot be read for any reason.
*/ */
private String readFileContentsIntoString(File file, String name) { private String readFileContentsIntoString(File file, String name) throws GuacamoleException {
// Attempt to read the file directly into a String // Attempt to read the file directly into a String
try { try {
@@ -422,9 +417,8 @@ public class ConfigurationService {
// If the file cannot be read, log a warning and treat it as if it does not exist // If the file cannot be read, log a warning and treat it as if it does not exist
catch (IOException e) { catch (IOException e) {
logger.warn("{} \"{}\" could not be read: {}.", name, file, e.getMessage()); throw new GuacamoleServerException(
logger.debug("{} \"{}\" could not be read.", name, file, e); name + " at \"" + file.getAbsolutePath() + "\" could not be read.", e);
return null;
} }
} }