protected OAuthToken getOAuthToken(
      SecurityToken securityToken, String serviceName, String tokenName) 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.getGadget(user.getCompanyId(), securityToken.getAppUrl());
    } catch (Exception e) {
      throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
    }

    OAuthToken oAuthToken = null;

    try {
      oAuthToken =
          OAuthTokenLocalServiceUtil.getOAuthToken(
              userId, gadget.getGadgetId(), serviceName, securityToken.getModuleId(), tokenName);
    } catch (Exception e) {
    }

    return oAuthToken;
  }
Exemple #2
0
 private CollectionOptions manipulateCollectionOptions(
     CollectionOptions options, SecurityToken token) {
   if (options != null && options.getFilterValue() != null) {
     if (options.getFilterValue().equalsIgnoreCase(AbstractSecurityToken.Keys.OWNER.name()))
       options.setFilterValue(token.getOwnerId());
     else if (options.getFilterValue().equalsIgnoreCase(AbstractSecurityToken.Keys.VIEWER.name()))
       options.setFilterValue(token.getViewerId());
   }
   return options;
 }
Exemple #3
0
 @Override
 public List<org.apache.rave.model.Person> getPeople(
     Set<UserId> userIds,
     GroupId groupId,
     CollectionOptions collectionOptions,
     SecurityToken token) {
   switch (groupId.getType()) {
     case all:
       return getUniqueListOfConnectedPeople(userIds, collectionOptions, token);
     case friends:
       return getUniqueListOfFriends(userIds, collectionOptions, token);
     case objectId:
       return getGroupMembersFromRepository(
           collectionOptions, groupId.getObjectId().toString(), token.getAppId());
     case self:
       UserId id =
           userIds.size() == 1 ? userIds.iterator().next() : new UserId(UserId.Type.me, null);
       return Lists.newArrayList(getPersonForId(id, token));
     case custom:
       throw new ProtocolException(
           HttpServletResponse.SC_NOT_IMPLEMENTED,
           "Custom GroupIDs are not tracked by the container");
     default:
       throw new ProtocolException(
           HttpServletResponse.SC_BAD_REQUEST, "Invalid group id specified by request");
   }
 }
  protected OAuthConsumer getOAuthConsumer(SecurityToken securityToken, String serviceName)
      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.getGadget(user.getCompanyId(), securityToken.getAppUrl());
    } catch (Exception e) {
      throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
    }

    OAuthConsumer oAuthConsumer = null;

    try {
      oAuthConsumer =
          OAuthConsumerLocalServiceUtil.getOAuthConsumer(gadget.getGadgetId(), serviceName);
    } catch (Exception e) {
      return _oAuthConsumer;
    }

    if (oAuthConsumer.getKeyType().equals(OAuthConsumerConstants.KEY_TYPE_RSA_PRIVATE)) {

      if (_oAuthConsumer == null) {
        throw new GadgetException(
            GadgetException.Code.INTERNAL_SERVER_ERROR, "No OAuth key specified");
      }

      oAuthConsumer.setConsumerSecret(_oAuthConsumer.getConsumerSecret());
    }

    return oAuthConsumer;
  }
  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.getGadget(user.getCompanyId(), securityToken.getAppUrl());
    } catch (Exception e) {
      throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
    }

    try {
      OAuthTokenLocalServiceUtil.addOAuthToken(
          userId,
          gadget.getGadgetId(),
          serviceName,
          securityToken.getModuleId(),
          tokenInfo.getAccessToken(),
          tokenName,
          tokenInfo.getTokenSecret(),
          tokenInfo.getSessionHandle(),
          tokenInfo.getTokenExpireMillis());
    } catch (Exception e) {
      throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
    }
  }
Exemple #6
0
  private List<org.apache.rave.model.Person> getUniqueListOfFriends(
      Set<UserId> userIds, CollectionOptions collectionOptions, SecurityToken token) {

    List<org.apache.rave.model.Person> people = new ArrayList<org.apache.rave.model.Person>();
    for (UserId id : userIds) {
      org.apache.rave.model.Person person = this.getPersonForId(id, token);
      CollectionUtils.addUniqueValues(
          getFriendsFromRepository(collectionOptions, token.getAppId(), person.getUsername()),
          people);
    }
    return people;
  }
  protected ThemeDisplay getThemeDisplay(SecurityToken securityToken) throws Exception {

    long userIdLong = GetterUtil.getLong(securityToken.getViewerId());

    User user = UserLocalServiceUtil.getUserById(userIdLong);

    Company company = CompanyLocalServiceUtil.getCompanyById(user.getCompanyId());

    ThemeDisplay themeDisplay = new ThemeDisplay();

    themeDisplay.setCompany(company);
    themeDisplay.setLocale(user.getLocale());
    themeDisplay.setUser(user);

    return themeDisplay;
  }
  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 = _callbackURL.replace("%host%", ShindigUtil.getHost());

    return new ConsumerInfo(netOAuthConsumer, keyName, callbackURL);
  }