Include exceptions in logger errors.
[guacamole.git] / src / main / java / net / sourceforge / guacamole / net / basic / AuthenticatingHttpServlet.java
index bf227f7..12c480e 100644 (file)
@@ -44,6 +44,16 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet {
     private Logger logger = LoggerFactory.getLogger(AuthenticatingHttpServlet.class);
     
     /**
+     * The session attribute holding the map of configurations.
+     */
+    private static final String CONFIGURATIONS_ATTRIBUTE = "GUAC_CONFIGS";
+    
+    /**
+     * The session attribute holding the credentials authorizing this session.
+     */
+    private static final String CREDENTIALS_ATTRIBUTE = "GUAC_CREDS";
+    
+    /**
      * The error message to be provided to the client user if authentication
      * fails for ANY REASON.
      */
@@ -140,7 +150,6 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet {
      * @throws IOException If an error occurs while sending the error.
      */
     private void failAuthentication(HttpServletResponse response) throws IOException {
-        response.setHeader("X-Guacamole-Error-Message", AUTH_ERROR_MESSAGE);
         response.sendError(HttpServletResponse.SC_FORBIDDEN);
     }
     
@@ -151,7 +160,7 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet {
      * @return The credentials associated with the given session.
      */
     protected Credentials getCredentials(HttpSession session) {
-        return (Credentials) session.getAttribute("GUAC_CREDS");
+        return (Credentials) session.getAttribute(CREDENTIALS_ATTRIBUTE);
     }
 
     /**
@@ -161,7 +170,7 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet {
      * @return The configurations associated with the given session.
      */
     protected Map<String, GuacamoleConfiguration> getConfigurations(HttpSession session) {
-        return (Map<String, GuacamoleConfiguration>) session.getAttribute("GUAC_CONFIGS");
+        return (Map<String, GuacamoleConfiguration>) session.getAttribute(CONFIGURATIONS_ATTRIBUTE);
     }
     
     @Override
@@ -209,7 +218,7 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet {
             // If error retrieving configs, fail authentication, notify listeners
             catch (GuacamoleException e) {
                 logger.error("Error retrieving configuration(s) for user \"{}\".",
-                        credentials.getUsername());
+                        credentials.getUsername(), e);
 
                 notifyFailed(listeners, credentials);
                 failAuthentication(response);
@@ -246,15 +255,15 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet {
             catch (GuacamoleException e) {
                 
                 // Cancel authentication success if hook throws exception
-                logger.error("Successful authentication canceled by error in hook.");
+                logger.error("Successful authentication canceled by error in hook.", e);
                 failAuthentication(response);
                 return;
                 
             }
 
             // Associate configs and credentials with session
-            httpSession.setAttribute("GUAC_CONFIGS", configs);
-            httpSession.setAttribute("GUAC_CREDS",   credentials);
+            httpSession.setAttribute(CONFIGURATIONS_ATTRIBUTE, configs);
+            httpSession.setAttribute(CREDENTIALS_ATTRIBUTE,    credentials);
 
 
         }