mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-524: Changed to use AuthenticatedUser instead of Credentials
Fixed up some code style and add attributes in AuthenticatedUser object.
This commit is contained in:
@@ -22,7 +22,14 @@ package org.apache.guacamole.auth.ldap;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.novell.ldap.LDAPConnection;
|
import com.novell.ldap.LDAPConnection;
|
||||||
|
import com.novell.ldap.LDAPAttributeSet;
|
||||||
|
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.List;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import org.apache.guacamole.auth.ldap.user.AuthenticatedUser;
|
import org.apache.guacamole.auth.ldap.user.AuthenticatedUser;
|
||||||
import org.apache.guacamole.auth.ldap.user.UserContext;
|
import org.apache.guacamole.auth.ldap.user.UserContext;
|
||||||
import org.apache.guacamole.GuacamoleException;
|
import org.apache.guacamole.GuacamoleException;
|
||||||
@@ -33,14 +40,6 @@ import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
|
|||||||
import org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
|
import org.apache.guacamole.net.auth.credentials.GuacamoleInvalidCredentialsException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import com.novell.ldap.LDAPAttributeSet;
|
|
||||||
import com.novell.ldap.LDAPEntry;
|
|
||||||
import com.novell.ldap.LDAPAttribute;
|
|
||||||
import com.novell.ldap.LDAPException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service providing convenience functions for the LDAP AuthenticationProvider
|
* Service providing convenience functions for the LDAP AuthenticationProvider
|
||||||
@@ -230,22 +229,21 @@ public class AuthenticationProviderService {
|
|||||||
throw new GuacamoleInvalidCredentialsException("Permission denied.", CredentialsInfo.USERNAME_PASSWORD);
|
throw new GuacamoleInvalidCredentialsException("Permission denied.", CredentialsInfo.USERNAME_PASSWORD);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
|
||||||
String username = credentials.getUsername();
|
|
||||||
Map<String, String> ldapAttrs = getLDAPAttributes(ldapConnection, username);
|
|
||||||
credentials.setLDAPAttributes(ldapAttrs);
|
|
||||||
}
|
|
||||||
catch (LDAPException e) {
|
|
||||||
throw new GuacamoleServerException("Error while querying for LDAP User Attributes.", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return AuthenticatedUser if bind succeeds
|
// Return AuthenticatedUser if bind succeeds
|
||||||
AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
|
AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
|
||||||
authenticatedUser.init(credentials);
|
authenticatedUser.init(credentials);
|
||||||
|
|
||||||
|
//set attributes
|
||||||
|
String username = credentials.getUsername();
|
||||||
|
Map<String, String> attrs = getLDAPAttributes(ldapConnection, username);
|
||||||
|
authenticatedUser.setAttributes(attrs);
|
||||||
|
|
||||||
return authenticatedUser;
|
return authenticatedUser;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
catch (LDAPException e) {
|
||||||
|
throw new GuacamoleServerException("Error while querying for User Attributes.", e);
|
||||||
|
}
|
||||||
// Always disconnect
|
// Always disconnect
|
||||||
finally {
|
finally {
|
||||||
ldapService.disconnect(ldapConnection);
|
ldapService.disconnect(ldapConnection);
|
||||||
@@ -275,13 +273,13 @@ public class AuthenticationProviderService {
|
|||||||
* If an error occurs retrieving the user DN.
|
* If an error occurs retrieving the user DN.
|
||||||
*/
|
*/
|
||||||
private Map<String, String> getLDAPAttributes(LDAPConnection ldapConnection,
|
private Map<String, String> getLDAPAttributes(LDAPConnection ldapConnection,
|
||||||
String username) throws LDAPException, GuacamoleException {
|
String username) throws LDAPException {
|
||||||
|
|
||||||
// Get attributes from configuration information
|
// Get attributes from configuration information
|
||||||
List<String> attrList = confService.getAttributes();
|
List<String> attrList = confService.getAttributes();
|
||||||
|
|
||||||
// If there are no attributes there is no reason to search LDAP
|
// If there are no attributes there is no reason to search LDAP
|
||||||
if (attrList.size() == 0)
|
if (attrList == null || attrList.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Build LDAP query parameters
|
// Build LDAP query parameters
|
||||||
@@ -294,9 +292,8 @@ public class AuthenticationProviderService {
|
|||||||
|
|
||||||
// Add each attribute into Map
|
// Add each attribute into Map
|
||||||
Map<String, String> attrMap = new HashMap<String, String>();
|
Map<String, String> attrMap = new HashMap<String, String>();
|
||||||
Iterator attrIterator = attrSet.iterator();
|
for (Object attrObj : attrSet) {
|
||||||
while (attrIterator.hasNext()) {
|
LDAPAttribute attr = (LDAPAttribute)attrObj;
|
||||||
LDAPAttribute attr = (LDAPAttribute)attrIterator.next();
|
|
||||||
String attrName = attr.getName();
|
String attrName = attr.getName();
|
||||||
String attrValue = attr.getStringValue();
|
String attrValue = attr.getStringValue();
|
||||||
attrMap.put(attrName, attrValue);
|
attrMap.put(attrName, attrValue);
|
||||||
|
Reference in New Issue
Block a user