Package org.apache.shindig.social.opensocial.oauth

Examples of org.apache.shindig.social.opensocial.oauth.OAuthEntry


     */
    @Override
    public OAuthEntry execute(final PrincipalActionContext inActionContext) throws ExecutionException
    {
        CreateOAuthRequestTokenRequest currentRequest = (CreateOAuthRequestTokenRequest) inActionContext.getParams();
        OAuthEntry entry = new OAuthEntry();
        entry.setAppId(currentRequest.getConsumerKey());
        entry.setConsumerKey(currentRequest.getConsumerKey());
        entry.setDomain(oauthDomain);
        entry.setContainer(oauthContainer);

        entry.setToken(UUID.randomUUID().toString());
        entry.setTokenSecret(UUID.randomUUID().toString());

        entry.setType(OAuthEntry.Type.REQUEST);
        entry.setIssueTime(new Date());
        entry.setOauthVersion(currentRequest.getOauthVersion());
        if (currentRequest.getSignedCallbackUrl() != null)
        {
            entry.setCallbackUrlSigned(true);
            entry.setCallbackUrl(currentRequest.getSignedCallbackUrl());
        }

        OAuthDomainEntry dto = oauthConversionStrat.convertToEntryDTO(entry);
        insertMapper.execute(new PersistenceRequest<OAuthDomainEntry>(dto));
        return entry;
View Full Code Here


     *            the token.
     * @return the associated entry.
     */
    public OAuthEntry getEntry(final String oauthToken)
    {
        OAuthEntry entry = null;
        try
        {
            ServiceActionContext currentContext = new ServiceActionContext(oauthToken, null);
            entry = (OAuthEntry) actionController.execute(currentContext, getOAuthEntryByTokenAction);
        }
View Full Code Here

        log.trace("Request made to OAuthAccessTokenResource");
        try
        {
            OAuthMessage requestMessage = new RestletRequestMessage(this.getRequest());

            OAuthEntry entry = getValidatedEntry(requestMessage);
            if (entry == null)
            {
                throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
            }

            if (entry.getCallbackToken() != null)
            {
                // We're using the fixed protocol
                String clientCallbackToken = requestMessage.getParameter(OAuth.OAUTH_VERIFIER);
                if (!entry.getCallbackToken().equals(clientCallbackToken))
                {
                    dataStore.disableToken(entry);
                    throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, "This token is not authorized");
                }
            }
            else if (!entry.isAuthorized())
            {
                // Old protocol. Catch consumers trying to convert a token to one that's not authorized
                dataStore.disableToken(entry);
                throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, "This token is not authorized");
            }

            // turn request token into access token
            OAuthEntry accessEntry = dataStore.convertToAccessToken(entry);

            List<Parameter> params = OAuth.newList(OAuth.OAUTH_TOKEN, accessEntry.getToken(), OAuth.OAUTH_TOKEN_SECRET,
                    accessEntry.getTokenSecret(), "user_id", entry.getUserId());

            Representation rep = new StringRepresentation(OAuth.formEncode(params), MediaType.TEXT_PLAIN);
            return rep;
        }
        catch (IOException e)
View Full Code Here

     *          thrown if malformed URI was sent in the message.
     */
    private OAuthEntry getValidatedEntry(final OAuthMessage requestMessage) throws IOException,
            OAuthException, URISyntaxException
    {
        OAuthEntry entry = dataStore.getEntry(requestMessage.getToken());
        if (entry == null)
        {
            throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED);
        }

        if (entry.getType() != OAuthEntry.Type.REQUEST)
        {
            throw new OAuthProblemException(OAuth.Problems.TOKEN_USED);
        }

        if (entry.isExpired())
        {
            throw new OAuthProblemException(OAuth.Problems.TOKEN_EXPIRED);
        }

        // find consumer key, compare with supplied value, if present.

        if (requestMessage.getConsumerKey() == null)
        {
            OAuthProblemException e = new OAuthProblemException(OAuth.Problems.PARAMETER_ABSENT);
            e.setParameter(OAuth.Problems.OAUTH_PARAMETERS_ABSENT, OAuth.OAUTH_CONSUMER_KEY);
            throw e;
        }

        String consumerKey = entry.getConsumerKey();
        if (!consumerKey.equals(requestMessage.getConsumerKey()))
        {
            throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_REFUSED);
        }

        OAuthConsumer consumer = dataStore.getConsumer(consumerKey);

        if (consumer == null)
        {
            throw new OAuthProblemException(OAuth.Problems.CONSUMER_KEY_UNKNOWN);
        }

        OAuthAccessor accessor = new OAuthAccessor(consumer);

        accessor.requestToken = entry.getToken();
        accessor.tokenSecret = entry.getTokenSecret();

        VALIDATOR.validateMessage(requestMessage, accessor);

        return entry;
    }
