mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-243: Clean up code, remove unnecessary items, add JavaDocs, etc.
This commit is contained in:
@@ -121,8 +121,7 @@ public class LDAPConnectionService {
|
|||||||
// Set whether or not we follow referrals
|
// Set whether or not we follow referrals
|
||||||
ldapConstraints.setReferralFollowing(confService.getFollowReferrals());
|
ldapConstraints.setReferralFollowing(confService.getFollowReferrals());
|
||||||
|
|
||||||
// If the referral auth method is set to bind, we set it using the existing
|
// Set referral authentication to use the provided credentials.
|
||||||
// username and password.
|
|
||||||
if (userDN != null && !userDN.isEmpty())
|
if (userDN != null && !userDN.isEmpty())
|
||||||
ldapConstraints.setReferralHandler(new ReferralAuthHandler(userDN, password));
|
ldapConstraints.setReferralHandler(new ReferralAuthHandler(userDN, password));
|
||||||
|
|
||||||
|
@@ -28,6 +28,10 @@ import org.apache.guacamole.GuacamoleException;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that implements the necessary authentication handling
|
||||||
|
* for following referrals in LDAP connections.
|
||||||
|
*/
|
||||||
public class ReferralAuthHandler implements LDAPAuthHandler {
|
public class ReferralAuthHandler implements LDAPAuthHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,35 +45,14 @@ public class ReferralAuthHandler implements LDAPAuthHandler {
|
|||||||
private final LDAPAuthProvider ldapAuth;
|
private final LDAPAuthProvider ldapAuth;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for retrieving LDAP server configuration information.
|
* Creates a ReferralAuthHandler object to handle authentication when
|
||||||
|
* following referrals in a LDAP connection, using the provided dn and
|
||||||
|
* password.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException
|
||||||
|
* If exceptions are caught while converting the password from a string
|
||||||
|
* into a byte array.
|
||||||
*/
|
*/
|
||||||
@Inject
|
|
||||||
private ConfigurationService confService;
|
|
||||||
|
|
||||||
|
|
||||||
public ReferralAuthHandler() throws GuacamoleException {
|
|
||||||
String binddn = confService.getSearchBindDN();
|
|
||||||
String password = confService.getSearchBindPassword();
|
|
||||||
byte[] passwordBytes;
|
|
||||||
try {
|
|
||||||
|
|
||||||
// Convert password into corresponding byte array
|
|
||||||
if (password != null)
|
|
||||||
passwordBytes = password.getBytes("UTF-8");
|
|
||||||
else
|
|
||||||
passwordBytes = null;
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (UnsupportedEncodingException e) {
|
|
||||||
logger.error("Unexpected lack of support for UTF-8: {}", e.getMessage());
|
|
||||||
logger.debug("Support for UTF-8 (as required by Java spec) not found.", e);
|
|
||||||
throw new GuacamoleException("Could not set password due to missing support for UTF-8 encoding.");
|
|
||||||
}
|
|
||||||
|
|
||||||
ldapAuth = new LDAPAuthProvider(binddn, passwordBytes);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReferralAuthHandler(String dn, String password) throws GuacamoleException {
|
public ReferralAuthHandler(String dn, String password) throws GuacamoleException {
|
||||||
byte[] passwordBytes;
|
byte[] passwordBytes;
|
||||||
try {
|
try {
|
||||||
|
@@ -277,14 +277,13 @@ public class ConnectionService {
|
|||||||
|
|
||||||
catch (LDAPReferralException e) {
|
catch (LDAPReferralException e) {
|
||||||
if (confService.getFollowReferrals()) {
|
if (confService.getFollowReferrals()) {
|
||||||
logger.error("Could not follow referral.", e.getMessage());
|
logger.error("Could not follow referral: {}", e.getFailedReferral());
|
||||||
logger.debug("Error encountered trying to follow referral.", e);
|
logger.debug("Error encountered trying to follow referral.", e);
|
||||||
throw new GuacamoleServerException("Could not follow LDAP referral.", e);
|
throw new GuacamoleServerException("Could not follow LDAP referral.", e);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.warn("Given a referral, but referrals are disabled.", e.getMessage());
|
logger.warn("Given a referral, but referrals are disabled.", e.getMessage());
|
||||||
logger.debug("Got a referral, but configured to not follow them.", e);
|
logger.debug("Got a referral, but configured to not follow them.", e);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -129,14 +129,13 @@ public class UserService {
|
|||||||
// Deal with errors trying to follow referrals
|
// Deal with errors trying to follow referrals
|
||||||
catch (LDAPReferralException e) {
|
catch (LDAPReferralException e) {
|
||||||
if (confService.getFollowReferrals()) {
|
if (confService.getFollowReferrals()) {
|
||||||
logger.error("Could not follow referral.", e.getFailedReferral());
|
logger.error("Could not follow referral: {}", e.getFailedReferral());
|
||||||
logger.debug("Error encountered trying to follow referral.", e);
|
logger.debug("Error encountered trying to follow referral.", e);
|
||||||
throw new GuacamoleServerException("Could not follow LDAP referral.", e);
|
throw new GuacamoleServerException("Could not follow LDAP referral.", e);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.warn("Given a referral, but referrals are disabled.", e.getMessage());
|
logger.warn("Given a referral, but referrals are disabled.", e.getMessage());
|
||||||
logger.debug("Got a referral, but configured to not follow them.", e);
|
logger.debug("Got a referral, but configured to not follow them.", e);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user