Examples of ClientResource


Examples of org.restlet.resource.ClientResource

            getLogger().info("After Redirecting to : " + redirRef.toUri());
            // return true;
            // return null;
        } else {
            getLogger().info("Came back after SNS code = " + code);
            ClientResource tokenResource = new CookieCopyClientResource(
                    params.getBaseRef() + params.getAccessTokenPath());

            Form form = new Form();
            form.add(OAuthServerResource.GRANT_TYPE,
                    OAuthServerResource.GrantType.authorization_code.name());
            String redir = request.getResourceRef().getHostIdentifier()
                    + request.getResourceRef().getPath();
            form.add(OAuthServerResource.REDIR_URI, redir);

            if (basicSecret) {
                ChallengeResponse authentication = new ChallengeResponse(
                        ChallengeScheme.HTTP_BASIC);
                authentication.setDigestAlgorithm("NONE");
                String basic = params.getClientId() + ':'
                        + params.getClientSecret();
                authentication.setRawValue(Base64.encode(basic.getBytes(),
                        false));
                tokenResource.setChallengeResponse(authentication);
            } else {
                form.add(OAuthServerResource.CLIENT_ID, params.getClientId());
                form.add(OAuthServerResource.CLIENT_SECRET,
                        params.getClientSecret());
            }

            form.add(OAuthServerResource.CODE, code);
            getLogger().info(
                    "Sending access form : " + form.getQueryString() + " to : "
                            + tokenResource.getReference());

            try {
                Representation input = form.getWebRepresentation();
                Representation body = tokenResource.post(input);

                if (tokenResource.getStatus().isSuccess()) {
                    // Store away the user
                    OAuthUser authUser = OAuthUser.createJson(body);

                    if (authUser != null) {
                        request.getClientInfo().setUser(authUser);
                        request.getClientInfo().setAuthenticated(true);
                        getLogger().info(
                                "storing to context = : " + getContext());
                        // continue in the filter chain
                        auth = true;
                    }
                }

                getLogger().info("Before sns release");
                body.release();
            } catch (ResourceException re) {
                getLogger().warning("Could not find token resource.");
            }
            tokenResource.release();
        }
        return auth;
    }
View Full Code Here

Examples of org.restlet.resource.ClientResource

        this.responseLogTemplate = (getLogFormat() == null) ? null
                : new Template(getLogFormat());

        if (getLogPropertiesRef() != null) {
            Representation logProperties = new ClientResource(getContext(),
                    getLogPropertiesRef()).get();

            if (logProperties != null) {
                LogManager.getLogManager().readConfiguration(
                        logProperties.getStream());
View Full Code Here

Examples of org.restlet.resource.ClientResource

            Reference meRef = new Reference("me");
            meRef.addQueryParameter(OAuthServerResource.ACCESS_TOKEN,
                    accessToken);

            ClientResource graphResource = new ClientResource(FB_GRAPH);
            ClientResource meResource = graphResource.getChild(meRef);
            JsonRepresentation meRepr = meResource
                    .get(JsonRepresentation.class);
            if (meResource.getResponse().getStatus().isSuccess()) {
                JSONObject me;
                try {
                    me = meRepr.getJsonObject();
                    String id = me.get("id").toString();
                    log.info("Your ID = " + id);
                    accessTokens.put(id, accessToken);
                    // TODO Set Cookie
                    return true;
                } catch (JSONException e) {
                    log.log(Level.WARNING, "Failed in parsing the me object.",
                            e);
                }
            }
            meRepr.release();
            meResource.release();
            graphResource.release();
        }

        return false;
    }
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.