コード例 #1
0
 public OAuth2AppInfo infoForService(com.ccc.oauth.apimanagement.model.Service service) {
   int serviceId = service.getId();
   List<OAuth2AppInfo> info =
       appInfoManager.elementsWithValue("service_id", String.valueOf(serviceId));
   if (info != null && !info.isEmpty()) return info.get(0);
   return null;
 }
コード例 #2
0
  /**
   * This will return whether a given auth type is supported for a given service
   *
   * @param authType the auth type
   * @param service the service to check for
   * @return true if the auth is supported, false otherwise
   */
  public boolean authSupported(String authType, com.ccc.oauth.apimanagement.model.Service service) {
    List<AuthSupports> supports =
        authSupportManager.elementsWithValue("service_id", String.valueOf(service.getId()));
    for (AuthSupports supported : supports) {
      if (supported.getAuthType().equals(authType)) return true;
    }

    return false;
  }
コード例 #3
0
  public boolean processRedirect(
      HttpServletRequest request,
      HttpServletResponse response,
      String token,
      String error,
      String errorMessage,
      String oauth1Token,
      String oauthVerifier,
      com.ccc.oauth.apimanagement.model.Service s,
      String userName) {
    if (log.isDebugEnabled()) {
      log.debug(
          "Code {} token {} error {} error descriptor {}  error message {} oauthtoken {} oauthverifer {} ",
          new Object[] {token, token, error, errorMessage, oauth1Token, oauthVerifier});
    }

    if (error != null && errorMessage != null) {
      log.warn(
          "Error found when retrieving code: "
              + " Error type: "
              + error
              + " and message: "
              + errorMessage);
    }
    OAuth2KeyUser key = null;

    List<AuthSupports> supported = supportedAuthForService(s);
    for (AuthSupports supports : supported) {
      if (supports.getAuthType().getName().equals(HttpAuthUtils.OAUTH2)) {

        key = new OAuth2KeyUser();
        key.setUserName(userName);
        key.setService(s);
        key.setTimeMade(new Timestamp(System.currentTimeMillis()));
        key.setCode(token);
        if (log.isDebugEnabled()) {
          log.debug("Added new key for: " + userName + " and service: " + s.getName());
        }

        Assert.isTrue(addKeyForUser(key));
        AccessKeyForUser accessKey =
            HttpAuthUtils.requestAccessWithLookup(this, userName, s.getId());
        if (log.isDebugEnabled()) {
          log.debug(
              "Requested to find access key: " + accessKey == null
                  ? " not found: "
                  : accessKey.getAccessCode());
        }

        if (accessKey == null) {
          log.warn("Failed to retrieve access key");
          return false;
        }

        Assert.isTrue(addKeyForUser(accessKey), "Couldn't add key for user: "******"Attempting oauth authorization");
          }

          String toSave = null;
          // 1.0a compliance
          if (oauthVerifier != null && oauth1Token != null) toSave = oauthVerifier;
          else if (oauthVerifier != null) toSave = oauthVerifier;
          else if (oauth1Token != null) toSave = oauth1Token;

          if (toSave != null) {

            requestToken.setRequestToken(toSave);
          } else {
            if (log.isDebugEnabled()) {
              log.debug(
                  "Attempted to save oauth 1 token for service: {} but couldn't find token passed in  for user {}",
                  s.getName(),
                  userName);
            }
          }
          if (log.isDebugEnabled()) {
            log.debug("Found request token: " + toSave);
          }
          updateRequestToken(requestToken);
        }

        OAuth1Info oauth1Info = oauthInfoForService(s);

        try {
          String accessToken = HttpAuthUtils.getAccessTokenFromPin(oauth1Info, this, requestToken);
          if (accessToken == null) log.warn("Error retrieving access token for {}", s.getName());

          log.info("Access token: " + accessToken);
        } catch (OAuthMessageSignerException e) {
          log.error("Error oauth1 token: ", e);
          return false;
        } catch (OAuthNotAuthorizedException e) {
          log.error("Error oauth1 token: ", e);
          return false;
        } catch (OAuthExpectationFailedException e) {
          log.error("Error oauth1 token: ", e);
          return false;
        } catch (OAuthCommunicationException e) {
          log.error("Error oauth1 token: ", e);
          return false;
        }
      }
    }
    return true;
  }
コード例 #4
0
 public OAuth2Urls urlsForService(com.ccc.oauth.apimanagement.model.Service service) {
   int serviceId = service.getId();
   List<OAuth2Urls> urls = urlsManager.elementsWithValue("service_id", String.valueOf(serviceId));
   if (urls != null && !urls.isEmpty()) return urls.get(0);
   return null;
 }
コード例 #5
0
 public List<AuthSupports> supportedAuthForService(
     com.ccc.oauth.apimanagement.model.Service service) {
   return authSupportManager.elementsWithValue("service_id", String.valueOf(service.getId()));
 }