Commits

Juan Carlos Picado Herrera  committed b7e1597 Merge

Merge branch 'juanpicado' into development

  • Participants
  • Parent commits 4f8369b, e8d9712

Comments (0)

Files changed (80)

File encuestame-business/pom.xml

                 <groupId>org.springframework.social</groupId>
                 <artifactId>spring-social-core</artifactId>
             </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-facebook</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-twitter</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-linkedin</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-github</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-tripit</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-web</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-gowalla</artifactId>
+            </dependency>
               <!-- Spring Security -->
              <dependency>
                 <groupId>org.springframework.security</groupId>

File encuestame-business/src/main/java/org/encuestame/business/security/oauth/AppConnectionProviderToken.java

      */
     public Authentication getUserAuthentication() {
         if (userAuthentication == null) {
-            UserAccount account = this.accountDaoImp.getSecondaryUserById(connection.getAccount().getUid());
+            UserAccount account = this.accountDaoImp.getUserAccountById(connection.getAccount().getUid());
             log.debug("Get User Authentication "+account);
             return this.authenticationTokenFor(account);
         }
         return new UsernamePasswordAuthenticationToken(account, null, (Collection<GrantedAuthority>)null);
     }
 
-}
+}

File encuestame-business/src/main/java/org/encuestame/business/service/AbstractBaseService.java

      */
     public UserAccountBean getUserCompleteInfo(final Long userId, final String currentUsername) throws EnMeDomainNotFoundException {
         UserAccountBean userInfo = null;
-        final UserAccount user = getAccountDao().getSecondaryUserById(userId);
+        final UserAccount user = getAccountDao().getUserAccountById(userId);
         if(this.validateOwnerGroup(user, currentUsername)){
             userInfo =  ConvertDomainBean.convertSecondaryUserToUserBean(user);
             log.debug("getUserCompleteInfo info "+userInfo.getId());
      * @return
      */
     public UserAccount getValidateUser(final Long userId, final String currentUsername){
-        final UserAccount user = getAccountDao().getSecondaryUserById(userId);
+        final UserAccount user = getAccountDao().getUserAccountById(userId);
         UserAccount expetedUser = null;
         if(this.validateOwnerGroup(user, currentUsername)){
             expetedUser = user;

File encuestame-business/src/main/java/org/encuestame/business/service/AbstractConfigurationService.java

     private @Value("${application.picture.path}") String dataGlobalPath;
 
     /**
+     * App Consumer Key.
+     */
+    public @Value("${twitter.oauth.consumerKey}") String consumerKey;
+
+    /**
+     * App consumer secret.
+     */
+    public @Value("${twitter.oauth.consumerSecret}") String consumerSecret;
+
+    /**
      * @return the domainUrl
      */
     public String getDomainUrl() {

File encuestame-business/src/main/java/org/encuestame/business/service/AbstractDataSource.java

     private IEmail emailListsDao;
 
     /**
-     * Get User.
-     * @param username
+     * Get {@link UserAccount} by Username.
+     * @param username username
      * @return user domain
      * @throws EnMeDomainNotFoundException exception
      */
             throw new EnMeDomainNotFoundException(" user not found {"+username+"}");
         } else {
             //TODO: we can add others validations, like is disabled, banned or the account is expired.
-            return getAccountDao().getUserByUsername(username);
+            return userAccount;
+        }
+    }
+
+    /**
+     * Get {@link UserAccount} by Id.
+     * @param userId user id
+     * @return {@link UserAccount}.
+     * @throws EnMeDomainNotFoundException
+     */
+   public final UserAccount getUserAccount(final Long userId) throws EnMeDomainNotFoundException {
+        final UserAccount userAccount = getAccountDao().getUserAccountById(userId);
+        if(userAccount == null){
+            throw new EnMeDomainNotFoundException(" user id not found {"+userId+"}");
+        } else {
+            //TODO: we can add others validations, like is disabled, banned or the account is expired.
+            return userAccount;
         }
     }
 
     /**
-     * Get secondary. User.
-     * @param userId
+     * Get {@link UserAccount} by Id.
+     * @param userId user id.
      * @return
+     * @see user getUserAccount(id);
+     * @deprecated should be use getUserAccount.
      */
+    @Deprecated
     public final UserAccount getUser(final Long  userId){
-        return getAccountDao().getSecondaryUserById(userId);
+        return getAccountDao().getUserAccountById(userId);
     }
 
     /**
                 projectDomain.setHideProject(projectBean.getHide());
                 projectDomain.setNotifyMembers(projectBean.getNotify());
                 if(projectBean.getLeader()!=null){
-                    projectDomain.setLead(getAccountDao().getSecondaryUserById(projectBean.getLeader()));
+                    projectDomain.setLead(getAccountDao().getUserAccountById(projectBean.getLeader()));
                 }
                 projectDomain.setUsers(getAccountDao().getUserById(projectBean.getUserId()));
                 getProjectDaoImp().saveOrUpdate(projectDomain);

File encuestame-business/src/main/java/org/encuestame/business/service/ProjectService.java

         if (projectBean != null) {
             try {
                 final Project projectDomain = new Project();
-                final UserAccount secondary = getAccountDao().getSecondaryUserById(projectBean.getLeader());
+                final UserAccount secondary = getAccountDao().getUserAccountById(projectBean.getLeader());
                 final Account user = getUserAccount(username).getAccount();
                 projectDomain.setProjectDateFinish(projectBean.getDateFinish());
                 projectDomain.setProjectDateStart(projectBean.getDateInit());
             throw new EnMeExpcetion("project not found");
         }
         else{
-            final UserAccount secondary = getAccountDao().getSecondaryUserById(projectBean.getLeader());
+            final UserAccount secondary = getAccountDao().getUserAccountById(projectBean.getLeader());
             final Account user = getUserAccount(username).getAccount();
             project.setProjectName(projectBean.getName());
             project.setHideProject(projectBean.getHide());

File encuestame-business/src/main/java/org/encuestame/business/service/SecurityService.java

     /** Default User Permission **/
     private static final String PUBLISHER = EnMePermission.ENCUESTAME_PUBLISHER.name();
 
-    /** Anonnymous User. **/
-    private static final String ANONYMOUS = EnMePermission.ENCUESTAME_ANONYMOUS.name();
-
 
     private final Integer DEFAULT_LENGTH_PASSWORD = 8;
 
 
     /**
      * Retrieve Total Own Users.
-     * @param username
-     * @return
-     * @throws EnMeDomainNotFoundException
+     * @param username username
+     * @return total own users.
+     * @throws EnMeDomainNotFoundException exception
      */
     public Long totalOwnUsers(final String username) throws EnMeDomainNotFoundException{
         return getAccountDao().retrieveTotalUsers(getUserAccount(username).getAccount());
 
     /**
      * Load Groups by Client
-     * @return
-     * @throws EnMeDomainNotFoundException
+     * @return list of groups
+     * @throws EnMeDomainNotFoundException exception
      */
     public List<UnitGroupBean> loadGroups(final String currentUsername) throws EnMeDomainNotFoundException{
         final UserAccount userAccount = getUserAccount(currentUsername);
 
     /**
      * Update Twitter Account.
-     * @param account account
+     * @param accountBean account
      * @param password password
-     * @param secUser {@link Account}
      * TODO: this method is close to be deprecated, twitter don't allow password login.
      */
+    @Deprecated
     public void updateTwitterAccount(
             final UnitTwitterAccountBean accountBean,
             final String password,
         if(accountBean.getAccountId() != null){
             final SocialAccount twitterAccount = getAccountDao().getTwitterAccount(accountBean.getAccountId());
             if(twitterAccount != null){
-                twitterAccount.setTwitterPassword(password);
+                //twitterAccount.setTwitterPassword(password);
                 twitterAccount.setVerfied(verify);
                 log.debug("Updating twitter password account");
                 getAccountDao().saveOrUpdate(twitterAccount);
             final String username) throws EnMeExpcetion{
          //TODO: we should search twitter account filter by username
          final SocialAccount twitterAccount = this.getSocialAccount(accountBean.getAccountId()); //TODO: filter by Username Too
-         twitterAccount.setConsumerKey(accountBean.getKey());
-         twitterAccount.setConsumerSecret(accountBean.getSecret());
+         //twitterAccount.setConsumerKey(accountBean.getKey());
+         //twitterAccount.setConsumerSecret(accountBean.getSecret());
          twitterAccount.setType(ConvertDomainBean.convertStringToEnum(accountBean.getType()));
          if(accountBean.getPin() != null && !accountBean.getPin().isEmpty()){
              log.debug("PIN Exists {"+accountBean.getPin());
-             twitterAccount.setTwitterPin(Integer.valueOf(accountBean.getPin()));
+             //twitterAccount.setTwitterPin(Integer.valueOf(accountBean.getPin()));
             //If exist pin, we can verify credentials
             log.debug("Verify OAuth Credentials");
                 if(verifyCredentials(
                 }
          } else {
              log.info("Account not verified, pin not found");
-             twitterAccount.setTwitterPin(null);
+             //twitterAccount.setTwitterPin(null);
              twitterAccount.setVerfied(Boolean.FALSE);
          }
         log.debug("Update Secret Twitter Credentials");
 
     /**
      * Update OAuth Token/Secret Social Account.
-     * @param accountId
+     * @param socialAccountId
      * @param token
      * @param tokenSecret
      * @param username
+     * @param account
      * @throws EnMeExpcetion
      */
-    public void updateOAuthTokenSocialAccount(final Long accountId, final String token, final String tokenSecret,
-            final String username) throws EnMeExpcetion{
-        final SocialAccount twitterAccount = this.getSocialAccount(accountId); //TODO: filter by Username Too
-        if(twitterAccount == null){
-            throw new EnMeExpcetion("Social Account not found");
-        }
-        else{
+    public void addOAuthTokenSocialAccount(
+            final Long socialAccountId,
+            final String token,
+            final String tokenSecret,
+            final String username,
+            final UserAccount account) throws EnMeExpcetion{
+        final SocialAccount socialAccount = new SocialAccount();
             log.debug("Updating  Token to {"+token);
             log.debug("Updating Secret Token to {"+tokenSecret);
-            twitterAccount.setToken(token);
-            twitterAccount.setSecretToken(tokenSecret);
-            getAccountDao().saveOrUpdate(twitterAccount);
+            socialAccount.setToken(token);
+            socialAccount.setVerfied(Boolean.TRUE);
+            socialAccount.setSecUsers(account.getAccount());
+            socialAccount.setSocialAccountName(username);
+            socialAccount.setType(TypeAuth.OAUTH);
+            socialAccount.setSecretToken(tokenSecret);
+            socialAccount.setSocialUserId(socialAccountId);
+            getAccountDao().saveOrUpdate(socialAccount);
             log.debug("Updated Token");
-        }
     }
 
-    /**
-     * Add new Twitter Account.
-     * @param account account.
-     * @param username
-     * @throws EnMeDomainNotFoundException
-     */
-    public void addNewTwitterAccount(final String account, final String username) throws EnMeDomainNotFoundException{
-        final Account user = getUserAccount(username).getAccount();
-        final SocialAccount userTwitterAccount = new SocialAccount();
-        userTwitterAccount.setSecUsers(user);
-        userTwitterAccount.setTwitterAccount(account);
-        userTwitterAccount.setTwitterPassword("");
-        userTwitterAccount.setType(TypeAuth.PASSWORD); //By default is PASSWORD.
-        getAccountDao().saveOrUpdate(userTwitterAccount);
-    }
 
     /**
      * Get Twitter Account.
             // save user
             getAccountDao().saveOrUpdate(userAccount);
             // assing first default group to user
-            final UserAccount retrievedUser = getAccountDao().getSecondaryUserById(userAccount.getUid());
+            final UserAccount retrievedUser = getAccountDao().getUserAccountById(userAccount.getUid());
             final Permission permission = getPermissionByName(SecurityService.DEFAULT);
             if(permission != null){
                 final List<Permission> all = getPermissionDao().findAllPermissions();
         log.info("userBean found "+userBean.getId());
         log.info("permissionBean found "+permissionBean.getId());
         if (userBean.getId() != null) {
-            userDomain = getAccountDao().getSecondaryUserById(userBean.getId());
+            userDomain = getAccountDao().getUserAccountById(userBean.getId());
             log.info("user found "+userDomain);
         }
         if (permissionBean.getId() != null) {

File encuestame-business/src/main/java/org/encuestame/business/service/TweetPollService.java

                 final SocialAccount socialTwitterAccounts = getAccountDao().getTwitterAccount(unitTwitterAccountBean.getAccountId());
                 publishedStatus.setApiType(Type.TWITTER);
                 if(socialTwitterAccounts != null && tweetPoll != null){
-                    log.debug("secUserTwitterAccounts Account"+socialTwitterAccounts.getTwitterAccount());
+                    log.debug("secUserTwitterAccounts Account"+socialTwitterAccounts.getSocialAccountName());
                     publishedStatus.setTweetPoll(tweetPoll);
                     publishedStatus.setTwitterAccount(socialTwitterAccounts);
                     try {
                         publishedStatus.setPublicationDateTweet(status.getCreatedAt());
                         publishedStatus.setStatus(TweetPollSavedPublishedStatus.Status.SUCCESS);
                         createNotification(NotificationEnum.TWEETPOLL_PUBLISHED,
-                                buildTwitterItemView(socialTwitterAccounts.getTwitterAccount(), String.valueOf(status.getId())),
+                                buildTwitterItemView(socialTwitterAccounts.getSocialAccountName(), String.valueOf(status.getId())),
                                 socialTwitterAccounts.getSecUsers());
                     } catch (Exception e) {
                         log.error("Error publish tweet "+e.getMessage());

File encuestame-business/src/main/java/org/encuestame/business/service/TwitterService.java

-/*
- ************************************************************************************
- * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2010
- * encuestame Development Team.
- * Licensed under the Apache Software License version 2.0
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to  in writing,  software  distributed
- * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
- * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
- * specific language governing permissions and limitations under the License.
- ************************************************************************************
- */
-
-package org.encuestame.business.service;
-
-import java.io.IOException;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.encuestame.business.service.imp.ITwitterService;
-import org.encuestame.core.util.SocialUtils;
-import org.encuestame.persistence.domain.security.SocialAccount;
-import org.springframework.stereotype.Service;
-
-import twitter4j.Status;
-import twitter4j.Twitter;
-import twitter4j.TwitterException;
-import twitter4j.TwitterFactory;
-import twitter4j.User;
-import twitter4j.http.AccessToken;
-import twitter4j.http.RequestToken;
-
-/**
- * Twitter Service.
- * @author Picado, Juan juan@encuestame.org
- * @since Feb 13, 2010 4:07:03 PM
- * @version $Id$
- */
-@Service
-public class TwitterService extends AbstractBaseService implements ITwitterService {
-
-
-    private String tinyApi;
-
-    private Log log = LogFactory.getLog(this.getClass());
-
-    /**
-     * Constructor.
-     */
-    public TwitterService() {
-    }
-
-    /**
-     * Get Tiny Url.
-     * @param url survey url
-     * @return tiny url
-     * @throws IOException IOException
-     * @throws HttpException HttpExceptio
-     * @deprecated moved to {@link SocialUtils}.
-     */
-    @Deprecated
-    public String getTinyUrl(final String url) throws HttpException, IOException{
-        final HttpClient httpclient = new HttpClient();
-        final HttpMethod method = new GetMethod(tinyApi);
-        method.setQueryString(new NameValuePair[]{new NameValuePair("url",url)});
-        httpclient.executeMethod(method);
-        final String tinyUrl = method.getResponseBodyAsString();
-        method.releaseConnection();
-        return tinyUrl;
-    }
-
-    /**
-     * OAuth Public Tweet.
-     * @param socialTwitterAccount
-     * @param tweet
-     * @return
-     * @throws TwitterException
-     */
-    public Status publicTweet(final SocialAccount socialTwitterAccount, final String tweet) throws TwitterException{
-        log.debug("publicTweet "+socialTwitterAccount.getTwitterAccount());
-        //Twitter twitter = new TwitterFactory().getInstance();
-        log.debug("publicTweet Before  Token  {"+socialTwitterAccount.getToken());
-        log.debug("publicTweet Before Secret Token  {"+socialTwitterAccount.getSecretToken());
-        final AccessToken accessToken = this.createNewOAuthAccessToken(socialTwitterAccount);
-        log.debug("Access Token "+accessToken);
-        final Twitter twitter = this.getOAuthAuthorizedInstance(socialTwitterAccount, accessToken);
-        log.debug("Verify  "+twitter.verifyCredentials());
-        log.debug("Update Status "+tweet);
-        return twitter.updateStatus(tweet);
-    }
-
-    /**
-     * Create New OAuth Access Token.
-     * @param socialTwitterAccount {@link SocialAccount}.
-     * @return {@link AccessToken}.
-     */
-    public AccessToken createNewOAuthAccessToken(final SocialAccount socialTwitterAccount){
-         final AccessToken accessToken = new AccessToken(socialTwitterAccount.getToken(), socialTwitterAccount.getSecretToken());
-         return accessToken;
-    }
-
-    /**
-     * Get OAuthorized Token.
-     * @param socialTwitterAccount {@link SocialAccount}.
-     * @return {@link Twitter}.
-     */
-    public Twitter getOAuthAuthorizedInstance(final SocialAccount socialTwitterAccount, final AccessToken accessToken){
-         return new TwitterFactory().getOAuthAuthorizedInstance(socialTwitterAccount.getConsumerKey(),
-                 socialTwitterAccount.getConsumerSecret(),
-                 accessToken);
-    }
-
-    /**
-     * Verify Credentials.
-     * @param username username
-     * @param password password
-     * @return {@link User}
-     * @throws TwitterException exception
-     */
-    @Deprecated
-    public User verifyCredentials(final String username, final String password) throws TwitterException{
-        log.debug("verifyCredentials");
-        final Twitter twitter = new TwitterFactory().getInstance(username, password);
-        return twitter.verifyCredentials();
-    }
-
-    /**
-     * Get Twitter Ping.
-     * @param consumerKey consumer key
-     * @param consumerSecret consumer secret
-     * @return {@link RequestToken}
-     * @throws TwitterException exception
-     */
-    public RequestToken getTwitterPing(String consumerKey, String consumerSecret)
-            throws TwitterException {
-        if (consumerKey == null) {
-            throw new IllegalArgumentException("Consumer key is missing");
-        }
-        if (consumerSecret == null) {
-            throw new IllegalArgumentException("Consumer secret is missing");
-        }
-        final Twitter twitter = new TwitterFactory().getInstance();
-        twitter.setOAuthConsumer(consumerKey, consumerSecret);
-        return twitter.getOAuthRequestToken();
-    }
-
-    /**
-     * @return the tinyApi
-     */
-    public String getTinyApi() {
-        return tinyApi;
-    }
-
-    /**
-     * @param tinyApi the tinyApi to set
-     */
-    public void setTinyApi(final String tinyApi) {
-        this.tinyApi = tinyApi;
-    }
-}

File encuestame-business/src/main/java/org/encuestame/business/service/imp/ILinkedInService.java

+
+package org.encuestame.business.service.imp;
+
+import org.encuestame.core.service.IService;
+
+
+public interface ILinkedInService extends IService {
+
+    public String getAuthorizeLinkedInUrl();
+}

File encuestame-business/src/main/java/org/encuestame/business/service/imp/ISecurityService.java

 
 
     /**
-     * Add new Twitter Account.
-     * @param account account.
-     * @param username
-     * @throws EnMeDomainNotFoundException
-     */
-     void addNewTwitterAccount(final String account, final String username) throws EnMeDomainNotFoundException;
-
-    /**
      * Assing Group to User.
      * @param user user
      * @param group group
 
     /**
      * Update OAuth Token/Secret Social Account.
-     * @param accountId
+     * @param socialAccountId
      * @param token
      * @param tokenSecret
      * @param username
+     * @param account
      * @throws EnMeExpcetion
      */
-    void updateOAuthTokenSocialAccount(final Long accountId, final String token, final String tokenSecret,
-            final String username) throws EnMeExpcetion;
+    public void addOAuthTokenSocialAccount(
+            final Long socialAccountId,
+            final String token,
+            final String tokenSecret,
+            final String username,
+            final UserAccount account) throws EnMeExpcetion;
 
     /**
      * Assign Permission,

File encuestame-business/src/main/java/org/encuestame/business/service/imp/ISurveyService.java

 import java.util.Collection;
 import java.util.List;
 
-import org.encuestame.business.service.TwitterService;
+import org.encuestame.business.service.social.provider.TwitterService;
 import org.encuestame.persistence.domain.Question;
 import org.encuestame.persistence.exception.EnMeDomainNotFoundException;
 import org.encuestame.persistence.exception.EnMeExpcetion;

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/AbstractISocialService.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+import org.encuestame.core.exception.EnMeNoSuchAccountConnectionException;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.exception.EnMeDomainNotFoundException;
+import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.utils.oauth.AuthorizedRequestToken;
+import org.encuestame.utils.oauth.OAuthToken;
+
+/**
+ * Description Class.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 31, 2010 3:34:55 PM
+ * @version Id:
+ */
+public abstract interface AbstractISocialService {
+
+     boolean isConnected(Long id);
+
+        /**
+         * Sever the connection between the member account and this service provider.
+         * Has no effect if no connection is established to begin with.
+         */
+        void disconnect(Long accountId);
+
+
+        //String fetchProviderAccountId(TwitterOperations serviceOperations);
+
+        /**
+         * The key used to identify the local application with the remote service provider.
+         * Used when establishing an account connection with the service provider.
+         * Available as a public property to support client code that wishes to manage the service connection process itself, for example, in JavaScript.
+         * The term "API key" is derived from the OAuth 2 specification.
+         */
+        String getApiKey();
+
+        OAuthToken fetchNewRequestToken(final String callbackUrl);
+
+        String buildAuthorizeUrl(final String requestToken);
+
+        void connect(Long accountId, AuthorizedRequestToken requestToken) throws EnMeExistPreviousConnectionException;
+
+
+        UserAccount findAccountByConnection(String accessToken) throws EnMeDomainNotFoundException;
+
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/AbstractSocialProvider.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+import java.util.List;
+
+import org.apache.commons.logging.LogFactory;
+import org.encuestame.persistence.dao.IAccountDao;
+import org.encuestame.persistence.dao.ISocialProviderDao;
+import org.encuestame.persistence.domain.security.AccountConnection;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.exception.EnMeDomainNotFoundException;
+import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.utils.oauth.AuthorizedRequestToken;
+import org.encuestame.utils.oauth.OAuthToken;
+import org.scribe.extractors.BaseStringExtractorImpl;
+import org.scribe.extractors.HeaderExtractorImpl;
+import org.scribe.extractors.TokenExtractorImpl;
+import org.scribe.model.OAuthConfig;
+import org.scribe.model.Token;
+import org.scribe.model.Verb;
+import org.scribe.model.Verifier;
+import org.scribe.oauth.OAuth10aServiceImpl;
+import org.scribe.oauth.OAuthService;
+import org.scribe.services.HMACSha1SignatureService;
+import org.scribe.services.TimestampServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Abstract Social Provider.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 25, 2010 2:10:36 AM <-- Merry Christmas
+ * @version $Id:$
+ */
+public abstract class AbstractSocialProvider<S> implements SocialProviderOperations<S>{
+
+
+    protected org.apache.commons.logging.Log log = LogFactory.getLog(this.getClass());
+
+    /**
+     * Account Dao.
+     */
+    @Autowired
+    private IAccountDao accountDaoImp;
+
+    /**
+     * Social Provide Dao.
+     */
+    @Autowired
+    private ISocialProviderDao socialProviderDao;
+
+    /**
+     * Get Provider Name.
+     * @return
+     */
+    public String getName() {
+        return getParameters().getName();
+    }
+
+    /**
+     * Get Provider Display Name.
+     * @return
+     */
+    public String getDisplayName() {
+        return getParameters().getName(); //display name, maybe should be a description.
+    }
+
+    /**
+     * Get Provider Api Key.
+     * @return
+     */
+    public String getApiKey() {
+        return getParameters().getApiKey();
+    }
+
+    /**
+     * Get Provider application Id.
+     * @return
+     */
+    public Long getAppId() {
+        return getParameters().getAppId();
+    }
+
+    /**
+     * Get provider parameters.
+     * @return
+     */
+    abstract SocialAccountProvider getParameters();
+
+
+    /**
+     * Set provider parameters.
+     * @param accountProvider provider.
+     * @return
+     */
+    abstract SocialAccountProvider setParameters(final SocialAccountProvider accountProvider);
+
+    /**
+     * Fetch New Request Token.
+     * @param callbackUrl
+     * @return
+     */
+    public OAuthToken fetchNewRequestToken(final String callbackUrl) {
+        final Token requestToken = getOAuthService(callbackUrl).getRequestToken();
+        return new OAuthToken(requestToken.getToken(), requestToken.getSecret());
+    }
+
+    /**
+     * Build Authorize Url.
+     * @param requestToken request token.
+     * @return
+     */
+    public String buildAuthorizeUrl(final String requestToken) {
+        //get authorize url and replace word {token} by request Token
+        return getParameters().getAuthorizeUrl().replace("{token}", requestToken);
+    }
+
+    /**
+     * Add new Connection, UserAccount <--> Social Provider Account.
+     * @throws EnMeExistPreviousConnectionException
+     */
+    public void connect(Long accountId, AuthorizedRequestToken requestToken) throws EnMeExistPreviousConnectionException {
+        final OAuthToken accessToken = getAccessToken(requestToken);
+        S serviceOperations = createServiceOperations(accessToken);
+        //find
+        String providerAccountId = fetchProviderAccountId(serviceOperations);
+        try {
+            final AccountConnection s = this.findAccountConnection(accessToken.getValue());
+            if (s != null) {
+                log.debug("adding new connection");
+                this.accountDaoImp.addConnection(
+                        getName(),
+                        accessToken,
+                        providerAccountId,
+                        accountId,
+                        buildProviderProfileUrl(providerAccountId, serviceOperations));
+            } else {
+                log.info("There is already a connection created");
+                throw new EnMeExistPreviousConnectionException("There is already a connection created");
+            }
+        } catch (EnMeDomainNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Records an existing connection between a user account and this service provider.
+     * Use when the connection process happens outside of the control of this package; for example, in JavaScript.
+     * @param accountId the member account identifier
+     * @param accessToken the access token that was granted as a result of the connection
+     * @param providerAccountId the id of the user in the provider's system; may be an assigned number or a user-selected screen name.
+     */
+    public void addConnection(Long accountId, String accessToken, String providerAccountId) {
+        OAuthToken oauthAccessToken = new OAuthToken(accessToken);
+        S serviceOperations = createServiceOperations(oauthAccessToken);
+        this.accountDaoImp.addConnection(getName(), oauthAccessToken, providerAccountId, accountId,
+                buildProviderProfileUrl(providerAccountId, serviceOperations));
+    }
+
+    /**
+     * Returns true if the user account is connected to this provider, false otherwise.
+     */
+    public boolean isConnected(Long accountId) {
+            return this.accountDaoImp.isConnected(accountId, getName());
+    }
+
+    /**
+     * Return if user account have previous account connection.
+     * @param accessToken
+     * @return
+     */
+    public boolean isConnected(final String accessToken){
+        boolean conected = false;
+        try {
+            if(this.findAccountByConnection(accessToken) != null){
+                conected = true;
+            }
+        } catch (EnMeExpcetion e) {
+            log.error("isConected error :"+e);
+        }
+        return conected;
+    }
+
+    /**
+     * Sever the connection between the member account and this service provider.
+     * Has no effect if no connection is established to begin with.
+     */
+    public void disconnect(Long accountId) {
+            try {
+                this.accountDaoImp.disconnect(accountId, getName());
+            } catch (EnMeDomainNotFoundException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+    }
+
+    /**
+     * Gets a handle to the API offered by this service provider.
+     * This API may be used by the application to invoke the service on behalf of a member.
+     * @param accountId the member account identifier (may be null, if so, only operations that require no authorization may be invoked)
+     * @throws EnMeDomainNotFoundException
+     */
+    @Transactional
+    public S getServiceOperations(Long accountId) throws EnMeDomainNotFoundException {
+        if (accountId == null || !isConnected(accountId)) {
+            return getServiceOperations(null);
+        }
+        OAuthToken accessToken = this.accountDaoImp.getAccessToken(accountId, getName());
+        return createServiceOperations(accessToken);
+    }
+
+    /**
+     * Find possible open provider account connections.
+     * @param accessToken
+     * @return
+     * @throws EnMeDomainNotFoundException
+     */
+    public UserAccount findAccountByConnection(String accessToken) throws EnMeDomainNotFoundException {
+        return this.accountDaoImp.findAccountByConnection(this.getName(), accessToken);
+    }
+
+    /**
+     *
+     * @param accessToken
+     * @return
+     * @throws EnMeDomainNotFoundException
+     */
+    public AccountConnection findAccountConnection(String accessToken) throws EnMeDomainNotFoundException {
+        return this.accountDaoImp.findAccountConnectionByAccessToken(this.getName(), accessToken);
+    }
+
+    //This method should retrieve list of user accounts connected with this provider.
+    //public List<ProfileReference> findUserAccountsConnectedTo(List<String> providerAccountIds) {
+      // getName(),
+      // providerAccountIds;
+    //}
+
+    /**
+     * Construct the strongly-typed service API template that callers may use to invoke the service offered by this service provider.
+     * Subclasses should override to return their concrete service implementation.
+     * @param accessToken the granted access token needed to make authorized requests for protected resources
+     */
+
+    protected abstract S createServiceOperations(OAuthToken accessToken);
+
+    /**
+     * Use the service API to fetch the id the member has been assigned in the provider's system.
+     * This id is stored locally to support linking to the user's connected profile page.
+     * It is also used for finding connected friends, see {@link #findMembersConnectedTo(List)}.
+     */
+    protected abstract String fetchProviderAccountId(S serviceOperations);
+
+    /**
+     * Build the URL pointing to the member's public profile on the provider's system.
+     * @param providerAccountId the id the member is known by in the provider's system.
+     * @param serviceOperations the service API
+     */
+    protected abstract String buildProviderProfileUrl(String providerAccountId, S serviceOperations);
+
+    /**
+     * The {@link #getApiKey() apiKey} secret.
+     */
+    protected String getSecret() {
+        return getParameters().getSecret();
+    }
+
+    // internal helpers
+
+    private OAuthService getOAuthService() {
+        return getOAuthService(null);
+    }
+
+    /**
+     * Get OAuth Service.
+     * @param callbackUrl
+     * @return
+     */
+    private OAuthService getOAuthService(String callbackUrl) {
+        log.debug("get getOAuthService "+callbackUrl);
+        OAuthConfig config = new OAuthConfig();
+        config.setRequestTokenEndpoint(getParameters().getRequestTokenUrl());
+        config.setAccessTokenEndpoint(getParameters().getAccessTokenUrl());
+        config.setAccessTokenVerb(Verb.POST);
+        config.setRequestTokenVerb(Verb.POST);
+        config.setApiKey(getParameters().getApiKey());
+        config.setApiSecret(getParameters().getSecret());
+        if (callbackUrl != null) {
+            log.debug("Setting callback url "+callbackUrl);
+            config.setCallback(callbackUrl);
+        }
+        //return new OAuth.
+        return new OAuth10aServiceImpl(new HMACSha1SignatureService(),
+                new TimestampServiceImpl(),
+                new BaseStringExtractorImpl(),
+                new HeaderExtractorImpl(),
+                new TokenExtractorImpl(),
+                new TokenExtractorImpl(),
+                config);
+    }
+
+    /**
+     * Get Access Token.
+     * @param requestToken
+     * @return
+     */
+    private OAuthToken getAccessToken(final AuthorizedRequestToken requestToken) {
+        Token accessToken = getOAuthService().getAccessToken(new Token(requestToken.getValue(),
+                            requestToken.getSecret()),
+                            new Verifier(requestToken.getVerifier()));
+        return new OAuthToken(accessToken.getToken(), accessToken.getSecret());
+    }
+
+    /**
+     * @return the accountDaoImp
+     */
+    public IAccountDao getAccountDaoImp() {
+        return accountDaoImp;
+    }
+
+    /**
+     * @param accountDaoImp the accountDaoImp to set
+     */
+    public void setAccountDaoImp(final IAccountDao accountDaoImp) {
+        this.accountDaoImp = accountDaoImp;
+    }
+
+    /**
+     * @return the socialProviderDao
+     */
+    public ISocialProviderDao getSocialProviderDao() {
+        return socialProviderDao;
+    }
+
+    /**
+     * @param socialProviderDao the socialProviderDao to set
+     */
+    public void setSocialProviderDao(final ISocialProviderDao socialProviderDao) {
+        this.socialProviderDao = socialProviderDao;
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/EnMeExistPreviousConnectionException.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+import org.encuestame.persistence.exception.EnMeExpcetion;
+
+/**
+ * Previous Provider Connection.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 30, 2010 8:29:18 PM
+ * @version $Id:$
+ */
+public class EnMeExistPreviousConnectionException extends EnMeExpcetion{
+
+    /**
+     * Constructor.
+     * @param message
+     */
+    public EnMeExistPreviousConnectionException(final String message) {
+        super(message);
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/FacebookSocialService.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+import org.encuestame.utils.oauth.OAuthToken;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.social.facebook.FacebookApi;
+import org.springframework.social.facebook.FacebookTemplate;
+import org.springframework.social.twitter.TwitterTemplate;
+
+/**
+ * Facebook. Social Service.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 25, 2010 5:57:35 PM
+ * @version $Id:$
+ */
+public class FacebookSocialService extends AbstractSocialProvider<FacebookApi> implements IFacebookSocialService{
+
+
+    /**
+     * Social Account Provider;
+     */
+    private SocialAccountProvider parameters = new SocialAccountProvider();
+
+    /**
+     * Twitter Template.
+     */
+    private FacebookTemplate facebookTemplate;
+
+    /**
+     * Consumer Key.
+     */
+    public @Value("${facebook.api.id}") Long apiId;
+
+    /**
+     * Consumer Secret.
+     */
+    public @Value("${facebook.api.secret}") String secret;
+
+    /**
+     * Authorize Url.
+     */
+    public @Value("${facebook.api.key}") String key;
+
+
+    /**
+     *
+     * @param socialProviderName
+     */
+    public FacebookSocialService() {
+        this.loadParameters();
+    }
+
+    /**
+     * Load Parameters.
+     */
+    private void loadParameters(){
+        this.parameters.setAppId(this.apiId);
+        this.parameters.setApiKey(this.key);
+        this.parameters.setSecret(this.secret);
+    }
+
+    @Override
+    protected FacebookApi createServiceOperations(OAuthToken accessToken) {
+        if (accessToken == null) {
+            throw new IllegalStateException("Cannot access Facebook without an access token");
+        }
+        return new FacebookTemplate(accessToken.getValue());
+    }
+
+    @Override
+    protected String fetchProviderAccountId(FacebookApi serviceOperations) {
+      return serviceOperations.getProfileId();
+    }
+
+    @Override
+    protected String buildProviderProfileUrl(String providerAccountId,
+            FacebookApi serviceOperations) {
+        return "http://www.facebook.com/profile.php?id=" + providerAccountId;
+    }
+
+    @Override
+    SocialAccountProvider getParameters() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    SocialAccountProvider setParameters(SocialAccountProvider accountProvider) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/IFacebookSocialService.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+/**
+ * Description Class.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 31, 2010 3:34:35 PM
+ * @version Id:
+ */
+public interface IFacebookSocialService extends AbstractISocialService {
+
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/ILinkedInSocialProvider.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+import org.springframework.social.linkedin.LinkedInOperations;
+import org.springframework.social.twitter.TwitterOperations;
+
+
+/**
+ * Interface for Twitter Service Provider Implementation.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 30, 2010 11:22:51 PM
+ * @version $Id:$
+ */
+public interface ILinkedInSocialProvider extends AbstractISocialService {
+
+    String fetchProviderAccountId(LinkedInOperations serviceOperations);
+
+
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/ITwitterSocialProvider.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+
+/**
+ * Interface for Twitter Service Provider Implementation.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 30, 2010 11:22:51 PM
+ * @version $Id:$
+ */
+public interface ITwitterSocialProvider extends AbstractISocialService {
+
+
+
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/LinkedInSocialService.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+import org.encuestame.utils.oauth.OAuthToken;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.social.linkedin.LinkedInApi;
+import org.springframework.social.linkedin.LinkedInApi;
+import org.springframework.social.linkedin.LinkedInTemplate;
+
+/**
+ * LinkedIn Social Service.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 25, 2010 5:57:35 PM
+ * @version $Id:$
+ */
+public class LinkedInSocialService extends AbstractSocialProvider<LinkedInApi>{
+
+    /**
+     * Social Account Provider;
+     */
+    private SocialAccountProvider parameters = new SocialAccountProvider();
+
+    /**
+     * Twitter Template.
+     */
+    private LinkedInTemplate linkedInTemplate;
+
+    /**
+     * Consumer Key.
+     */
+    public @Value("${linkedIn.oauth.api.key}") String apiKey;
+
+    /**
+     * Consumer Secret.
+     */
+    public @Value("${linkedIn.oauth.api.secret}") String consumerSecret;
+
+    /**
+     * Authorize Url.
+     */
+    public @Value("${linkedIn.oauth.authorize.url}") String authorizeUrl;
+
+    /**
+     * Request Token Url.
+     */
+    public @Value("${linkedIn.oauth.request.token}") String requestTokenUrl;
+
+    /**
+     *
+     * @param socialProviderName
+     */
+    public LinkedInSocialService() {
+       this.loadParameters();
+    }
+
+    @Override
+    protected LinkedInApi createServiceOperations(OAuthToken accessToken) {
+        log.debug("Twitter Operations createServiceOperations "+accessToken.toString());
+        if(this.linkedInTemplate == null){
+            log.debug("Creando Provider");
+            this.createLinkedInTemplate(accessToken);
+        }
+        return this.linkedInTemplate;
+    }
+
+    /**
+     * Create Twitter Template.
+     * @param accessToken
+     */
+    private void createLinkedInTemplate(final OAuthToken accessToken){
+        if (accessToken == null) {
+            throw new IllegalStateException("Cannot access LinkedIn without an access token");
+        }
+        this.linkedInTemplate = new LinkedInTemplate(getApiKey(), getSecret(), accessToken.getValue(), accessToken.getSecret());
+
+    }
+
+    /**
+     * Fetch Provider Account Id.
+     */
+    @Override
+    public String fetchProviderAccountId(LinkedInApi serviceOperations) {
+      log.debug("MEAN fetchNewRequestToken "+serviceOperations.getProfileId());
+      return serviceOperations.getProfileId();
+    }
+
+    /**
+     * Build Provider Profile Url.
+     */
+    @Override
+    protected String buildProviderProfileUrl(String providerAccountId,
+            LinkedInApi serviceOperations) {
+        return "url-" + providerAccountId;
+    }
+
+    /**
+     * Load Parameters.
+     */
+    private void loadParameters(){
+        this.parameters.setApiKey(this.apiKey);
+        this.parameters.setSecret(this.consumerSecret);
+        this.parameters.setAuthorizeUrl(this.authorizeUrl);
+        this.parameters.setRequestTokenUrl(this.requestTokenUrl);
+    }
+
+    /**
+     * Get Parameters.
+     */
+    @Override
+    SocialAccountProvider getParameters() {
+        log.error("getParameters ");
+        if(this.parameters == null){
+             log.info("loadParameters");
+            this.loadParameters();
+        } else {
+            log.debug("Parametros encontrados");
+        }
+        return this.parameters;
+    }
+
+    /**
+     * Set Parameters.
+     */
+    @Override
+    SocialAccountProvider setParameters(final SocialAccountProvider accountProvider) {
+        log.error("No getParameters "+accountProvider);
+        this.parameters = accountProvider;
+        return this.parameters;
+    }
+
+    /**
+     * @return the consumerKey
+     */
+    public String getConsumerKey() {
+        return apiKey;
+    }
+
+    /**
+     * @param consumerKey the consumerKey to set
+     */
+    public void setConsumerKey(String consumerKey) {
+        this.apiKey = consumerKey;
+    }
+
+    /**
+     * @return the consumerSecret
+     */
+    public String getConsumerSecret() {
+        return consumerSecret;
+    }
+
+    /**
+     * @param consumerSecret the consumerSecret to set
+     */
+    public void setConsumerSecret(String consumerSecret) {
+        this.consumerSecret = consumerSecret;
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/NoSocialAccountConnectionException.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.business.service.social.connect;
+
+import org.encuestame.persistence.exception.EnMeExpcetion;
+
+/**
+ * No Sicual Account Connection Exception.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 25, 2010 2:19:06 AM
+ * @version Id:
+ */
+public class NoSocialAccountConnectionException extends EnMeExpcetion{
+
+    private String accessToken;
+
+    public NoSocialAccountConnectionException(final String accessToken) {
+        super("invalid access token");
+    }
+
+    /**
+     * @return the accessToken
+     */
+    public String getAccessToken() {
+        return accessToken;
+    }
+
+
+}

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/SocialAccountProvider.java

+
+package org.encuestame.business.service.social.connect;
+
+/**
+ * Social Account Provider.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Feb 20, 2011 10:45:15 PM
+ */
+public class SocialAccountProvider {
+
+    private String name;
+
+    private String apiKey;
+
+    private String secret;
+
+    private Long appId;
+
+    private String requestTokenUrl;
+
+    private String authorizeUrl;
+
+    private String accessTokenUrl;
+
+    /**
+     * Constructor.
+     */
+    public SocialAccountProvider() {}
+
+    /**