From 616cb3968270be4fc6cc96c72ed967e27872fcfb Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Tue, 5 Jul 2022 20:37:05 +0000 Subject: [PATCH] GUACAMOLE-1372: Throw fatal exception if files are specified but unreadable. --- .../auth/saml/conf/ConfigurationService.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/extensions/guacamole-auth-sso/modules/guacamole-auth-sso-saml/src/main/java/org/apache/guacamole/auth/saml/conf/ConfigurationService.java b/extensions/guacamole-auth-sso/modules/guacamole-auth-sso-saml/src/main/java/org/apache/guacamole/auth/saml/conf/ConfigurationService.java index 026f17363..95862bd34 100644 --- a/extensions/guacamole-auth-sso/modules/guacamole-auth-sso-saml/src/main/java/org/apache/guacamole/auth/saml/conf/ConfigurationService.java +++ b/extensions/guacamole-auth-sso/modules/guacamole-auth-sso-saml/src/main/java/org/apache/guacamole/auth/saml/conf/ConfigurationService.java @@ -41,8 +41,6 @@ import org.apache.guacamole.properties.FileGuacamoleProperty; import org.apache.guacamole.properties.IntegerGuacamoleProperty; import org.apache.guacamole.properties.StringGuacamoleProperty; import org.apache.guacamole.properties.URIGuacamoleProperty; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Service for retrieving configuration information regarding the SAML @@ -50,11 +48,6 @@ import org.slf4j.LoggerFactory; */ 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 * SAML IdP. @@ -400,8 +393,8 @@ public class ConfigurationService { /** * 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 - * will be logged and null will be returned. + * a String. If the file does not exist, or cannot be read for any reason, an exception + * will be thrown with the details of the failure. * * @param file * 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. * * @return - * The contents of the file having the given path, or null if the file does not - * exist or cannot be read. + * The contents of the file having the given path. + * + * @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 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 catch (IOException e) { - logger.warn("{} \"{}\" could not be read: {}.", name, file, e.getMessage()); - logger.debug("{} \"{}\" could not be read.", name, file, e); - return null; + throw new GuacamoleServerException( + name + " at \"" + file.getAbsolutePath() + "\" could not be read.", e); } }