mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
MD5 encoding, fixed build.xml
This commit is contained in:
@@ -66,7 +66,7 @@
|
|||||||
|
|
||||||
<copy todir="${tar.dir}">
|
<copy todir="${tar.dir}">
|
||||||
<fileset file="${doc.dir}/example/guacamole.xml"/>
|
<fileset file="${doc.dir}/example/guacamole.xml"/>
|
||||||
<fileset file="${doc.dir}/example/guacamole-users.xml"/>
|
<fileset file="${doc.dir}/example/user-mapping.xml"/>
|
||||||
<fileset file="${dist.dir}/guacamole.war"/>
|
<fileset file="${dist.dir}/guacamole.war"/>
|
||||||
<fileset file="LICENSE.txt"/>
|
<fileset file="LICENSE.txt"/>
|
||||||
</copy>
|
</copy>
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
package net.sourceforge.guacamole.basic;
|
package net.sourceforge.guacamole.basic;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -16,19 +18,26 @@ public class BasicUserMappingContentHandler extends DefaultHandler {
|
|||||||
return Collections.unmodifiableMap(authMapping);
|
return Collections.unmodifiableMap(authMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AuthInfo {
|
public static class AuthInfo {
|
||||||
|
|
||||||
|
public static enum Encoding {
|
||||||
|
PLAIN_TEXT,
|
||||||
|
MD5
|
||||||
|
}
|
||||||
|
|
||||||
private String auth_username;
|
private String auth_username;
|
||||||
private String auth_password;
|
private String auth_password;
|
||||||
|
private Encoding auth_encoding;
|
||||||
|
|
||||||
private String protocol;
|
private String protocol;
|
||||||
private String hostname;
|
private String hostname;
|
||||||
private int port;
|
private int port;
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
public AuthInfo(String auth_username, String auth_password) {
|
public AuthInfo(String auth_username, String auth_password, Encoding auth_encoding) {
|
||||||
this.auth_username = auth_username;
|
this.auth_username = auth_username;
|
||||||
this.auth_password = auth_password;
|
this.auth_password = auth_password;
|
||||||
|
this.auth_encoding = auth_encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthorizedUsername() {
|
public String getAuthorizedUsername() {
|
||||||
@@ -38,6 +47,59 @@ public class BasicUserMappingContentHandler extends DefaultHandler {
|
|||||||
public String getAuthorizedPassword() {
|
public String getAuthorizedPassword() {
|
||||||
return auth_password;
|
return auth_password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final char HEX_CHARS[] = {
|
||||||
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||||
|
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||||
|
};
|
||||||
|
|
||||||
|
public static String getHexString(byte[] bytes) {
|
||||||
|
|
||||||
|
if (bytes == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
StringBuilder hex = new StringBuilder(2 * bytes.length);
|
||||||
|
for (byte b : bytes) {
|
||||||
|
hex.append(HEX_CHARS[(b & 0xF0) >> 4])
|
||||||
|
.append(HEX_CHARS[(b & 0x0F) ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hex.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean validate(String username, String password) {
|
||||||
|
|
||||||
|
// If username matches
|
||||||
|
if (username != null && password != null && username.equals(auth_username)) {
|
||||||
|
|
||||||
|
switch (auth_encoding) {
|
||||||
|
|
||||||
|
case PLAIN_TEXT:
|
||||||
|
|
||||||
|
// Compare plaintext
|
||||||
|
return password.equals(auth_password);
|
||||||
|
|
||||||
|
case MD5:
|
||||||
|
|
||||||
|
// Compare hashed password
|
||||||
|
try {
|
||||||
|
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||||
|
String hashedPassword = getHexString(digest.digest(password.getBytes()));
|
||||||
|
return hashedPassword.equals(auth_password);
|
||||||
|
}
|
||||||
|
catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new UnsupportedOperationException("Unexpected lack of MD5 support.", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
return hostname;
|
return hostname;
|
||||||
@@ -90,9 +152,22 @@ public class BasicUserMappingContentHandler extends DefaultHandler {
|
|||||||
|
|
||||||
if (localName.equals("authorize")) {
|
if (localName.equals("authorize")) {
|
||||||
|
|
||||||
|
AuthInfo.Encoding encoding;
|
||||||
|
String encodingString = attributes.getValue("encoding");
|
||||||
|
if (encodingString == null)
|
||||||
|
encoding = AuthInfo.Encoding.PLAIN_TEXT;
|
||||||
|
else if (encodingString.equals("plain"))
|
||||||
|
encoding = AuthInfo.Encoding.PLAIN_TEXT;
|
||||||
|
else if (encodingString.equals("md5"))
|
||||||
|
encoding = AuthInfo.Encoding.MD5;
|
||||||
|
else
|
||||||
|
throw new SAXException("Invalid encoding type");
|
||||||
|
|
||||||
|
|
||||||
current = new AuthInfo(
|
current = new AuthInfo(
|
||||||
attributes.getValue("username"),
|
attributes.getValue("username"),
|
||||||
attributes.getValue("password")
|
attributes.getValue("password"),
|
||||||
|
encoding
|
||||||
);
|
);
|
||||||
|
|
||||||
infoState = null;
|
infoState = null;
|
||||||
|
Reference in New Issue
Block a user