1. Juan Carlos Picado Herrera
  2. encuestame

Commits

Juan Carlos Picado Herrera  committed d5ba88b
  • Participants
  • Parent commits 6f3a483
  • Branches master

Comments (0)

Files changed (12)

File enme-business/src/main/java/org/encuestame/business/service/AbstractSurveyService.java

View file
  • Ignore whitespace
 import org.encuestame.core.security.util.WidgetUtil;
 import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.core.util.InternetUtils;
-import org.encuestame.core.util.SocialUtils;
 import org.encuestame.persistence.dao.IHashTagDao;
 import org.encuestame.persistence.dao.ITweetPoll;
 import org.encuestame.persistence.domain.HashTag;
 import org.encuestame.persistence.domain.tweetpoll.TweetPollSwitch;
 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
-import org.encuestame.persistence.exception.EnmeFailOperation;
 import org.encuestame.social.api.FacebookAPITemplate;
 import org.encuestame.social.api.GoogleBuzzAPITemplate;
 import org.encuestame.social.api.IdenticaAPITemplate;
 import org.encuestame.utils.MD5Utils;
 import org.encuestame.utils.PictureUtils;
 import org.encuestame.utils.RestFullUtil;
-import org.encuestame.utils.ShortUrlProvider;
 import org.encuestame.utils.TweetPublishedMetadata;
 import org.encuestame.utils.enums.QuestionPattern;
 import org.encuestame.utils.json.QuestionBean;

File enme-core/src/main/java/org/encuestame/core/service/SecurityService.java

View file
  • Ignore whitespace
                 socialProvider, userAccount);
     }
 
-    /**
-     *
-     * @param socialProvider
-     * @param socialAccountId
-     * @return
+    /*
+     * (non-Javadoc)
+     * @see org.encuestame.core.service.imp.SecurityOperations#getCurrentSocialAccount(org.encuestame.utils.social.SocialProvider, java.lang.String)
      */
     public SocialAccount getCurrentSocialAccount(final SocialProvider socialProvider, final String socialProfileId){
         return getAccountDao().getSocialAccount(socialProvider, socialProfileId);
     }
 
+    /*
+     * (non-Javadoc)
+     * @see org.encuestame.core.service.imp.SecurityOperations#getCurrentSocialAccount(org.encuestame.utils.social.SocialProvider, java.lang.String, java.lang.String)
+     */
+    public SocialAccount getCurrentSocialAccount(final SocialProvider socialProvider, final String socialProfileId, final String socialUserName) {
+        return getAccountDao().getSocialAccount(socialProvider, socialProfileId, socialUserName);
+    }
+
     /**
      * Get User Logged Scocial Accounts.
      * @param username

File enme-core/src/main/java/org/encuestame/core/service/imp/SecurityOperations.java

View file
  • Ignore whitespace
      */
     SocialAccount getCurrentSocialAccount(final SocialProvider socialProvider, final String socialProfileId);
 
