GUACAMOLE-524: Fixed try block, exceptions, and import order
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/00b33dae Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/00b33dae Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/00b33dae Branch: refs/heads/master Commit: 00b33daea7f678d2af56d43427d8dd8edd12531a Parents: d27f8f9 Author: Jared Frees <frees...@osu.edu> Authored: Tue Jun 12 11:42:30 2018 -0400 Committer: Jared Frees <frees...@osu.edu> Committed: Tue Jun 12 11:42:30 2018 -0400 ---------------------------------------------------------------------- .../ldap/AuthenticationProviderService.java | 33 +++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/00b33dae/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java index 090dd93..8e51c37 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java @@ -27,8 +27,8 @@ import com.novell.ldap.LDAPEntry; import com.novell.ldap.LDAPAttribute; import com.novell.ldap.LDAPException; import java.util.HashMap; -import java.util.List; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.apache.guacamole.auth.ldap.user.AuthenticatedUser; import org.apache.guacamole.auth.ldap.user.UserContext; @@ -241,9 +241,6 @@ public class AuthenticationProviderService { return authenticatedUser; } - catch (LDAPException e) { - throw new GuacamoleServerException("Error while querying for User Attributes.", e); - } // Always disconnect finally { ldapService.disconnect(ldapConnection); @@ -258,6 +255,7 @@ public class AuthenticationProviderService { * * @param ldapConnection * LDAP connection to find the custom LDAP attributes. + * * @param username * The username of the user whose attributes are queried. * @@ -273,7 +271,7 @@ public class AuthenticationProviderService { * If an error occurs retrieving the user DN. */ private Map<String, String> getLDAPAttributes(LDAPConnection ldapConnection, - String username) throws LDAPException { + String username) throws GuacamoleException { // Get attributes from configuration information List<String> attrList = confService.getAttributes(); @@ -286,17 +284,22 @@ public class AuthenticationProviderService { String[] attrArray = attrList.toArray(new String[attrList.size()]); String userDN = getUserBindDN(username); - // Get LDAP attributes by querying LDAP - LDAPEntry userEntry = ldapConnection.read(userDN, attrArray); - LDAPAttributeSet attrSet = userEntry.getAttributeSet(); - - // Add each attribute into Map Map<String, String> attrMap = new HashMap<String, String>(); - for (Object attrObj : attrSet) { - LDAPAttribute attr = (LDAPAttribute)attrObj; - String attrName = attr.getName(); - String attrValue = attr.getStringValue(); - attrMap.put(attrName, attrValue); + try { + // Get LDAP attributes by querying LDAP + LDAPEntry userEntry = ldapConnection.read(userDN, attrArray); + LDAPAttributeSet attrSet = userEntry.getAttributeSet(); + + // Add each attribute into Map + for (Object attrObj : attrSet) { + LDAPAttribute attr = (LDAPAttribute)attrObj; + String attrName = attr.getName(); + String attrValue = attr.getStringValue(); + attrMap.put(attrName, attrValue); + } + } + catch (LDAPException e) { + throw new GuacamoleServerException("Error while querying for User Attributes.", e); } return attrMap;