public synchronized boolean isAuthenticated(String username, String apiKey) {

        LOGGER.entering();
        final String key = username + ":" + apiKey;
        final String authKey = new String(Base64.encodeBase64(key.getBytes()));

        if (accountCache.containsKey(md5(authKey))) {
            final boolean authenticated = accountCache.get(md5(authKey));
            LOGGER.exiting(authenticated);
            return authenticated;
        }

        SauceLabsHttpResponse response;
        try {
            final URL url = new URL(SauceConfigReader.getInstance().getSauceURL() + "/users/" + username);
            response = doSauceRequest(url, authKey, sauceTimeout, 0);
            if (response.getStatus() == HttpStatus.SC_OK) {
                addToAccountCache(md5(authKey), true);
                LOGGER.exiting(true);
                return true;
            }
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "Unable to communicate with sauce labs api.", e);
        }
        // TODO don't add to cache if sauce api is down
        addToAccountCache(md5(authKey), false);

        LOGGER.exiting(false);
        return false;
    }
public synchronized boolean isAuthenticated ( String username , String apiKey ) { LOGGER . entering ( ) ; final String key = username + ":" + apiKey ; final String authKey = new String ( Base64 . encodeBase64 ( key . getBytes ( ) ) ) ; if ( accountCache . containsKey ( md5 ( authKey ) ) ) { final boolean authenticated = accountCache . get ( md5 ( authKey ) ) ; LOGGER . exiting ( authenticated ) ; return authenticated ; } SauceLabsHttpResponse response ; try { final URL url = new URL ( SauceConfigReader . getInstance ( ) . getSauceURL ( ) + "/users/" + username ) ; response = doSauceRequest ( url , authKey , sauceTimeout , 0 ) ; if ( response . getStatus ( ) == HttpStatus . SC_OK ) { addToAccountCache ( md5 ( authKey ) , true ) ; LOGGER . exiting ( true ) ; return true ; } } catch ( IOException e ) { LOGGER . log ( Level . SEVERE , "Unable to communicate with sauce labs api." , e ) ; } addToAccountCache ( md5 ( authKey ) , false ) ; LOGGER . exiting ( false ) ; return false ; }
Determine if the account credentials specified are valid by calling the sauce rest api. Uses a local account
cache for credentials which have already been presented. Cached credentials expire when the cache reaches a size
of {@link SauceLabsRestApi#MAX_CACHE}

@param username
the user name
@param apiKey
the sauce labs api access key
@return <code>true</code> on success. <code>false</code> if unauthorized or unable to call sauce.