+
+    /**
+     * Check if exist {@link SocialAccount} with unique social profile social id.
+     * @param socialProvider
+     * @param socialAccountId
+     * @param socialUserName
+     * @return
+     */
+    SocialAccount getCurrentSocialAccount(final SocialProvider socialProvider, final String socialProfileId, final String socialUserName);
+
     /**
      * Update OAuth Token/Secret Social Account.
      * @param socialAccountId

File enme-css/src/css/resource/css/web/default.css

View file
  • Ignore whitespace
 .mainError {
   background-color: #F4A1A1;
   color: #FEFEFE;
-  font-size: 125%;
+  font-size: 120%;
   margin-top: 15px;
-  padding: 15px;
+  padding: 10px;
   -webkit-box-shadow: 3px 3px 7px rgba(50, 50, 48, 0.7);
   -moz-box-shadow:    3px 3px 7px rgba(50, 50, 48, 0.7);
    box-shadow:         3px 3px 7px rgba(50, 50, 48, 0.7);

File enme-mvc/src/main/java/org/encuestame/mvc/controller/social/AbstractAccountConnect.java

View file
  • Ignore whitespace
                 LinkedInProfile profile = apiOperations.getUserProfile();
                 SocialUserProfile profileAPI = apiOperations.getProfile();
                 log.debug("linkedin profile "+profile.toString());
-                final SocialAccount socialAccount = getSecurityService().getCurrentSocialAccount(socialProvider,
-                        profile.getId());
+                final SocialAccount socialAccount = getSecurityService().getCurrentSocialAccount(socialProvider, profile.getId());
                 if (socialAccount == null) {
                     getSecurityService().addNewSocialAccount(
                             accessToken.getValue(), accessToken.getSecret(), null, profileAPI,
                         accessToken.getSecret());
                 SocialUserProfile profile = operations.getProfile();
                 log.debug("twitter profile "+profile.toString());
-                final SocialAccount socialAccount = getSecurityService().getCurrentSocialAccount(socialProvider,
-                        profile.getId());
+                final SocialAccount socialAccount = getSecurityService().getCurrentSocialAccount(socialProvider, profile.getId());
                 if (socialAccount == null) {
                     getSecurityService().addNewSocialAccount(
                             accessToken.getValue(), accessToken.getSecret(), null, profile,
     }
 
     /**
-     *
-     * @param socialProvider
-     * @param accessGrant
+     * Check and save a social account if exist previously.
+     * @param socialProvider {@link SocialProvider}
+     * @param accessGrant {@link AccessGrant}
      * @return
-     * @throws Exception
+     * @throws Exception if the social account exist, throw a exception
      */
     public String checkOAuth2SocialAccount(final SocialProvider socialProvider,
             final AccessGrant accessGrant) throws Exception {
         String actionToDo = "";
         if (socialProvider.equals(SocialProvider.FACEBOOK)) {
             final FacebookAPIOperations facebookAPIOperations = new FacebookAPITemplate(accessGrant.getAccessToken());
-            getSecurityService().addNewSocialAccount(
-                    accessGrant.getAccessToken(), accessGrant.getRefreshToken(), accessGrant.getExpires(),
-                    facebookAPIOperations.getProfile(),
-                    socialProvider, getUserAccount());
-        } else if (socialProvider.equals(SocialProvider.GOOGLE_BUZZ)) {
-            final BuzzAPIOperations apiOperations = new GoogleBuzzAPITemplate(accessGrant.getAccessToken(), this.apiKey);
-            log.debug(apiOperations.getProfile());
-            getSecurityService().addNewSocialAccount(
-                    accessGrant.getAccessToken(), accessGrant.getRefreshToken(), accessGrant.getExpires(),
-                    apiOperations.getProfile(),
-                    socialProvider, getUserAccount());
+            final SocialAccount socialAccount = getSecurityService().getCurrentSocialAccount(socialProvider, facebookAPIOperations.getProfile().getId(), facebookAPIOperations.getProfile().getUsername());
+            if (socialAccount == null) {
+                  getSecurityService().addNewSocialAccount(
+                          accessGrant.getAccessToken(), accessGrant.getRefreshToken(), accessGrant.getExpires(),
+                          facebookAPIOperations.getProfile(),
+                          socialProvider, getUserAccount());
+            } else {
+                log.warn("This account already exist");
+                throw new EnMeExistPreviousConnectionException(getMessage("social.repeated.account"));
+            }
+
         }
+
+        //    else if (socialProvider.equals(SocialProvider.GOOGLE_BUZZ)) {
+        //            final BuzzAPIOperations apiOperations = new GoogleBuzzAPITemplate(accessGrant.getAccessToken(), this.apiKey);
+        //            log.debug(apiOperations.getProfile());
+        //            getSecurityService().addNewSocialAccount(
+        //                    accessGrant.getAccessToken(), accessGrant.getRefreshToken(), accessGrant.getExpires(),
+        //                    apiOperations.getProfile(),
+        //                    socialProvider, getUserAccount());
+        //        }
         return actionToDo;
     }
 }

File enme-mvc/src/main/java/org/encuestame/mvc/controller/social/FacebookConnectSocialAccount.java

View file
  • Ignore whitespace
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.log4j.Logger;
+import org.encuestame.core.exception.EnMeExistPreviousConnectionException;
+import org.encuestame.core.filter.RequestSessionMap;
 import org.encuestame.core.util.SocialUtils;
+import org.encuestame.persistence.exception.EnMeOAuthSecurityException;
 import org.encuestame.utils.oauth.AccessGrant;
 import org.encuestame.utils.social.SocialProvider;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