View Full Code Here

             * OAuthProblemException(OAuth.Problems.PARAMETER_ABSENT);
             * e.setParameter(OAuth.Problems.OAUTH_PARAMETERS_ABSENT, OAuth.OAUTH_CALLBACK); throw e; }
             */

            // generate request_token and secret
            OAuthEntry entry = dataStore.generateRequestToken(consumerKey, requestMessage
                    .getParameter(OAuth.OAUTH_VERSION), callback);

            List<Parameter> responseParams = OAuth.newList(OAuth.OAUTH_TOKEN, entry.getToken(),
                    OAuth.OAUTH_TOKEN_SECRET, entry.getTokenSecret());
            if (callback != null)
            {
                responseParams.add(new Parameter(OAuth.OAUTH_CALLBACK_CONFIRMED, "true"));
            }

View Full Code Here

     * {@inheritDoc}. Convert the supplied Request Token into an Access Token.
     */
    @Override
    public OAuthEntry execute(final PrincipalActionContext inActionContext) throws ExecutionException
    {
        OAuthEntry requestEntry = (OAuthEntry) inActionContext.getParams();
        OAuthEntry accessEntry = new OAuthEntry(requestEntry);

        accessEntry.setToken(UUID.randomUUID().toString());
        accessEntry.setTokenSecret(UUID.randomUUID().toString());

        accessEntry.setType(OAuthEntry.Type.ACCESS);
        accessEntry.setIssueTime(new Date());

        deleteMapper.execute(requestEntry.getToken());
        insertMapper.execute(new PersistenceRequest<OAuthDomainEntry>(conversionStrat.convertToEntryDTO(accessEntry)));

        return accessEntry;
View Full Code Here

    {
        final String accountId = inActionContext.getPrincipal().getAccountId();
        final String token = (String) inActionContext.getParams();

        log.trace("Authorizing OAuth token for user: " + accountId);
        OAuthEntry tokenEntry = new OAuthEntry();
        tokenEntry.setToken(token);

        try
        {
            OAuthDomainEntry dto = entryMapper.execute(token);
            dto.setAuthorized(true);
            if (dto.isCallbackUrlSigned())
            {
                dto.setCallbackToken(Crypto.getRandomDigits(CALLBACK_TOKEN_LENGTH));
            }
        }
        catch (Exception ex)
        {
            log.error("An error occurred authorizing the OAuth token.", ex);
            throw new ExecutionException(ex);
        }

        OAuthDomainEntry currentEntry = entryMapper.execute(tokenEntry.getToken());
        log.trace("Authorization for user: " + accountId + " complete.");
        String callbackUrl = "";
        if (currentEntry.getCallbackUrl() != null && currentEntry.getCallbackUrl().length() > 0)
        {
            try
View Full Code Here

     *          the dto to convert.
     * @return the converted entry.
     */
    public OAuthEntry convertToEntry(final OAuthDomainEntry dto)
    {
        OAuthEntry entry = new OAuthEntry();
        entry.setAppId(dto.getAppId());
        entry.setAuthorized(dto.isAuthorized());
        entry.setCallbackToken(dto.getCallbackToken());
        entry.setCallbackTokenAttempts(dto.getCallbackTokenAttempts());
        entry.setCallbackUrl(dto.getCallbackUrl());
        entry.setCallbackUrlSigned(dto.isCallbackUrlSigned());
        entry.setConsumerKey(dto.getConsumer().getConsumerKey());
        entry.setContainer(dto.getContainer());
        entry.setDomain(dto.getDomain());
        entry.setIssueTime(dto.getIssueTime());
        entry.setOauthVersion(dto.getOauthVersion());
        entry.setToken(dto.getToken());
        entry.setTokenSecret(dto.getTokenSecret());
        entry.setType(Type.valueOf(dto.getType()));
        entry.setUserId(dto.getUserId());
        return entry;
    }
View Full Code Here

TOP

Related Classes of org.apache.shindig.social.opensocial.oauth.OAuthEntry

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.