Package com.sun.jersey.oauth.signature

Examples of com.sun.jersey.oauth.signature.OAuthParameters


        };

        // create a new OAuth client filter passing the needed info as well as the AuthHandler
        OAuthClientFilter filter = new OAuthClientFilter(
                client.getProviders(),
                new OAuthParameters().consumerKey(PROPERTIES.getProperty(PROPERTY_CONSUMER_KEY))
                    .token(PROPERTIES.getProperty(PROPERTY_TOKEN)),
                new OAuthSecrets().consumerSecret(PROPERTIES.getProperty(PROPERTY_CONSUMER_SECRET))
                    .tokenSecret(PROPERTIES.getProperty(PROPERTY_TOKEN_SECRET)),
                "http://twitter.com/oauth/request_token",
                "http://twitter.com/oauth/access_token",
View Full Code Here


      }
    }
    else if (oAuthConsumerKey != null && oAuthConsumerSecret != null && oAuthSignatureMethod != null) {
      if (this.client == null) {
        Client c = new Client();
        OAuthParameters params = new OAuthParameters()
          .signatureMethod(oAuthSignatureMethod)
          .consumerKey(oAuthConsumerKey)
          .version("1.1");

        OAuthSecrets secrets = new OAuthSecrets()
View Full Code Here

    @Produces(MediaType.APPLICATION_FORM_URLENCODED)
    public Response postAccessTokenRequest(@Context HttpContext hc, @Context Request req) {
        try {
            boolean sigIsOk = false;
            OAuthServerRequest request = new OAuthServerRequest(hc.getRequest());
            OAuthParameters params = new OAuthParameters();
            params.readRequest(request);

            if (params.getToken() == null) {
                throw new WebApplicationException(new Throwable("oauth_token MUST be present."), 400);
            }

            String consKey = params.getConsumerKey();
            if (consKey == null) {
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }

            OAuthToken rt = provider.getRequestToken(params.getToken());
            if (rt == null) {
                // token invalid
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }

            OAuthConsumer consumer = rt.getConsumer();
            if (consumer == null || !consKey.equals(consumer.getKey())) {
                // token invalid
                throw new OAuthException(Response.Status.BAD_REQUEST, null);

            }

            OAuthSecrets secrets = new OAuthSecrets().consumerSecret(consumer.getSecret()).tokenSecret(rt.getSecret());
            try {
                sigIsOk = OAuthSignature.verify(request, params, secrets);
            } catch (OAuthSignatureException ex) {
                Logger.getLogger(AccessTokenRequest.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (!sigIsOk) {
                // signature invalid
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }

            // We're good to go.
            OAuthToken at = provider.newAccessToken(rt, params.getVerifier());
           
            if(at == null) {
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }
View Full Code Here

    @Consumes("application/x-www-form-urlencoded")
    @Produces("application/x-www-form-urlencoded")
    public Response postReqTokenRequest() {
        try {
            OAuthServerRequest request = new OAuthServerRequest(hc.getRequest());
            OAuthParameters params = new OAuthParameters();
            params.readRequest(request);

            String tok = params.getToken();
            if ((tok != null) && (!tok.contentEquals(""))) {
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }

            String consKey = params.getConsumerKey();
            if (consKey == null) {
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }

            OAuthConsumer consumer = provider.getConsumer(consKey);
            if (consumer == null) {
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }
            OAuthSecrets secrets = new OAuthSecrets().consumerSecret(consumer.getSecret()).tokenSecret("");

            boolean sigIsOk = false;
            try {
                sigIsOk = OAuthSignature.verify(request, params, secrets);
            } catch (OAuthSignatureException ex) {
                Logger.getLogger(RequestTokenRequest.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (!sigIsOk) {
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }

            MultivaluedMap<String, String> parameters = new MultivaluedMapImpl();
            for (String n : request.getParameterNames()) {
                parameters.put(n, request.getParameterValues(n));
            }

            OAuthToken rt = provider.newRequestToken(consKey, params.getCallback(), parameters);

            Form resp = new Form();
            resp.putSingle(OAuthParameters.TOKEN, rt.getToken());
            resp.putSingle(OAuthParameters.TOKEN_SECRET, rt.getSecret());
            resp.putSingle(OAuthParameters.CALLBACK_CONFIRMED, "true");
View Full Code Here

        return request;
    }

    private OAuthSecurityContext getSecurityContext(ContainerRequest request) throws OAuthException {
        OAuthServerRequest osr = new OAuthServerRequest(request);
        OAuthParameters params = new OAuthParameters().readRequest(osr);

        // apparently not signed with any OAuth parameters; unauthorized
        if (params.size() == 0) {
            throw newUnauthorizedException();
        }

        // get required OAuth parameters
        String consumerKey = requiredOAuthParam(params.getConsumerKey());
        String token = params.getToken();
        String timestamp = requiredOAuthParam(params.getTimestamp());
        String nonce = requiredOAuthParam(params.getNonce());

        // enforce other supported and required OAuth parameters
        requiredOAuthParam(params.getSignature());
        supportedOAuthParam(params.getVersion(), versions);

        // retrieve secret for consumer key
        OAuthConsumer consumer = provider.getConsumer(consumerKey);
        if (consumer == null) {
            throw newUnauthorizedException();
View Full Code Here

   */
  private void setAccess(String accessToken, String accessSecret){
    this.accessToken = accessToken;
    this.accessSecret = accessSecret;
    if (accessToken != null && accessSecret != null){
      OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY)
        .signatureMethod("HMAC-SHA1").version("1.1").token(accessToken);
      OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET)
        .tokenSecret(accessSecret);
      oAuthFilter = new OAuthClientFilter(client.getProviders(), params, secrets);
      service.addFilter(oAuthFilter);
View Full Code Here

                            state = State.MANAGED;
                        }
                    }

            }
            final OAuthParameters p = (OAuthParameters)parameters.clone(); // make modifications to clone

            if (p.getTimestamp() == null) {
                p.setTimestamp();
            }

            if (p.getNonce() == null) {
                p.setNonce();
            }

            try {
                OAuthSignature.sign(new RequestWrapper(request, providers), p, secrets);
            }
View Full Code Here

TOP

Related Classes of com.sun.jersey.oauth.signature.OAuthParameters

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.