Ejemplo n.º 1
0
  private String addDefaultQueryParameters(String uri) {
    if (connection.hasToken()) {
      uri += "?" + TOKEN_HEADER + "=" + connection.getToken();
    }

    return uri;
  }
Ejemplo n.º 2
0
  private Map<String, Collection<String>> getDefaultHeaders() {
    Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();

    headers.put("X-Plex-Client-Identifier", Arrays.asList(CLIENT_ID));
    headers.put("X-Plex-Product", Arrays.asList("openHAB"));
    headers.put("X-Plex-Version", Arrays.asList(PlexActivator.getVersion().toString()));
    headers.put("X-Plex-Device", Arrays.asList(SystemUtils.JAVA_RUNTIME_NAME));
    headers.put("X-Plex-Device-Name", Arrays.asList("openHAB"));
    headers.put("X-Plex-Provides", Arrays.asList("controller"));
    headers.put("X-Plex-Platform", Arrays.asList("Java"));
    headers.put("X-Plex-Platform-Version", Arrays.asList(SystemUtils.JAVA_VERSION));

    if (connection.hasToken()) {
      headers.put(TOKEN_HEADER, Arrays.asList(connection.getToken()));
    }

    return headers;
  }
Ejemplo n.º 3
0
  private void requestToken() {
    boolean tokenPresent = !isEmpty(connection.getToken());
    boolean usernamePresent = !isEmpty(connection.getUsername());
    boolean passwordPresent = !isEmpty(connection.getPassword());

    if (!tokenPresent && usernamePresent && passwordPresent) {
      Map<String, String> parameters = new HashMap<String, String>();
      String authString =
          Base64.encode((connection.getUsername() + ":" + connection.getPassword()).getBytes());
      parameters.put("Authorization", "Basic " + authString);

      User user = postDocument(SIGN_IN_URL, parameters, User.class);
      if (user != null) {
        logger.debug("Plex login successful");
        connection.setToken(user.getAuthenticationToken());
      } else {
        logger.warn("Invalid credentials for Plex account");
      }
    }
  }