Ejemplo n.º 1
0
  public boolean completeLogin(AuthRequest req, Player player) {
    // used custAuth or is remembered

    if (req.remember) {
      if (req.isValid()) {
        if (req.isGuest) {
          player.addTMessage(Color.GRAY, "Guestname remembered.");
          player.setGuest(true);
        } else {
          player.addTMessage(Color.GRAY, "Custom Authentication remembered.");
          player.setUsedAuthenticator(true);
          player.setGuest(false);
        }

        return player.setName(req.playerName);
      }
    } else {
      if (req.isValid()) {
        player.addTMessage(Color.GRAY, "Custom Authentication successfully completed.");
        player.setUsedAuthenticator(true);
        player.setGuest(false);
        return player.setName(req.playerName);
      } else {
        player.addTMessage(Color.RED, "Your custom Authentication expired. Please try again.");
      }
    }

    return false;
  }
Ejemplo n.º 2
0
 private void cleanLoginRequests() {
   ListIterator<AuthRequest> requests = authRequests.listIterator();
   while (requests.hasNext()) {
     AuthRequest current = requests.next();
     if (!current.isValid()) {
       if (current.isGuest) {
         releaseGuestName(current.playerName);
       }
       requests.remove();
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * Request an access token from an OAuth 2.0 provider.
   *
   * <p>If it can be determined that the user has already granted access, and the token has not yet
   * expired, and that the token will not expire soon, the existing token will be passed to the
   * callback.
   *
   * <p>Otherwise, a popup window will be displayed which may prompt the user to grant access. If
   * the user has already granted access the popup will immediately close and the token will be
   * passed to the callback. If access hasn't been granted, the user will be prompted, and when they
   * grant, the token will be passed to the callback.
   *
   * @param req Request for authentication.
   * @param callback Callback to pass the token to when access has been granted.
   */
  public void login(AuthRequest req, final Callback<String, Throwable> callback) {
    lastRequest = req;
    lastCallback = callback;

    String authUrl = req.toUrl(urlCodex) + "&redirect_uri=" + urlCodex.encode(oauthWindowUrl);

    // Try to look up the token we have stored.
    final TokenInfo info = getToken(req);
    if (info == null || info.expires == null || expiringSoon(info)) {
      // Token wasn't found, or doesn't have an expiration, or is expired or
      // expiring soon. Requesting access will refresh the token.
      doLogin(authUrl, callback);
    } else {
      // Token was found and is good, immediately execute the callback with the
      // access token.

      scheduler.scheduleDeferred(
          new ScheduledCommand() {
            @Override
            public void execute() {
              callback.onSuccess(info.accessToken);
            }
          });
    }
  }
Ejemplo n.º 4
0
 public void assureLaunchingPad(AuthRequest ar) throws Exception {
   File launchFile = new File(containingFolder, ".cogProjectView.htm");
   if (!launchFile.exists()) {
     boolean previousUI = ar.isNewUI();
     ar.setNewUI(true);
     OutputStream os = new FileOutputStream(launchFile);
     Writer w = new OutputStreamWriter(os, "UTF-8");
     w.write("<html><body><script>document.location = \"");
     UtilityMethods.writeHtml(w, ar.baseURL);
     UtilityMethods.writeHtml(w, ar.getResourceURL(this, "public.htm"));
     w.write("\";</script></body></html>");
     w.flush();
     w.close();
     ar.setNewUI(previousUI);
   }
 }
Ejemplo n.º 5
0
  /** *** LOGIN REQUEST VALIDATION / COMPLETE LOGIN **** */
  public synchronized AuthRequest getAuthRequest(String IP) {
    if (!allowLogin()) {
      return null;
    }
    ListIterator<AuthRequest> requests = authRequests.listIterator();
    AuthRequest res = null;

    while (requests.hasNext()) {
      AuthRequest current = requests.next();
      if (current.IP.equals(IP)) {
        res = current;
        requests.remove();
        break;
      }

      if (!current.isValid()) {
        if (current.isGuest) {
          releaseGuestName(current.playerName);
        }
        requests.remove();
      }
    }
    return res;
  }
Ejemplo n.º 6
0
 /*
  * @param req The authentication request of which to request the expiration
  *        status.
  * @return The number of milliseconds until the token expires, or negative
  *         infinity if no token was found.
  */
 public double expiresIn(AuthRequest req) {
   String val = tokenStore.get(req.asString());
   return val == null
       ? Double.NEGATIVE_INFINITY
       : Double.valueOf(TokenInfo.fromString(val).expires) - clock.now();
 }
Ejemplo n.º 7
0
 void setToken(AuthRequest req, TokenInfo info) {
   tokenStore.set(req.asString(), info.asString());
 }
Ejemplo n.º 8
0
 TokenInfo getToken(AuthRequest req) {
   String tokenStr = tokenStore.get(req.asString());
   return tokenStr != null ? TokenInfo.fromString(tokenStr) : null;
 }