Examples of OAuthRequestFailedException


Examples of org.springframework.security.oauth.consumer.OAuthRequestFailedException

        catch (OAuthRequestFailedException eo) {
          fail(request, response, eo);
        }
        catch (Exception ex) {
          Throwable[] causeChain = getThrowableAnalyzer().determineCauseChain(ex);
          OAuthRequestFailedException rfe = (OAuthRequestFailedException) getThrowableAnalyzer().getFirstThrowableOfType(OAuthRequestFailedException.class, causeChain);
          if (rfe != null) {
            fail(request, response, rfe);
          }
          else {
            // Rethrow ServletExceptions and RuntimeExceptions as-is
View Full Code Here

Examples of org.springframework.security.oauth.consumer.OAuthRequestFailedException

    AccessTokenRequiredException ase = (AccessTokenRequiredException) getThrowableAnalyzer().getFirstThrowableOfType(AccessTokenRequiredException.class, causeChain);
    ProtectedResourceDetails resourceThatNeedsAuthorization;
    if (ase != null) {
      resourceThatNeedsAuthorization = ase.getResource();
      if (resourceThatNeedsAuthorization == null) {
        throw new OAuthRequestFailedException(ase.getMessage());
      }
    }
    else {
      // Rethrow ServletExceptions and RuntimeExceptions as-is
      if (ex instanceof ServletException) {
View Full Code Here

Examples of org.springframework.security.oauth.consumer.OAuthRequestFailedException

  }

  // Inherited.
  public InputStream readProtectedResource(URL url, OAuthConsumerToken accessToken, String httpMethod) throws OAuthRequestFailedException {
    if (accessToken == null) {
      throw new OAuthRequestFailedException("A valid access token must be supplied.");
    }

    ProtectedResourceDetails resourceDetails = getProtectedResourceDetailsService().loadProtectedResourceDetailsById(accessToken.getResourceId());
    if ((!resourceDetails.isAcceptsAuthorizationHeader()) && !"POST".equalsIgnoreCase(httpMethod) && !"PUT".equalsIgnoreCase(httpMethod)) {
      throw new IllegalArgumentException("Protected resource " + resourceDetails.getId() + " cannot be accessed with HTTP method " +
View Full Code Here

Examples of org.springframework.security.oauth.consumer.OAuthRequestFailedException

      if (responseMessage == null) {
        responseMessage = "Unknown Error";
      }
    }
    catch (IOException e) {
      throw new OAuthRequestFailedException("OAuth connection failed.", e);
    }

    if (responseCode >= 200 && responseCode < 300) {
      try {
        return connection.getInputStream();
      }
      catch (IOException e) {
        throw new OAuthRequestFailedException("Unable to get the input stream from a successful response.", e);
      }
    }
    else if (responseCode == 400) {
      throw new OAuthRequestFailedException("OAuth authentication failed: " + responseMessage);
    }
    else if (responseCode == 401) {
      String authHeaderValue = connection.getHeaderField("WWW-Authenticate");
      if (authHeaderValue != null) {
        Map<String, String> headerEntries = StringSplitUtils.splitEachArrayElementAndCreateMap(StringSplitUtils.splitIgnoringQuotes(authHeaderValue, ','), "=", "\"");
        String requiredRealm = headerEntries.get("realm");
        if ((requiredRealm != null) && (!requiredRealm.equals(realm))) {
          throw new InvalidOAuthRealmException(String.format("Invalid OAuth realm. Provider expects \"%s\", when the resource details specify \"%s\".", requiredRealm, realm), requiredRealm);
        }
      }

      throw new OAuthRequestFailedException("OAuth authentication failed: " + responseMessage);
    }
    else {
      throw new OAuthRequestFailedException(String.format("Invalid response code %s (%s).", responseCode, responseMessage));
    }
  }
View Full Code Here

Examples of org.springframework.security.oauth.consumer.OAuthRequestFailedException

      else if ("https".equalsIgnoreCase(url.getProtocol())) {
        URLStreamHandler streamHandler = getStreamHandlerFactory().getHttpsStreamHandler(details, requestToken, this, httpMethod, additionalParameters);
        return new URL(url.getProtocol(), url.getHost(), url.getPort(), file, streamHandler);
      }
      else {
        throw new OAuthRequestFailedException("Unsupported OAuth protocol: " + url.getProtocol());
      }
    }
    catch (MalformedURLException e) {
      throw new IllegalStateException(e);
    }
View Full Code Here

Examples of org.springframework.security.oauth.consumer.OAuthRequestFailedException

      }

      tokenInfo = new String(out.toByteArray(), "UTF-8");
    }
    catch (IOException e) {
      throw new OAuthRequestFailedException("Unable to read the token.", e);
    }

    StringTokenizer tokenProperties = new StringTokenizer(tokenInfo, "&");
    Map<String, String> tokenPropertyValues = new TreeMap<String, String>();
    while (tokenProperties.hasMoreElements()) {
      try {
        String tokenProperty = (String) tokenProperties.nextElement();
        int equalsIndex = tokenProperty.indexOf('=');
        if (equalsIndex > 0) {
          String propertyName = OAuthCodec.oauthDecode(tokenProperty.substring(0, equalsIndex));
          String propertyValue = OAuthCodec.oauthDecode(tokenProperty.substring(equalsIndex + 1));
          tokenPropertyValues.put(propertyName, propertyValue);
        }
        else {
          tokenProperty = OAuthCodec.oauthDecode(tokenProperty);
          tokenPropertyValues.put(tokenProperty, null);
        }
      }
      catch (DecoderException e) {
        throw new OAuthRequestFailedException("Unable to decode token parameters.");
      }
    }

    String tokenValue = tokenPropertyValues.remove(OAuthProviderParameter.oauth_token.toString());
    if (tokenValue == null) {
      throw new OAuthRequestFailedException("OAuth provider failed to return a token.");
    }

    String tokenSecret = tokenPropertyValues.remove(OAuthProviderParameter.oauth_token_secret.toString());
    if (tokenSecret == null) {
      throw new OAuthRequestFailedException("OAuth provider failed to return a token secret.");
    }

    OAuthConsumerToken consumerToken = new OAuthConsumerToken();
    consumerToken.setValue(tokenValue);
    consumerToken.setSecret(tokenSecret);
View Full Code Here

Examples of org.springframework.security.oauth.consumer.OAuthRequestFailedException

    OAuthSignatureMethod signatureMethod;
    try {
      signatureMethod = getSignatureFactory().getSignatureMethod(details.getSignatureMethod(), details.getSharedSecret(), tokenSecret);
    }
    catch (UnsupportedSignatureMethodException e) {
      throw new OAuthRequestFailedException(e.getMessage(), e);
    }
    String signature = signatureMethod.sign(signatureBaseString);
    oauthParams.put(OAuthConsumerParameter.oauth_signature.toString(), Collections.singleton((CharSequence) signature));
    return oauthParams;
  }
View Full Code Here

Examples of org.springframework.security.oauth.consumer.OAuthRequestFailedException

      connection.setConnectTimeout(getConnectionTimeout());
      connection.setReadTimeout(getReadTimeout());
      return connection;
    }
    catch (IOException e) {
      throw new OAuthRequestFailedException("Failed to open an OAuth connection.", e);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.