+import org.springframework.util.Assert;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
             @RequestParam(value = "code", required = true) String code,
             HttpServletRequest httpRequest,
             WebRequest request) throws Exception {
-        final AccessGrant accessGrant = auth2RequestProvider.getAccessGrant(code, httpRequest);
-        log.debug(accessGrant.getAccessToken());
-        log.debug(accessGrant.getRefreshToken());
-        checkOAuth2SocialAccount(SocialProvider.FACEBOOK, accessGrant);
-        return this.redirect+"#provider="+SocialProvider.FACEBOOK.toString().toLowerCase()+"&refresh=true&successful=true";
+        try {
+             final AccessGrant accessGrant = auth2RequestProvider.getAccessGrant(code, httpRequest);
+             log.debug(accessGrant.getAccessToken());
+             log.debug(accessGrant.getRefreshToken());
+             checkOAuth2SocialAccount(SocialProvider.FACEBOOK, accessGrant);
+        } catch (EnMeOAuthSecurityException e1) {
+            RequestSessionMap.setErrorMessage(getMessage("errorOauth", httpRequest, null));
+        } catch (EnMeExistPreviousConnectionException e1) {
+            RequestSessionMap.setErrorMessage(getMessage("social.repeated.account", httpRequest, null));
+        } catch (Exception e) {
+            RequestSessionMap.setErrorMessage(getMessage("errorOauth", httpRequest, null));
+        }
+        return this.redirect + "#provider=" + SocialProvider.FACEBOOK.toString().toLowerCase() + "&refresh=true&successful=true";
     }
 
     /**
             WebRequest request) throws Exception {
         log.error("ERROR error_code" + error_code);
         log.error("ERROR error_msg" + error_msg);
-        final SocialProvider soProvider = SocialProvider.getProvider("socialProvider");
+        log.error("ERROR socialProvider" + socialProvider);
+        final SocialProvider soProvider = SocialProvider.getProvider(socialProvider);
         return this.redirect+"#provider=" + soProvider.toString().toLowerCase() + "&refresh=true&successful=false";
     }
 }

File enme-mvc/src/main/java/org/encuestame/mvc/controller/social/IdenticaConnectSocialAccount.java

View file
  • Ignore whitespace
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.log4j.Logger;
+import org.encuestame.core.exception.EnMeExistPreviousConnectionException;
 import org.encuestame.core.filter.RequestSessionMap;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.exception.EnMeOAuthSecurityException;
+import org.encuestame.utils.oauth.AccessGrant;
 import org.encuestame.utils.oauth.OAuth1Token;
 import org.encuestame.utils.social.SocialProvider;
 import org.springframework.beans.factory.annotation.Value;
     public String oauth1Callback(
             @RequestParam("oauth_token") String token,
             @RequestParam(value = "oauth_verifier", required = false) String verifier,
+            HttpServletRequest httpRequest,
             WebRequest request,
             final UserAccount account) throws Exception {
-        final OAuth1Token accessToken = auth1RequestProvider.getAccessToken(verifier, request);
-        log.debug("OAUTH 1 ACCESS TOKEN " + accessToken.toString());
-        this.checkOAuth1SocialAccount(SocialProvider.IDENTICA, accessToken);
+        try {
+             final OAuth1Token accessToken = auth1RequestProvider.getAccessToken(verifier, request);
+             log.debug("OAUTH 1 ACCESS TOKEN " + accessToken.toString());
+             this.checkOAuth1SocialAccount(SocialProvider.IDENTICA, accessToken);
+        } catch (EnMeOAuthSecurityException e1) {
+               RequestSessionMap.setErrorMessage(getMessage("errorOauth", httpRequest, null));
+        } catch (EnMeExistPreviousConnectionException e1) {
+               RequestSessionMap.setErrorMessage(getMessage("social.repeated.account", httpRequest, null));
+        } catch (Exception e) {
+               RequestSessionMap.setErrorMessage(getMessage("errorOauth", httpRequest, null));
+        }
         return this.redirect+"#provider="+SocialProvider.IDENTICA.toString().toLowerCase()+"&refresh=true&successful=true";
     }
 }

File enme-mvc/src/main/java/org/encuestame/mvc/controller/social/LinkedInConnectSocialAccount.java

View file
  • Ignore whitespace
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.log4j.Logger;
+import org.encuestame.core.exception.EnMeExistPreviousConnectionException;
+import org.encuestame.core.filter.RequestSessionMap;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.exception.EnMeOAuthSecurityException;
 import org.encuestame.utils.oauth.OAuth1Token;
 import org.encuestame.utils.social.SocialProvider;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
+import org.springframework.util.Assert;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
     public String oauth1Callback(
             @RequestParam("oauth_token") String token,
             @RequestParam(value = "oauth_verifier", required = false) String verifier,
+            HttpServletRequest httpRequest,
             WebRequest request, final UserAccount account) throws Exception {
-         final OAuth1Token accessToken = auth1RequestProvider.getAccessToken(verifier, request);
-         this.checkOAuth1SocialAccount(SocialProvider.LINKEDIN, accessToken);
+         try {
+             final OAuth1Token accessToken = auth1RequestProvider.getAccessToken(verifier, request);
+             this.checkOAuth1SocialAccount(SocialProvider.LINKEDIN, accessToken);
+             log.debug("OAUTH 1 ACCESS TOKEN:{ " + accessToken.toString());
+             this.checkOAuth1SocialAccount(SocialProvider.TWITTER, accessToken);
+         } catch (EnMeOAuthSecurityException e1) {
+             e1.printStackTrace();
+             RequestSessionMap.setErrorMessage(getMessage("errorOauth", httpRequest, null));
+         } catch (EnMeExistPreviousConnectionException e1) {
+             e1.printStackTrace();
+             RequestSessionMap.setErrorMessage(getMessage("social.repeated.account", httpRequest, null));
+         } catch (Exception e) {
+             e.printStackTrace();
+             RequestSessionMap.setErrorMessage(getMessage("errorOauth", httpRequest, null));
+         }
          return this.redirect+"#provider="+SocialProvider.LINKEDIN.toString().toLowerCase()+"&refresh=true&successful=true";
     }
 }

File enme-persistence/enme-dao/src/main/java/org/encuestame/persistence/dao/IAccountDao.java

View file
  • Ignore whitespace
      */
     SocialAccount getSocialAccount(final SocialProvider socialProvider, final String socialAccountId);
 
