Search in sources :

Example 1 with GadgetException

use of org.apache.shindig.gadgets.GadgetException in project liferay-ide by liferay.

the class LiferayOAuthStore method setTokenInfo.

public void setTokenInfo(SecurityToken securityToken, ConsumerInfo consumerInfo, String serviceName, String tokenName, TokenInfo tokenInfo) throws GadgetException {
    long userId = GetterUtil.getLong(securityToken.getViewerId());
    User user = null;
    try {
        user = UserLocalServiceUtil.getUser(userId);
    } catch (Exception e) {
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
    }
    Gadget gadget = null;
    try {
        gadget = GadgetLocalServiceUtil.fetchGadget(user.getCompanyId(), securityToken.getAppUrl());
    } catch (SystemException se) {
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, se);
    }
    String gadgetKey = StringPool.BLANK;
    if (gadget == null) {
        gadgetKey = GadgetConstants.toAdhocGadgetKey(securityToken.getModuleId());
    } else {
        gadgetKey = GadgetConstants.toPublishedGadgetKey(gadget.getGadgetId());
    }
    try {
        OAuthTokenLocalServiceUtil.addOAuthToken(userId, gadgetKey, serviceName, securityToken.getModuleId(), tokenInfo.getAccessToken(), tokenName, tokenInfo.getTokenSecret(), tokenInfo.getSessionHandle(), tokenInfo.getTokenExpireMillis());
    } catch (Exception e) {
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) User(com.liferay.portal.model.User) SystemException(com.liferay.portal.kernel.exception.SystemException) GadgetException(org.apache.shindig.gadgets.GadgetException) SystemException(com.liferay.portal.kernel.exception.SystemException) GadgetException(org.apache.shindig.gadgets.GadgetException)

Example 2 with GadgetException

use of org.apache.shindig.gadgets.GadgetException in project liferay-ide by liferay.

the class LiferayOAuthStore method getConsumerKeyAndSecret.

public ConsumerInfo getConsumerKeyAndSecret(SecurityToken securityToken, String serviceName, OAuthServiceProvider oAuthServiceProvider) throws GadgetException {
    OAuthConsumer oAuthConsumer = getOAuthConsumer(securityToken, serviceName);
    if (oAuthConsumer == null) {
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, "No key for gadget " + securityToken.getAppUrl() + " and service " + serviceName);
    }
    net.oauth.OAuthConsumer netOAuthConsumer = null;
    String keyType = oAuthConsumer.getKeyType();
    if (keyType.equals(OAuthConsumerConstants.KEY_TYPE_RSA_PRIVATE)) {
        netOAuthConsumer = new net.oauth.OAuthConsumer(null, oAuthConsumer.getConsumerKey(), null, oAuthServiceProvider);
        netOAuthConsumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
        netOAuthConsumer.setProperty(RSA_SHA1.PRIVATE_KEY, oAuthConsumer.getConsumerSecret());
    } else {
        netOAuthConsumer = new net.oauth.OAuthConsumer(null, oAuthConsumer.getConsumerKey(), oAuthConsumer.getConsumerSecret(), oAuthServiceProvider);
        netOAuthConsumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
    }
    String keyName = oAuthConsumer.getKeyName();
    String callbackURL = ShindigUtil.transformURL(_callbackURL);
    return new ConsumerInfo(netOAuthConsumer, keyName, callbackURL);
}
Also used : OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) GadgetException(org.apache.shindig.gadgets.GadgetException)

Example 3 with GadgetException

use of org.apache.shindig.gadgets.GadgetException in project liferay-ide by liferay.

the class LiferayOAuthStore method getOAuthToken.

protected OAuthToken getOAuthToken(SecurityToken securityToken, String serviceName, String tokenName) throws GadgetException {
    long userId = GetterUtil.getLong(securityToken.getViewerId());
    OAuthToken oAuthToken = null;
    try {
        oAuthToken = OAuthTokenLocalServiceUtil.fetchOAuthToken(userId, securityToken.getAppId(), serviceName, securityToken.getModuleId(), tokenName);
    } catch (SystemException se) {
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, se);
    }
    return oAuthToken;
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken) SystemException(com.liferay.portal.kernel.exception.SystemException) GadgetException(org.apache.shindig.gadgets.GadgetException)

Aggregations

GadgetException (org.apache.shindig.gadgets.GadgetException)3 SystemException (com.liferay.portal.kernel.exception.SystemException)2 Gadget (com.liferay.opensocial.model.Gadget)1 OAuthConsumer (com.liferay.opensocial.model.OAuthConsumer)1 OAuthToken (com.liferay.opensocial.model.OAuthToken)1 User (com.liferay.portal.model.User)1