@@ -0,0 +1,2280 @@
+package com.aldebaran.qi;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * Specific %7B@link ClientAuthenticator%7D authenticating from a user and a token.%0A *%0A * If the server trusts on first use, we may receive a new token. In that case,%0A * %7B@link #hasNewToken()%7D returns %7B@code true%7D and the new token is available%0A * through %7B@link #getToken()%7D.%0A */%0Apublic class UserTokenAuthenticator implements ClientAuthenticator%0A%7B%0A  private String user;%0A  private String token;%0A  private boolean hasNewToken;%0A%0A  /**%0A   * Create an authenticator with an user and an initial token.%0A   *%0A   * @param user%0A   *          the user%0A   * @param initialToken%0A   *          the initial token (may be %7B@code null%7D)%0A   */%0A  public UserTokenAuthenticator(String user, String initialToken)%0A  %7B%0A    if (initialToken == null)%0A    %7B%0A      // %22%22 means no token (null would segfault in the API)%0A      initialToken = %22%22;%0A    %7D%0A    this.user = user;%0A    token = initialToken;%0A  %7D%0A%0A  /**%0A   * Create an authenticator with an user but no token.%0A   *%0A   * @param user%0A   *          the user%0A   */%0A  public UserTokenAuthenticator(String user)%0A  %7B%0A    this(user, null);%0A  %7D%0A%0A  private static Map%3CString, Object%3E createMap(String user, String token)%0A  %7B%0A    Map%3CString, Object%3E authData = new HashMap%3CString, Object%3E();%0A    authData.put(%22user%22, user);%0A    authData.put(%22token%22, token);%0A    return authData;%0A  %7D%0A%0A  @Override%0A  public Map%3CString, Object%3E initialAuthData()%0A  %7B%0A    hasNewToken = false;%0A    return createMap(user, token);%0A  %7D%0A%0A  @Override%0A  public Map%3CString, Object%3E _processAuth(Map%3CString, Object%3E authData)%0A  %7B%0A    // If no token was provided by initialAuthData(), the gateway%0A    // generates and provides it the very first time (it trusts on first%0A    // use).%0A    token = (String) authData.get(%22newToken%22);%0A    hasNewToken = true;%0A%0A    // We must return our new authentication data.%0A    return createMap(user, token);%0A  %7D%0A%0A  /**%0A   * Indicates whether a new token has been retrieved during the last%0A   * authentication.%0A   *%0A   * @return %7B@%C2%A9ode true%7D if a new token has been retrieved, %7B@false%7D otherwise%0A   */%0A  public boolean hasNewToken()%0A  %7B%0A    return hasNewToken;%0A  %7D%0A%0A  /**%0A   * Return the token.%0A   *%0A   * @return the token%0A   */%0A  public String getToken()%0A  %7B%0A    return token;%0A  %7D%0A%7D

Provide a UserTokenAuthenticator