Package org.fluxtream.core.domain

Examples of org.fluxtream.core.domain.ApiKey$PermanentFailReason


      @PathVariable("UID") Long uid,
      @PathVariable("LOGREC_ID") String LOGREC_ID) throws IOException, UnexpectedHttpResponseCodeException {
        if (!checkForPermissionAccess(uid)){
            uid = null;
        }
        ApiKey apiKey = guestService.getApiKey(uid, Connector.getConnector("bodytrack"));
        String user_id = guestService.getApiKeyAttribute(apiKey, "user_id");
    String tunnelUrl = "http://localhost:3000/users/" + user_id + "/tags/"
        + LOGREC_ID + "/get";
    writeTunnelResponse(tunnelUrl, response);
  }
View Full Code Here


      @PathVariable("LOGREC_ID") String LOGREC_ID,
      @RequestParam("tags") String tags) throws IOException, UnexpectedHttpResponseCodeException {
        if (!checkForPermissionAccess(uid)){
            uid = null;
        }
        ApiKey apiKey = guestService.getApiKey(uid, Connector.getConnector("bodytrack"));
        String user_id = guestService.getApiKeyAttribute(apiKey, "user_id");
    Map<String, String> params = new HashMap<String, String>();
    params.put("tags", tags);
    String tunnelUrl = "http://localhost:3000/users/" + user_id + "/tags/"
        + LOGREC_ID + "/set";
View Full Code Here

    private final static String APIKEYID_ATTRIBUTE = "google.oauth2.apiKeyId";

    @RequestMapping(value = "/{apiKeyId}/token")
    public String renewToken(@PathVariable("apiKeyId") String apiKeyId, HttpServletRequest request) throws IOException, ServletException {
        request.getSession().setAttribute(APIKEYID_ATTRIBUTE, apiKeyId);
        final ApiKey apiKey = guestService.getApiKey(Long.valueOf(apiKeyId));

        // Check if the stored client ID matches the one in our properties file, and only in that
        // case try to revoke.  TODO: in that case skip next two lines
        String propertiesClientId = env.get("google.client.id");
        String storedClientId = guestService.getApiKeyAttribute(apiKey,"google.client.id");

        if(propertiesClientId !=null && storedClientId!=null && propertiesClientId.equals(storedClientId)) {
            // Renewing token for the same server, do revoke attempt first
            final String refreshTokenRemoveURL = guestService.getApiKeyAttribute(apiKey,"refreshTokenRemoveURL");
            oAuth2Helper.revokeRefreshToken(apiKey.getGuestId(), apiKey.getConnector(), refreshTokenRemoveURL);

            String msg="Called revokeRefreshToken with refreshTokenRemoveURL='" + refreshTokenRemoveURL + "'";
            StringBuilder sb = new StringBuilder("module=GoogleOauth2Controller component=renewToken action=renewToken apiKeyId=" + apiKeyId)
                    .append(" guestId=").append(apiKey.getGuestId())
                    .append(" message=\"").append(msg).append("\"");
            logger.info(sb.toString());
        }
        else {
            String msg="Skipped revokeRefreshToken, stored and properties google.client.id do not match (" + storedClientId + " vs " + propertiesClientId + ")" ;
                        StringBuilder sb = new StringBuilder("module=GoogleOauth2Controller component=renewToken action=renewToken apiKeyId=" + apiKeyId)
                                .append(" guestId=").append(apiKey.getGuestId())
                                .append(" message=\"").append(msg).append("\"");
                        logger.info(sb.toString());
        }
        // Continue on to ask user for authorization whether or not you did a revoke
        return getToken(request);
View Full Code Here

         token = JSONObject.fromObject(fetched);
      } catch(Throwable e) {
         token = null;
      }

        ApiKey apiKey;
        final boolean isRenewToken = request.getSession().getAttribute(APIKEYID_ATTRIBUTE) != null;
        if (isRenewToken) {
            String apiKeyId = (String)request.getSession().getAttribute(APIKEYID_ATTRIBUTE);
            apiKey = guestService.getApiKey(Long.valueOf(apiKeyId));
            if (apiKey==null) {
                Exception e = new Exception();
                String stackTrace = ExceptionUtils.getStackTrace(e);
                String errorMessage = "no apiKey with id '%s'... It looks like you are trying to renew the tokens of a non-existing Connector (/ApiKey)";
                return errorController.handleError(500, errorMessage, stackTrace);
            }

            if (token == null || !token.has("refresh_token")) {
                String message = (new StringBuilder("<p>We couldn't get your oauth2 refresh token.  "))
                        .append("Something went wrong.</p>")
                        .append("<p>You'll have to surf to your ")
                        .append("<a target='_new'  href='https://accounts.google.com/b/0/IssuedAuthSubTokens'>token mgmt page at Google</a> ")
                        .append("and hit \"Revoke Access\" next to \"").append(brandName).append(" — ").append(getGooglePrettyName(scopedApi)).append("\"</p>")
                      .append("<p>Then please, head to <a href=\"javascript:App.manageConnectors()\">Manage Connectors</a> ")
                      .append("and renew your tokens (look for the <i class=\"icon-resize-small icon-large\"></i> icon)</p>")
                        .append("<p>We apologize for the inconvenience</p>").toString();

                notificationsService.addNamedNotification(guest.getId(),
                                                     Notification.Type.ERROR,
                                                     apiKey.getConnector().statusNotificationName(),
                                                     message);
                // Record permanent failure since this connector won't work again until
                // it is reauthenticated
                guestService.setApiKeyStatus(apiKey.getId(), ApiKey.Status.STATUS_PERMANENT_FAILURE, null, ApiKey.PermanentFailReason.NEEDS_REAUTH);
                return new ModelAndView("redirect:/app");
            }

            // Remove oauth1 keys if upgrading from previous connector version.
            // Remember whether or not we're upgrading from previous connector version.
            // If so, do a full history update.  Otherwise don't force a full
            // history update and allow the update to be whatever it normally would be
            boolean upgradeFromOauth1 = false;

            if (guestService.getApiKeyAttribute(apiKey, "googleConsumerKey")!=null) {
                guestService.removeApiKeyAttribute(apiKey.getId(), "googleConsumerKey");
                upgradeFromOauth1 = true;
            }
            if (guestService.getApiKeyAttribute(apiKey, "googleConsumerSecret")!=null) {
                guestService.removeApiKeyAttribute(apiKey.getId(), "googleConsumerSecret");
                upgradeFromOauth1 = true;
            }

            // If upgradeFromOauth1 reset the connector to force a full reimport on google calendar,
            // otherwise just do a normal update
            if (apiKey.getConnector().getName().equals("google_calendar")) {
                connectorUpdateService.flushUpdateWorkerTasks(apiKey, upgradeFromOauth1);
            }

        } else {
            apiKey = guestService.createApiKey(guest.getId(), scopedApi);
        }

        // We need to store google.client.id and google.client.secret with the
        // apiKeyAttributes in either the case of original creation of the key
        // or token renewal.  createApiKey actually handles the former case, but
        // not the latter.  Do it in all cases here.
        guestService.setApiKeyAttribute(apiKey, "google.client.id", env.get("google.client.id"));
        guestService.setApiKeyAttribute(apiKey, "google.client.secret", env.get("google.client.secret"));

        final String refresh_token = token.getString("refresh_token");

        guestService.setApiKeyAttribute(apiKey,
        "accessToken", token.getString("access_token"));
    guestService.setApiKeyAttribute(apiKey,
        "tokenExpires", String.valueOf(System.currentTimeMillis() + (token.getLong("expires_in")*1000)));
        guestService.setApiKeyAttribute(apiKey,
        "refreshToken", refresh_token);
        final String encodedRefreshToken = URLEncoder.encode(refresh_token, "UTF-8");
        guestService.setApiKeyAttribute(apiKey,
                                        "refreshTokenRemoveURL",
                                        "https://accounts.google.com/o/oauth2/revoke?token="
                                        + encodedRefreshToken);

        // Record this connector as having status up
        guestService.setApiKeyStatus(apiKey.getId(), ApiKey.Status.STATUS_UP, null, null);
        // Schedule an update for this connector
        connectorUpdateService.updateConnector(apiKey, false);

        if (isRenewToken) {
            request.getSession().removeAttribute(APIKEYID_ATTRIBUTE);
View Full Code Here

    @RequestMapping("/admin/{guestId}/{apiKeyId}")
    public ModelAndView showConnectorInstanceDetails(@PathVariable("guestId") long guestId,
                                                     @PathVariable("apiKeyId") long apiKeyId) {
        ModelAndView mav = getAdminModel();
        mav.addObject("subview", "connectorDetails");
        final ApiKey apiKey = guestService.getApiKey(apiKeyId);
        final Map<String, Object> connectorInstanceModel = connectorInstanceModelFactory.createConnectorInstanceModel(apiKey);
        final Guest guest = guestService.getGuestById(guestId);
        final List<ApiUpdate> lastUpdates = connectorUpdateService.getUpdates(apiKey, 100, 0);
        mav.addObject("guest", guest);
        mav.addObject("guestId", guest.getId());
View Full Code Here

    public String welcomeBack(String connectorName, String message) {
        long guestId = AuthHelper.getGuestId();
        final Connector connector = Connector.getConnector(connectorName);
        notificationsService.addNamedNotification(guestId, Type.INFO, connector.statusNotificationName(), message);
        ApiKey apiKey = guestService.getApiKey(guestId, connector);
        connectorUpdateService.updateConnector(apiKey, true);
        return "redirect:/app";
    }
View Full Code Here

        String sessionKey = LastfmHelper.getSessionKey(jsonResponse);
    String username = LastfmHelper.getUsername(jsonResponse);
    Guest guest = AuthHelper.getGuest();

        final Connector connector = Connector.getConnector("lastfm");
        ApiKey apiKey;
        if (request.getSession().getAttribute(LASTFM_RENEWTOKEN_APIKEYID)!=null) {
            final String apiKeyIdString = (String) request.getSession().getAttribute(LASTFM_RENEWTOKEN_APIKEYID);
            long apiKeyId = Long.valueOf(apiKeyIdString);
            apiKey = guestService.getApiKey(apiKeyId);
        } else
            apiKey = guestService.createApiKey(guest.getId(), connector);

        guestService.populateApiKey(apiKey.getId());
    guestService.setApiKeyAttribute(apiKey, "sessionKey", sessionKey);
    guestService.setApiKeyAttribute(apiKey,  "username", username);

        if (request.getSession().getAttribute(LASTFM_RENEWTOKEN_APIKEYID)!=null) {
            request.getSession().removeAttribute(LASTFM_RENEWTOKEN_APIKEYID);
View Full Code Here

    String fullname = user.attributeValue("fullname");
    String token = document.selectSingleNode("rsp/auth/token/text()").getStringValue();
   
    Connector flickrConnector = Connector.getConnector("flickr");

        ApiKey apiKey;
        if (request.getSession().getAttribute(FLICKR_RENEWTOKEN_APIKEYID)!=null) {
            final String apiKeyIdString = (String)request.getSession().getAttribute(FLICKR_RENEWTOKEN_APIKEYID);
            long apiKeyId = Long.valueOf(apiKeyIdString);
            apiKey = guestService.getApiKey(apiKeyId);
        } else
            apiKey = guestService.createApiKey(guest.getId(), flickrConnector);

        guestService.populateApiKey(apiKey.getId());
    guestService.setApiKeyAttribute(apiKey,  "username", username);
    guestService.setApiKeyAttribute(apiKey,  "token", token);
    guestService.setApiKeyAttribute(apiKey,  "nsid", nsid);
    guestService.setApiKeyAttribute(apiKey,  "fullname", fullname);
View Full Code Here

    }

    @Override
    public void connectorSettingsChanged(final long apiKeyId, final Object settings) {
        final GoogleCalendarConnectorSettings connectorSettings = (GoogleCalendarConnectorSettings)settings;
        final ApiKey apiKey = guestService.getApiKey(apiKeyId);
        initChannelMapping(apiKey, connectorSettings.calendars);
    }
View Full Code Here

        return mav;
    }

    @RequestMapping("/test/setAtt")
    public void testSetAttribute(HttpServletResponse resp) throws IOException {
        final ApiKey apiKey = guestService.getApiKey(136);
        for (int i=0; i<1000; i++)
            setApiKeyAttribute(apiKey);
        resp.getWriter().write("OK");
    }
View Full Code Here

TOP

Related Classes of org.fluxtream.core.domain.ApiKey$PermanentFailReason

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.