Skip to content

Commit 0e99388

Browse files
author
Josna battula
committed
GUACAMOLE-1881: reading domain name from ldap extension
1 parent ca241ab commit 0e99388

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,23 @@ public LDAPAuthenticatedUser authenticateUser(Credentials credentials)
286286
CredentialsInfo.USERNAME_PASSWORD);
287287

288288
try {
289-
289+
290290
// Retrieve group membership of the user that just authenticated
291291
Set<String> effectiveGroups =
292292
userGroupService.getParentUserGroupIdentifiers(config, config.getBindDN());
293293

294294
// Return AuthenticatedUser if bind succeeds
295295
LDAPAuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
296+
297+
Map<String, String> tokens = getAttributeTokens(config);
298+
String domainName = getDomainToken(credentials);
299+
if (domainName != null) {
300+
tokens.put(TokenName.canonicalize("domain-name", LDAP_ATTRIBUTE_TOKEN_PREFIX), domainName);
301+
}
296302
authenticatedUser.init(config, credentials,
297-
getAttributeTokens(config), effectiveGroups);
303+
tokens, effectiveGroups);
298304

299305
return authenticatedUser;
300-
301306
}
302307

303308
catch (GuacamoleException | RuntimeException | Error e) {
@@ -306,6 +311,26 @@ public LDAPAuthenticatedUser authenticateUser(Credentials credentials)
306311
}
307312

308313
}
314+
/**
315+
* Returns parameter current ldap domain token generated from user credentials
316+
* If no multiple LDAP are configured on GUACAMOLE_HOME
317+
* a null is returned.
318+
*
319+
* @param credentials
320+
* The credentials to use for authentication.
321+
*
322+
* @return
323+
* Domain name by splitting logged username when multiple LDAP configuration is available
324+
* or null if no such configuration
325+
*/
326+
private String getDomainToken(Credentials credentials) {
327+
String ldapDomainName = null;
328+
// Creating custom LDAP attribute token - domain name - when configured to multiple LDAP
329+
if (credentials.getUsername().contains("\\")) {
330+
ldapDomainName =credentials.getUsername().split("\\\\")[0];
331+
}
332+
return ldapDomainName;
333+
}
309334

310335
/**
311336
* Returns parameter tokens generated from LDAP attributes on the user
@@ -356,7 +381,6 @@ private Map<String, String> getAttributeTokens(ConnectedLDAPConfiguration config
356381
tokens.put(TokenName.canonicalize(attr.getId(),
357382
LDAP_ATTRIBUTE_TOKEN_PREFIX), attr.getString());
358383
}
359-
360384
}
361385
catch (LdapException e) {
362386
throw new GuacamoleServerException("Could not query LDAP user attributes.", e);

0 commit comments

Comments
 (0)