All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.seq.http.session.ProdRefresher Maven / Gradle / Ivy

There is a newer version: 2.2
Show newest version
package com.seq.http.session;

import com.seq.exception.ChainException;
import com.seq.exception.ConfigurationException;
import com.seq.http.HttpWrapper;
import com.google.gson.annotations.SerializedName;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;

public class ProdRefresher implements Refresher {
  private class SessionResponse {
    @SerializedName("refresh_at")
    public Integer refreshAt;

    @SerializedName("team_name")
    public String teamName;

    @SerializedName("refresh_token")
    public String dischargeMacaroon;

    public SessionResponse() {
      this.refreshAt = 0;
      this.teamName = null;
      this.dischargeMacaroon = null;
    }
  }

  private HttpWrapper http;
  private SessionResponse resp;

  public ProdRefresher() {
    this.http = new HttpWrapper();
    this.resp = new SessionResponse();
  }

  public String teamName() {
    return this.resp.teamName;
  }

  public String dischargeMacaroon() {
    return this.resp.dischargeMacaroon;
  }

  public boolean needsRefresh() {
    return this.resp.refreshAt < System.currentTimeMillis() / 1000;
  }

  public void refresh(String macaroon) throws ChainException {
    Map sessionReq = new HashMap();
    sessionReq.put("macaroon", macaroon);
    this.resp = this.http.post("/sessions/validate", sessionReq, SessionResponse.class);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy