public String authenticate(Credentials credentials,String token) throws GuacamoleException {
  GuacamoleSession existingSession;
  if (token != null)   existingSession=tokenSessionMap.get(token);
 else   existingSession=null;
  AuthenticatedUser authenticatedUser=getAuthenticatedUser(existingSession,credentials);
  List<UserContext> userContexts=getUserContexts(existingSession,authenticatedUser,credentials);
  String authToken;
  if (existingSession != null) {
    authToken=token;
    existingSession.setAuthenticatedUser(authenticatedUser);
    existingSession.setUserContexts(userContexts);
  }
 else {
    authToken=authTokenGenerator.getToken();
    tokenSessionMap.put(authToken,new GuacamoleSession(environment,authenticatedUser,userContexts));
    logger.debug("Login was successful for user \"{}\".",authenticatedUser.getIdentifier());
  }
  return authToken;
}

public String authenticate ( Credentials credentials , String token ) throws GuacamoleException { GuacamoleSession existingSession ; if ( token != null ) existingSession = tokenSessionMap . get ( token ) ; else existingSession = null ; AuthenticatedUser authenticatedUser = getAuthenticatedUser ( existingSession , credentials ) ; List < UserContext > userContexts = getUserContexts ( existingSession , authenticatedUser , credentials ) ; String authToken ; if ( existingSession != null ) { authToken = token ; existingSession . setAuthenticatedUser ( authenticatedUser ) ; existingSession . setUserContexts ( userContexts ) ; } else { authToken = authTokenGenerator . getToken ( ) ; tokenSessionMap . put ( authToken , new GuacamoleSession ( environment , authenticatedUser , userContexts ) ) ; logger . debug ( "Login was successful for user \"{}\"." , authenticatedUser . getIdentifier ( ) ) ; } return authToken ; }
authenticates a user using the given credentials and optional authentication token , returning the authentication token associated with the user ' s guacamole session , which may be newly generated . if an existing token is provided , the authentication procedure will attempt to update or reuse the provided token , but it is possible that a new token will be returned . note that this function cannot return null .
