public Map < String , Connection > getConnections ( AuthenticatedUser user , LDAPConnection ldapConnection ) throws GuacamoleException { // Do not return any connections if base DN is not specified String configurationBaseDN = confService . getConfigurationBaseDN ( ) ; if ( configurationBaseDN == null ) return Collections . < String , Connection > emptyMap ( ) ; try { // Pull the current user DN from the LDAP connection String userDN = ldapConnection . getAuthenticationDN ( ) ; // getConnections() will only be called after a connection has been // authenticated (via non-anonymous bind), thus userDN cannot // possibly be null assert ( userDN != null ) ; // Get the search filter for finding connections accessible by the // current user String connectionSearchFilter = getConnectionSearchFilter ( userDN , ldapConnection ) ; // Find all Guacamole connections for the given user by // looking for direct membership in the guacConfigGroup // and possibly any groups the user is a member of that are // referred to in the seeAlso attribute of the guacConfigGroup. List < LDAPEntry > results = queryService . search ( ldapConnection , configurationBaseDN , connectionSearchFilter ) ; // Return a map of all readable connections return queryService . asMap ( results , ( entry ) - > { // Get common name (CN) LDAPAttribute cn = entry . getAttribute ( "cn" ) ; if ( cn == null ) { logger . warn ( "guacConfigGroup is missing a cn." ) ; return null ; } // Get associated protocol LDAPAttribute protocol = entry . getAttribute ( "guacConfigProtocol" ) ; if ( protocol == null ) { logger . warn ( "guacConfigGroup \"{}\" is missing the " + "required \"guacConfigProtocol\" attribute." , cn . getStringValue ( ) ) ; return null ; } // Set protocol GuacamoleConfiguration config = new GuacamoleConfiguration ( ) ; config . setProtocol ( protocol . getStringValue ( ) ) ; // Get parameters, if any LDAPAttribute parameterAttribute = entry . getAttribute ( "guacConfigParameter" ) ; if ( parameterAttribute != null ) { // For each parameter Enumeration < ? > parameters = parameterAttribute . getStringValues ( ) ; while ( parameters . hasMoreElements ( ) ) { String parameter = ( String ) parameters . nextElement ( ) ; // Parse parameter int equals = parameter . indexOf ( ' ' ) ; if ( equals != - 1 ) { // Parse name String name = parameter . substring ( 0 , equals ) ; String value = parameter . substring ( equals + 1 ) ; config . setParameter ( name , value ) ; } } } // Store connection using cn for both identifier and name String name = cn . getStringValue ( ) ; Connection connection = new SimpleConnection ( name , name , config ) ; connection . setParentIdentifier ( LDAPAuthenticationProvider . ROOT_CONNECTION_GROUP ) ; // Inject LDAP-specific tokens only if LDAP handled user // authentication if ( user instanceof LDAPAuthenticatedUser ) connection = new TokenInjectingConnection ( connection , ( ( LDAPAuthenticatedUser ) user ) . getTokens ( ) ) ; return connection ; } ) ; } catch ( LDAPException e ) { throw new GuacamoleServerException ( "Error while querying for connections." , e ) ; } }
Returns all Guacamole connections accessible to the user currently bound under the given LDAP connection .