private String getUserDomain(Credentials credentials) {

        // Extract domain from username (not necessarily present)
        String username = credentials.getUsername();
        Matcher matcher = LDAP_USERNAME_DOMAIN.matcher(username);
        if (!matcher.find())
            return null;

        String dlDomain = matcher.group(LDAP_USERNAME_DOMAIN_DOWN_LEVEL_GROUP);
        String upnDomain = matcher.group(LDAP_USERNAME_DOMAIN_UPN_GROUP);

        // The two domain formats are mutually exclusive. If any format is
        // present, the other must be absent unless there is a bug in the
        // way the domains are parsed
        assert(dlDomain == null || upnDomain == null);

        // Use whichever domain format is present
        return dlDomain != null ? dlDomain : upnDomain;

    }
Returns the Windows / Active Directory domain included in the username
of the provided user credentials. If the username does not contain a
domain, null is returned.

@param credentials
    The credentials used for authentication.

@return
    The domain name within the username of the provided credentials, or
    null if no domain is present.
extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java