Add hasNewCredentials() function to avoid uselessly hammering on auth logic.

This commit is contained in:
Michael Jumper
2013-08-07 16:15:54 -07:00
parent 857bd540dc
commit 7be306f1f4
2 changed files with 24 additions and 1 deletions

View File

@@ -200,6 +200,17 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet {
return (UserContext) session.getAttribute(CONTEXT_ATTRIBUTE); return (UserContext) session.getAttribute(CONTEXT_ATTRIBUTE);
} }
/**
* Returns whether the request given has updated credentials. If this
* function returns false, the UserContext will not be updated.
*
* @param request The request to check for credentials.
* @return true if the request contains credentials, false otherwise.
*/
protected boolean hasNewCredentials(HttpServletRequest request) {
return true;
}
@Override @Override
protected void service(HttpServletRequest request, HttpServletResponse response) protected void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException { throws IOException, ServletException {
@@ -247,7 +258,7 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet {
} }
// Otherwise, update existing context // Otherwise, update existing context
else else if (hasNewCredentials(request))
context = authProvider.updateUserContext(context, credentials); context = authProvider.updateUserContext(context, credentials);
// If no context, fail authentication, notify listeners // If no context, fail authentication, notify listeners

View File

@@ -251,5 +251,17 @@ public class BasicGuacamoleTunnelServlet extends AuthenticatingHttpServlet {
}; };
@Override
protected boolean hasNewCredentials(HttpServletRequest request) {
String query = request.getQueryString();
if (query == null)
return false;
// Only connections are given new credentials
return query.equals("connect");
}
} }