Package net.oauth

Examples of net.oauth.OAuthProblemException


  /**
   * Returns a {@link OAuthProblemException} with the given problem and the
   * correct status code. The problem should come from {@link OAuth.Problems}.
   */
  public static OAuthProblemException newOAuthProblemException(String problem) {
    OAuthProblemException exception = new OAuthProblemException(problem);
    exception.setParameter(HttpMessage.STATUS_CODE, OAuth.Problems.TO_HTTP_CODE.get(problem));
    return exception;
  }
View Full Code Here


            OAuthMessage oAuthMessage =
                OAuthUtils.getOAuthMessage(request, REQUIRED_PARAMETERS);

            RequestToken requestToken = dataProvider.getRequestToken(oAuthMessage.getToken());
            if (requestToken == null) {
                throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
            }
            String oauthVerifier = oAuthMessage.getParameter(OAuth.OAUTH_VERIFIER);
            if (oauthVerifier == null || !oauthVerifier.equals(requestToken.getVerifier())) {
                throw new OAuthProblemException(OAuthConstants.VERIFIER_INVALID);
            }
           
            OAuthUtils.validateMessage(oAuthMessage, requestToken.getClient(), requestToken,
                                       dataProvider);
View Full Code Here

                OAuthUtils.getOAuthMessage(request, REQUIRED_PARAMETERS);
            new DefaultOAuthValidator().checkSingleParameter(oAuthMessage);

            RequestToken token = dataProvider.getRequestToken(oAuthMessage.getToken());
            if (token == null) {
                throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
            }
           
            OAuthAuthorizationData secData = new OAuthAuthorizationData();
            if (!compareRequestSessionTokens(request, oAuthMessage)) {
                addAuthenticityTokenToSession(secData, request);
View Full Code Here

        String callback = token.getCallback();
        if (callback == null) {
            callback = token.getClient().getApplicationURI();
        }
        if (callback == null) {
            throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
        }
        return callback;
    }
View Full Code Here

            Client client = dataProvider
                .getClient(oAuthMessage.getParameter(OAuth.OAUTH_CONSUMER_KEY));
            //client credentials not found
            if (client == null) {
                OAuthProblemException problemEx = new OAuthProblemException(
                    OAuth.Problems.CONSUMER_KEY_UNKNOWN);
                problemEx
                    .setParameter(OAuthProblemException.HTTP_STATUS_CODE,
                        HttpServletResponse.SC_UNAUTHORIZED);
                throw problemEx;
            }
View Full Code Here

    protected void validateCallbackURL(Client client,
                                       String oauthCallback) throws OAuthProblemException {

        if (!StringUtils.isEmpty(client.getApplicationURI())
                    && !oauthCallback.startsWith(client.getApplicationURI())) {
            OAuthProblemException problemEx = new OAuthProblemException(
                OAuth.Problems.PARAMETER_REJECTED + " - " + OAuth.OAUTH_CALLBACK);
            problemEx
                .setParameter(OAuthProblemException.HTTP_STATUS_CODE,
                    HttpServletResponse.SC_BAD_REQUEST);
            throw problemEx;
           
        }
View Full Code Here

    }

    public static Response handleException(Exception e, int status,
                                           String realm) {
        if (e instanceof OAuthProblemException) {
            OAuthProblemException problem = (OAuthProblemException) e;
            OAuthMessage message = new OAuthMessage(null, null, problem
                    .getParameters().entrySet());
            try {
                return
                        Response.status(status).header("WWW-Authenticate",
                                message.getAuthorizationHeader(realm)).entity(e.getMessage()).build();
View Full Code Here

        return scopeList;
    }

   
    public static RequestToken handleTokenRejectedException() throws OAuthProblemException {
        OAuthProblemException problemEx = new OAuthProblemException(
                OAuth.Problems.TOKEN_REJECTED);
        problemEx
                .setParameter(OAuthProblemException.HTTP_STATUS_CODE, HttpServletResponse.SC_UNAUTHORIZED);
        throw problemEx;
    }
View Full Code Here

            accessToken = dataProvider.getAccessToken(oAuthMessage.getToken());

            //check if access token is not null
            if (accessToken == null) {
                LOG.warning("Access token is unavailable");
                throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
            }
            client = accessToken.getClient();
           
        } else {
            String consumerKey = oAuthMessage.getParameter(OAuth.OAUTH_CONSUMER_KEY);
            String consumerSecret = oAuthMessage.getParameter("oauth_consumer_secret");
            client = dataProvider.getClient(consumerKey);
            if (client == null || consumerSecret == null || !consumerSecret.equals(client.getSecretKey())) {
                LOG.warning("Client is invalid");
                throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_UNKNOWN);
            }
        }

        OAuthUtils.validateMessage(oAuthMessage, client, accessToken, dataProvider);

        //check valid URI
        checkRequestURI(req, getAllUris(client, accessToken));
       
        List<OAuthPermission> permissions = dataProvider.getPermissionsInfo(
                getAllScopes(client, accessToken));
       
        for (OAuthPermission perm : permissions) {
            if (perm.getUri() != null) {
                checkRequestURI(req, Collections.singletonList(perm.getUri()));
            }
            if (!perm.getHttpVerbs().isEmpty()
                && !perm.getHttpVerbs().contains(req.getMethod())) {
                String message = "Invalid http verb";
                LOG.warning(message);
                throw new OAuthProblemException(message);
            }
            checkNoAccessTokenIsAllowed(client, accessToken, perm);
        }
       
        return new OAuthInfo(client, accessToken, permissions);
View Full Code Here

    }
   
    protected void checkNoAccessTokenIsAllowed(Client client, AccessToken token,
            OAuthPermission perm) throws OAuthProblemException {
        if (token == null && perm.isAuthorizationKeyRequired()) {
            throw new OAuthProblemException();
        }
    }
View Full Code Here

TOP

Related Classes of net.oauth.OAuthProblemException

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.