mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Automatic reloading of password file
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
package net.sourceforge.guacamole.basic;
|
package net.sourceforge.guacamole.basic;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
@@ -16,6 +17,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
|
|
||||||
public class BasicLogin extends HttpServlet {
|
public class BasicLogin extends HttpServlet {
|
||||||
|
|
||||||
|
private long mappingTime;
|
||||||
private Map<String, AuthInfo> mapping;
|
private Map<String, AuthInfo> mapping;
|
||||||
|
|
||||||
// Added to session when session validated
|
// Added to session when session validated
|
||||||
@@ -51,13 +53,24 @@ public class BasicLogin extends HttpServlet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private File getUserMappingFile() {
|
||||||
public void init() throws ServletException {
|
|
||||||
|
|
||||||
// Get user mapping filename
|
// Get user mapping filename
|
||||||
ServletContext context = getServletContext();
|
ServletContext context = getServletContext();
|
||||||
String filename = context.getInitParameter("basic-user-mapping");
|
String filename = context.getInitParameter("basic-user-mapping");
|
||||||
if (filename == null)
|
if (filename == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new File(filename);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void init() throws ServletException {
|
||||||
|
|
||||||
|
// Get user mapping file
|
||||||
|
File mapFile = getUserMappingFile();
|
||||||
|
if (mapFile == null)
|
||||||
throw new ServletException("Missing \"basic-user-mapping\" parameter required for basic login.");
|
throw new ServletException("Missing \"basic-user-mapping\" parameter required for basic login.");
|
||||||
|
|
||||||
// Parse document
|
// Parse document
|
||||||
@@ -67,8 +80,9 @@ public class BasicLogin extends HttpServlet {
|
|||||||
|
|
||||||
XMLReader parser = XMLReaderFactory.createXMLReader();
|
XMLReader parser = XMLReaderFactory.createXMLReader();
|
||||||
parser.setContentHandler(contentHandler);
|
parser.setContentHandler(contentHandler);
|
||||||
parser.parse(filename);
|
parser.parse(mapFile.getAbsolutePath());
|
||||||
|
|
||||||
|
mappingTime = mapFile.lastModified();
|
||||||
mapping = contentHandler.getUserMapping();
|
mapping = contentHandler.getUserMapping();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -79,12 +93,23 @@ public class BasicLogin extends HttpServlet {
|
|||||||
throw new ServletException("Error parsing basic user mapping XML.", e);
|
throw new ServletException("Error parsing basic user mapping XML.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
|
||||||
|
// Check mapping file mod time
|
||||||
|
File userMappingFile = getUserMappingFile();
|
||||||
|
if (userMappingFile.exists() && mappingTime < userMappingFile.lastModified()) {
|
||||||
|
|
||||||
|
// If modified recently, gain exclusive access and recheck
|
||||||
|
synchronized (this) {
|
||||||
|
if (userMappingFile.exists() && mappingTime < userMappingFile.lastModified())
|
||||||
|
init(); // If still not up to date, re-init
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve username and password from parms
|
// Retrieve username and password from parms
|
||||||
String username = req.getParameter("username");
|
String username = req.getParameter("username");
|
||||||
String password = req.getParameter("password");
|
String password = req.getParameter("password");
|
||||||
|
Reference in New Issue
Block a user