+
+    /**
+     * Return a {@link SocialAccount} by {@link SocialProvider} and social profile id (unique) and social user name.
+     * @param socialProvider
+     * @param socialProfileId
+     * @param socialUsername
+     * @return
+     */
+    SocialAccount getSocialAccount(
+            final SocialProvider socialProvider,
+            final String socialProfileId,
+            final String socialUsername);
+
     /**
      * Get Social Account.
      * @param socialAccountId

File enme-persistence/enme-dao/src/main/java/org/encuestame/persistence/dao/imp/AbstractSocialAccount.java

View file
  • Ignore whitespace
  * @author Picado, Juan juanATencuestame.org
  * @since Jun 30, 2011
  */
-public abstract class AbstractSocialAccount extends AbstractHibernateDaoSupport{
+public abstract class AbstractSocialAccount extends AbstractHibernateDaoSupport {
 
     /**
      * Return a {@link SocialAccount} by account Id.
     @SuppressWarnings("unchecked")
     public final SocialAccount getSocialAccount(
             final SocialProvider socialProvider,
-            final String socialProfileId){
+            final String socialProfileId) {
         final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
         criteria.add(Restrictions.eq("accounType", socialProvider));
         criteria.add(Restrictions.eq("socialProfileId", socialProfileId));
     }
 
     /**
+     * Return a {@link SocialAccount} by {@link SocialProvider} and social profile id (unique) and social user name.
+     * @param socialProvider
+     * @param socialProfileId
+     * @param socialUsername
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public final SocialAccount getSocialAccount(
+            final SocialProvider socialProvider,
+            final String socialProfileId,
+            final String socialUsername) {
+        final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
+        criteria.add(Restrictions.eq("accounType", socialProvider));
+        criteria.add(Restrictions.eq("socialProfileId", socialProfileId));
+        criteria.add(Restrictions.eq("socialAccountName", socialUsername));
+        return (SocialAccount) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
+    }
+
+    /**
      * Return a {@link SocialAccount} by id and {@link Account}.
      * @param socialAccountId
      * @param account
     @SuppressWarnings("unchecked")
     public final SocialAccount getSocialAccount(
             final Long socialAccountId,
-            final Account account){
+            final Account account) {
         final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
         criteria.add(Restrictions.eq("account", account));
         criteria.add(Restrictions.eq("id", socialAccountId));

File enme-persistence/enme-dao/src/main/java/org/encuestame/persistence/dao/imp/AccountDaoImp.java

View file
  • Ignore whitespace
          final List list =  getHibernateTemplate().findByNamedParam("select count(*) from UserAccount "
                  +" WHERE account = :account", "account", account);
          if (list.get(0) instanceof Long){
-             log.trace("instace of Long");
+             log.debug("instace of Long");
              resultsSize = (Long) list.get(0);
          }
          return resultsSize;
      */
     //@Cacheable(cacheName = "userByUsername")
     public final UserAccount getUserByUsername(final String username)throws HibernateException {
-        log.trace("getUserByUsername by :{"+username);
+        log.debug("getUserByUsername by :{"+username);
         final DetachedCriteria criteria = DetachedCriteria.forClass(UserAccount.class);
         criteria.add(Restrictions.eq("username", username));
         getHibernateTemplate().setQueryCacheRegion("query.user.by.username");

File enme-persistence/enme-model/src/main/java/org/encuestame/persistence/domain/security/SocialAccount.java

View file
  • Ignore whitespace
      * @return the twitterAccount
      */
     @Field(index = Index.TOKENIZED, store = Store.YES)
-    @Column (name="social_account_name", nullable = false, unique=true)
+    @Column (name="social_account_name", nullable = false, unique = false)
     public String getSocialAccountName() {
         return socialAccountName;
     }