mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Code cleanup, add backwards compatibility.
This commit is contained in:
@@ -2,15 +2,10 @@
|
|||||||
|
|
||||||
<!-- Per-user authentication and config information -->
|
<!-- Per-user authentication and config information -->
|
||||||
<authorize username="USERNAME" password="PASSWORD">
|
<authorize username="USERNAME" password="PASSWORD">
|
||||||
|
<protocol>vnc</protocol>
|
||||||
<!-- Single authorized connection -->
|
<param name="hostname">localhost</param>
|
||||||
<connection name="localhost">
|
<param name="port">5900</param>
|
||||||
<protocol>vnc</protocol>
|
<param name="password">VNCPASS</param>
|
||||||
<param name="hostname">localhost</param>
|
|
||||||
<param name="port">5900</param>
|
|
||||||
<param name="password">VNCPASS</param>
|
|
||||||
</connection>
|
|
||||||
|
|
||||||
</authorize>
|
</authorize>
|
||||||
|
|
||||||
<!-- Another user, but using md5 to hash the password
|
<!-- Another user, but using md5 to hash the password
|
||||||
|
@@ -49,9 +49,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
* Each username/password may be associated with multiple configurations.
|
* Each username/password may be associated with multiple configurations.
|
||||||
* This list is stored in an XML file which is reread if modified.
|
* This list is stored in an XML file which is reread if modified.
|
||||||
*
|
*
|
||||||
* This is modified version of BasicFileAuthenticationProvider written by Michael Jumper.
|
* @author Michael Jumper, Michal Kotas
|
||||||
*
|
|
||||||
* @author Michal Kotas
|
|
||||||
*/
|
*/
|
||||||
public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
||||||
|
|
||||||
@@ -137,15 +135,8 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
|||||||
|
|
||||||
// Validate and return info for given user and pass
|
// Validate and return info for given user and pass
|
||||||
AuthInfo info = mapping.get(credentials.getUsername());
|
AuthInfo info = mapping.get(credentials.getUsername());
|
||||||
if (info != null && info.validate(credentials.getUsername(), credentials.getPassword())) {
|
if (info != null && info.validate(credentials.getUsername(), credentials.getPassword()))
|
||||||
|
return info.getConfigurations();
|
||||||
//Map<String, GuacamoleConfiguration> configs = new HashMap<String, GuacamoleConfiguration>();
|
|
||||||
//configs.put("DEFAULT", info.getConfiguration());
|
|
||||||
//return configs;
|
|
||||||
|
|
||||||
Map<String, GuacamoleConfiguration> configs = info.getConfigurations();
|
|
||||||
return configs;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unauthorized
|
// Unauthorized
|
||||||
return null;
|
return null;
|
||||||
@@ -227,15 +218,21 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GuacamoleConfiguration getConfiguration(String name) {
|
public GuacamoleConfiguration getConfiguration(String name) {
|
||||||
//return configs;
|
|
||||||
return configs.get(name);
|
// Create new configuration if not already in map
|
||||||
|
GuacamoleConfiguration config = configs.get(name);
|
||||||
|
if (config == null) {
|
||||||
|
config = new GuacamoleConfiguration();
|
||||||
|
configs.put(name, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, GuacamoleConfiguration> getConfigurations() {
|
public Map<String, GuacamoleConfiguration> getConfigurations() {
|
||||||
return configs;
|
return configs;
|
||||||
}
|
}
|
||||||
public void addConfiguration(String name) {
|
|
||||||
configs.put(name, new GuacamoleConfiguration());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,10 +247,19 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
|||||||
private enum State {
|
private enum State {
|
||||||
ROOT,
|
ROOT,
|
||||||
USER_MAPPING,
|
USER_MAPPING,
|
||||||
CONNECTION,
|
|
||||||
|
/* Username/password pair */
|
||||||
AUTH_INFO,
|
AUTH_INFO,
|
||||||
|
|
||||||
|
/* Connection configuration information */
|
||||||
|
CONNECTION,
|
||||||
PROTOCOL,
|
PROTOCOL,
|
||||||
PARAMETER,
|
PARAMETER,
|
||||||
|
|
||||||
|
/* Configuration information associated with default connection */
|
||||||
|
DEFAULT_CONNECTION_PROTOCOL,
|
||||||
|
DEFAULT_CONNECTION_PARAMETER,
|
||||||
|
|
||||||
END;
|
END;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,6 +325,24 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DEFAULT_CONNECTION_PROTOCOL:
|
||||||
|
|
||||||
|
if (localName.equals("protocol")) {
|
||||||
|
state = State.AUTH_INFO;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEFAULT_CONNECTION_PARAMETER:
|
||||||
|
|
||||||
|
if (localName.equals("param")) {
|
||||||
|
state = State.AUTH_INFO;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new SAXException("Tag not yet complete: " + localName);
|
throw new SAXException("Tag not yet complete: " + localName);
|
||||||
@@ -377,13 +401,35 @@ public class BasicFileAuthenticationProvider implements AuthenticationProvider {
|
|||||||
if (currentConnection == null)
|
if (currentConnection == null)
|
||||||
throw new SAXException("Attribute \"name\" required for connection tag.");
|
throw new SAXException("Attribute \"name\" required for connection tag.");
|
||||||
|
|
||||||
current.addConfiguration(currentConnection);
|
|
||||||
|
|
||||||
// Next state
|
// Next state
|
||||||
state = State.CONNECTION;
|
state = State.CONNECTION;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (localName.equals("protocol")) {
|
||||||
|
|
||||||
|
// Associate protocol with default connection
|
||||||
|
currentConnection = "DEFAULT";
|
||||||
|
|
||||||
|
// Next state
|
||||||
|
state = State.DEFAULT_CONNECTION_PROTOCOL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localName.equals("param")) {
|
||||||
|
|
||||||
|
// Associate parameter with default connection
|
||||||
|
currentConnection = "DEFAULT";
|
||||||
|
|
||||||
|
currentParameter = attributes.getValue("name");
|
||||||
|
if (currentParameter == null)
|
||||||
|
throw new SAXException("Attribute \"name\" required for param tag.");
|
||||||
|
|
||||||
|
// Next state
|
||||||
|
state = State.DEFAULT_CONNECTION_PARAMETER;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONNECTION:
|
case CONNECTION:
|
||||||
|
Reference in New Issue
Block a user