Commits

Juan Carlos Picado Herrera  committed 06c8141

Twitter Signin Account. (Alfa mode)

git-svn-id: http://svn.encuesta.me/trunk/encuestame@99539e2479b-dd58-4041-9f67-69c9b71f0610

  • Participants
  • Parent commits 1b29423

Comments (0)

Files changed (40)

File encuestame-business/src/main/java/org/encuestame/business/security/filter/VerifyAuthenticationFilter.java

 
     protected  String loginUrl = "/user/signin";
 
-    protected  String redirectUrl = "/dashboard.html";
+    protected  String redirectUrl = "/account/dashboard";
 
     /**
      * Do Filter.

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

  * @see OAuthSessionManagerProviderTokenServices
  */
 @SuppressWarnings("serial")
-class AppConnectionProviderToken implements OAuthAccessProviderToken {
+public class AppConnectionProviderToken implements OAuthAccessProviderToken {
 
     /** Log. **/
     protected Log log = LogFactory.getLog(this.getClass());

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

 import org.encuestame.persistence.domain.application.ApplicationConnection;
 import org.encuestame.persistence.exception.EnMeNotValidKeyOAuthSecurityException;
 import org.encuestame.persistence.utils.SecureRandomStringKeyGenerator;
+import org.encuestame.utils.oauth.OAuthSession;
+import org.encuestame.utils.oauth.StandardOAuthSession;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.google.common.collect.MapMaker;
 /**
      */
     public OAuthSession newOAuthSession(String apiKey, String callbackUrl) {
         final StandardOAuthSession session = new StandardOAuthSession(apiKey, callbackUrl, keyGenerator.generateKey(), keyGenerator.generateKey());
-        log.debug("New OAuth StandardOAuthSession"+session.apiKey);
-        log.debug("New OAuth StandardOAuthSession"+session.secret);
-        log.debug("New OAuth StandardOAuthSession"+session.verifier);
-        log.debug("New OAuth StandardOAuthSession"+session.callbackUrl);
+        log.debug("New OAuth StandardOAuthSession"+session.getApiKey());
+        log.debug("New OAuth StandardOAuthSession"+session.getSecret());
+        log.debug("New OAuth StandardOAuthSession"+session.getVerifier());
+        log.debug("New OAuth StandardOAuthSession"+session.getCallbackUrl());
         sessions.put(session.getRequestToken(), session);
         return session;
     }
     public void setApplicationDao(ApplicationDao applicationDao) {
         this.applicationDao = applicationDao;
     }
-
-
-    /**
-     * Describe Standard OAuth Session.
-     * Description Class.
-     * @author Picado, Juan juanATencuestame.org
-     * @since Dec 24, 2010 3:53:13 PM
-     * @version $Id:$
-     */
-    private static class StandardOAuthSession implements OAuthSession {
-
-        private String apiKey;
-
-        private String callbackUrl;
-
-        private String requestToken;
-
-        private String secret;
-
-        private Long authorizingAccountId;
-
-        private String verifier;
-
-        public StandardOAuthSession(String apiKey, String callbackUrl, String requestToken, String secret) {
-            this.apiKey = apiKey;
-            this.callbackUrl = callbackUrl;
-            this.requestToken = requestToken;
-            this.secret = secret;
-        }
-
-        public String getApiKey() {
-            return apiKey;
-        }
-
-        public String getCallbackUrl() {
-            return callbackUrl;
-        }
-
-        public String getRequestToken() {
-            return requestToken;
-        }
-
-        public String getSecret() {
-            return secret;
-        }
-
-        public void authorize(Long authorizingAccountId, String verifier) {
-            this.authorizingAccountId = authorizingAccountId;
-            this.verifier = verifier;
-        }
-
-        public boolean authorized() {
-            return authorizingAccountId != null;
-        }
-
-        public Long getAuthorizingAccountId() {
-            return authorizingAccountId;
-        }
-
-        public String getVerifier() {
-            return verifier;
-        }
-   }
 }

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

 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.exception.EnMeDomainNotFoundException;
 import org.encuestame.persistence.exception.EnMeNotValidKeyOAuthSecurityException;
+import org.encuestame.utils.oauth.OAuthSession;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.AuthenticationException;

File encuestame-business/src/main/java/org/encuestame/business/security/oauth/OAuthSession.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.security.oauth;
-
-/**
- * Models an active OAuth handshake that, when completed,
- * results in a connection being established between a client application and a user account.
- * @author Picado, Juan juanATencuestame.org
- * @since Dec 24, 2010 3:55:45 PM
- * @version $Id:$
- */
-public interface OAuthSession {
-
-    /**
-     * The api key that identifies the client application.
-     */
-    String getApiKey();
-
-    /**
-     * The URL the client application wants the server to redirect the member to after he or she authorizes the connection.
-     */
-    String getCallbackUrl();
-
-    /**
-     * The OAuthSession or request key.  Uniquely identifies this OAuthSession object.
-     * Presented by the client application for each step of the connection process.
-     */
-    String getRequestToken();
-
-    /**
-     * The request token secret.
-     * Used for signature verification for requests made by the client during the connection process.
-     * OAuth 1.0 only.
-     */
-    String getSecret();
-
-    /**
-     * Flag that indicates if a member has authorized the connection yet.
-     * Initially false.  True once the user clicks "Yes, I allow application identified by apiKey to access my data".
-     */
-    boolean authorized();
-
-    /**
-     * The id of the member account that authorized the app connection.
-     * Returns null until {@link #authorized()} returns true.
-     */
-    Long getAuthorizingAccountId();
-
-    /**
-     * The verifier generated by the OAuthProvider upon user authorization.
-     * Expected to be submitted to the client on the accessToken request that follows the authorization callback.
-     * Returns null until {@link #authorized()} returns true.
-     * OAuth 1.0 only.
-     */
-    String getVerifier();
-
-}

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

 
 import org.encuestame.persistence.domain.application.ApplicationConnection;
 import org.encuestame.persistence.exception.EnMeNotValidKeyOAuthSecurityException;
+import org.encuestame.utils.oauth.OAuthSession;
 /**
  * Implementation to manage OAuth Sessions
  * @author Picado, Juan juanATencuestame.org

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

  */
 package org.encuestame.business.security.oauth;
 
+import org.encuestame.utils.oauth.OAuthSession;
 import org.springframework.security.oauth.provider.token.OAuthProviderToken;
 
 /**

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

                     } catch (Exception e) {
                         log.error("Error publish tweet "+e.getMessage());
                         publishedStatus.setStatus(TweetPollSavedPublishedStatus.Status.FAILED);
-                        publishedStatus.setDescriptionStatus(e.getMessage());
+                        publishedStatus.setDescriptionStatus(e.getMessage().substring(254));
                     }
                     getTweetPollDao().saveOrUpdate(publishedStatus);
                 }

File encuestame-business/src/main/java/org/encuestame/business/social/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.social;
+
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.utils.oauth.AuthorizedRequestToken;
+import org.encuestame.utils.oauth.OAuthToken;
+import org.springframework.social.twitter.TwitterOperations;
+
+/**
+ * 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 EnMeExpcetion;
+
+}

File encuestame-business/src/main/java/org/encuestame/business/social/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.social;
+
+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.SocialAccountProvider;
+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/social/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.social;
+
+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/social/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.social;
+
+import org.encuestame.persistence.domain.security.SocialAccountProvider;
+import org.encuestame.utils.oauth.OAuthToken;
+import org.springframework.social.facebook.FacebookOperations;
+import org.springframework.social.facebook.FacebookTemplate;
+import org.springframework.social.twitter.TwitterOperations;
+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<FacebookOperations> implements IFacebookSocialService{
+
+    /**
+     *
+     * @param socialProviderName
+     */
+    public FacebookSocialService(String socialProviderName) {
+        //super(socialProviderName);
+    }
+
+    @Override
+    protected FacebookOperations 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(FacebookOperations serviceOperations) {
+      return serviceOperations.getProfileId();
+    }
+
+    @Override
+    protected String buildProviderProfileUrl(String providerAccountId,
+            FacebookOperations 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;
+    }
+
+    public String fetchProviderAccountId(TwitterOperations serviceOperations) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

File encuestame-business/src/main/java/org/encuestame/business/social/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.social;
+
+/**
+ * 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/social/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.social;
+
+
+/**
+ * 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/social/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.social;
+
+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/social/SocialProviderOperations.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.social;
+
+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;
+
+/**
+ * Description Class.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 25, 2010 2:11:24 AM
+ * @version Id:
+ */
+public interface SocialProviderOperations<S> {
+
+        /**
+         * The unique name or id of the service provider e.g. twitter.
+         * Unique across all service providers.
+         */
+        String getName();
+
+        /**
+         * A label suitable for display in a UI, typically used to inform the user which service providers he or she has connected with / may connect with. e.g. Twitter.
+         */
+        String getDisplayName();
+
+        /**
+         * 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();
+
+        /**
+         * An alternate identifier for the local application in the remote service provider's system.
+         * May be null of no such alternate identifier exists.
+         * Used by ServiceProvider&lt;FacebookOperations&gt; to support "Like" functionality.
+         * @return an alternate app id, or null if no alternate id exists (null is the typical case, as the {@link #getApiKey()} is the primary means of consumer identification)
+         */
+        Long getAppId();
+
+        // connection management
+
+        /**
+         * Begin the account connection process by fetching a new request token from this service provider.
+         * The new token should be stored in the member's session up until the authorization callback is made and it's time to {@link #connect(Long, AuthorizedRequestToken) connect}.
+         * @param callbackUrl the URL the provider should redirect to after the member authorizes the connection (may be null for OAuth 1.0-based service providers)
+         */
+        OAuthToken fetchNewRequestToken(String callbackUrl);
+
+        /**
+         * Construct the URL to redirect the member to for connection authorization.
+         * @param requestToken the request token value, to be encoded in the authorize URL
+         * @return the absolute authorize URL to redirect the member to for authorization
+         */
+        String buildAuthorizeUrl(String requestToken);
+
+        /**
+         * Connects a member account to this service provider.
+         * Called after the user authorizes the connection at the {@link #buildAuthorizeUrl(String) authorizeUrl} and the service provider calls us back.
+         * Internally, exchanges the authorized request token for an access token, then stores the awarded access token with the member account.
+         * This access token identifies the connection between the member account and this service provider.
+         * <p>
+         * This method completes the OAuth-based account connection process.
+         * {@link #getServiceOperations(Long)} may now be called to get and invoke the service provider's API.
+         * The requestToken required during the connection handshake is no longer valid and cannot be reused.
+         * @param accountId the member account identifier
+         * @param requestToken the OAuth request token that was authorized by the member.
+         * @return
+         * @throws EnMeExistPreviousConnectionException
+         */
+        void connect(Long accountId, AuthorizedRequestToken requestToken) throws EnMeExistPreviousConnectionException;
+
+        /**
+         * Records an existing connection between a member 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.
+         */
+        void addConnection(Long accountId, String accessToken, String providerAccountId);
+
+        /**
+         * Returns true if the member account is connected to this provider, false otherwise.
+         */
+        boolean isConnected(Long accountId);
+
+        /**
+         * 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);
+
+        // additional finders
+
+        /**
+         * The id of the member in the provider's system.
+         * May be an assigned internal identifier, such as a sequence number, or a user-selected screen name.
+         * Generally unique across accounts registered with this provider.
+         */
+        //String getProviderAccountId(Long accountId);
+
+        /**
+         * Authenticate a member Account by a connection established with this service provider.
+         * Used to support "Sign in using Facebook"-type scenarios, where the access token identifying a connection is available to client code, typically a cookie managed by JavaScript.
+         * @throws NoSuchAccountConnectionException no such connection has been established between a member and this service provider
+         */
+        UserAccount findAccountByConnection(String accessToken) throws EnMeDomainNotFoundException;
+
+        /**
+         * Find the members connected to this provider that have the specified account ids in the provider's system.
+         * Used to see which of your friends in the provider's network also have member accounts with the local application.
+         */
+        //List<ProfileReference> findMembersConnectedTo(List<String> providerAccountIds);
+
+}

File encuestame-business/src/main/java/org/encuestame/business/social/TwitterSocialService.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.social;
+
+import org.encuestame.persistence.domain.security.SocialAccountProvider;
+import org.encuestame.utils.oauth.OAuthToken;
+import org.springframework.social.twitter.TwitterOperations;
+import org.springframework.social.twitter.TwitterTemplate;
+
+/**
+ * Twitter Social Service.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 25, 2010 5:57:35 PM
+ * @version $Id:$
+ */
+public class TwitterSocialService extends AbstractSocialProvider<TwitterOperations> implements ITwitterSocialProvider{
+
+    /**
+     * Social Account Provider;
+     */
+    private SocialAccountProvider parameters;
+
+    /**
+     * Twitter Template.
+     */
+    private TwitterTemplate twitterTemplate;
+
+    /**
+     * Twitter Url.
+     */
+    private final String TWITTER_URL = "http://www.twitter.com/";
+
+    /**
+     *
+     * @param socialProviderName
+     */
+    public TwitterSocialService() {
+       this.loadParameters();
+    }
+
+    @Override
+    protected TwitterOperations createServiceOperations(OAuthToken accessToken) {
+        log.debug("Twitter Operations createServiceOperations "+accessToken.toString());
+        if(this.twitterTemplate == null){
+            log.debug("Creando Provider");
+            this.createTwitterTemplate(accessToken);
+        }
+        return this.twitterTemplate;
+    }
+
+    /**
+     * Create Twitter Template.
+     * @param accessToken
+     */
+    private void createTwitterTemplate(final OAuthToken accessToken){
+        this.twitterTemplate = accessToken != null ?
+                new TwitterTemplate(
+                        getApiKey(),
+                        getSecret(),
+                        accessToken.getValue(),
+                        accessToken.getSecret())
+        : new TwitterTemplate();
+    }
+
+    /**
+     * Fetch Provider Account Id.
+     */
+    @Override
+    public String fetchProviderAccountId(TwitterOperations serviceOperations) {
+      log.debug("MEAN fetchNewRequestToken "+serviceOperations.getProfileId());
+      return serviceOperations.getProfileId();
+    }
+
+    /**
+     * Build Provider Profile Url.
+     */
+    @Override
+    protected String buildProviderProfileUrl(String providerAccountId,
+            TwitterOperations serviceOperations) {
+        return this.TWITTER_URL + providerAccountId;
+    }
+
+    /**
+     * Load Parameters.
+     */
+    private void loadParameters(){
+        if(getSocialProviderDao() != null){
+            final SocialAccountProvider parameters = getSocialProviderDao().getSocialAccountProviderId(1L);
+            if(parameters == null){
+                log.error("NOT SOCIAL PROVIDER FOUND");
+            }
+            setParameters(parameters);
+        } else {
+            log.error("No Provider Dao");
+        }
+    }
+
+    /**
+     * 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;
+    }
+}

File encuestame-business/src/main/resources/encuestame-service-context.xml

          <ref bean="frontEndService"/>
     </property>
   </bean>
-</beans>
+
+  <!--
+        Social Accounts Beans
+        This beans provide next features:
+        * Facebook Connect
+        * Twitter Connect
+        * LinkedIn Connect
+  -->
+
+    <bean id="abstractSocialProvider" class="org.encuestame.business.social.AbstractSocialProvider"
+          abstract="true">
+    </bean>
+
+    <!-- Twitter Service Provider Consumer -->
+    <bean id="twitterServiceConnect" autowire="byName"
+          class="org.encuestame.business.social.TwitterSocialService" parent="abstractSocialProvider">
+    </bean>
+
+    <!-- Facebook OAuth Consumer
+    <bean id="facebookServiceConnect" autowire="byName" class="org.encuestame.business.social.FacebookSocialService" parent="abstractSocialProvider">
+        <constructor-arg value="facebook" />
+    </bean>-->
+
+    <!-- LinkedIn OAuth Consumer
+    <bean id="linkedInServiceConnect" autowire="byName" class="org.encuestame.business.social.LinkedInSocialService" parent="abstractSocialProvider">
+        <constructor-arg value="linkedin" />
+    </bean>-->
+
+</beans>

File encuestame-core/src/main/java/org/encuestame/core/security/EnMeUserServiceImp.java

  */
 package org.encuestame.core.security;
 
-import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Set;
 
 import org.apache.log4j.Logger;
-import org.encuestame.persistence.domain.security.Group;
-import org.encuestame.persistence.domain.security.UserAccount;
-import org.encuestame.core.util.ConvertDomainsToSecurityContext;
 import org.encuestame.persistence.dao.IAccountDao;
 import org.encuestame.persistence.dao.imp.AccountDaoImp;
+import org.encuestame.persistence.domain.security.UserAccount;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DataAccessException;
-import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.security.core.userdetails.UserDetailsService;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
      */
     public UserDetails loadUserByUsername(final String username)
             throws UsernameNotFoundException, DataAccessException {
-        log.debug("username "+username);
+        //log.debug("username "+username);
         final UserAccount user = this.accountDao.getUserByUsername(username);
         if (user == null) {
-            log.error("user not found");
+            //log.error("user not found");
             throw new UsernameNotFoundException("user not found");
+        } else {
+            this.updateLoggedInfo(user);
+            return SecurityUtils.convertUserAccount(user, this.roleUserAuth);
         }
-        this.updateLoggedInfo(user);
-        return convertToUserDetails(user);
     }
 
-
     /**
      * Update Logged Info.
      * @param secUserSecondary
     private void updateLoggedInfo(final UserAccount secUserSecondary){
         final Calendar calendar = Calendar.getInstance();
         secUserSecondary.setLastTimeLogged(calendar.getTime());
-        log.debug("Updating logged time "+calendar.getTime());
+        //log.debug("Updating logged time "+calendar.getTime());
         accountDao.saveOrUpdate(secUserSecondary);
     }
-
-    /**
-     * Convert Survey User to Spring Security UserDetails
-     *
-     * @param user
-     * @return {@link UserDetails}
-     */
-    protected UserDetails convertToUserDetails(final UserAccount user) {
-        log.debug("convertToUserDetails username "+user.getUsername());
-        final Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
-        // search if authorities if the group are activated
-       /* if (this.roleGroupAuth) {
-            // search groups of the user
-            final Set<SecGroup> groups = user.getSecGroups();
-            for (final SecGroup secGroups : groups) {
-                authorities.addAll(ConvertDomainsToSecurityContext.convertEnMePermission(secGroups.getSecPermissions()));
-            }
-        }*/
-        // sec permissions
-        if (this.roleUserAuth) {
-            authorities.addAll(ConvertDomainsToSecurityContext.convertEnMePermission(user.getSecUserPermissions()));
-        }
-
-         //creating user details
-         final EnMeUserDetails userDetails = new EnMeUserDetails(
-         user.getUsername(),
-         user.getPassword(),
-         authorities,
-         user.isUserStatus() == null ? false : user.isUserStatus(),
-         true, // accoun not expired
-         true, // cridentials not expired
-         true, // account not locked
-         user.getUserTwitterAccount() == null ? "" : user.getUserTwitterAccount(), //twitter account
-         user.getCompleteName() == null ? "" : user.getCompleteName(), // complete name
-         user.getUserEmail() // user email
-         );
-         userDetails.setAccountNonExpired(true);
-         userDetails.setAccountNonLocked(true);
-         log.debug("user details "+userDetails.getPassword());
-         log.debug("user details "+userDetails.getPassword());
-         log.debug("user details "+userDetails.getAuthorities());
-         log.debug("user details "+userDetails.getUserEmail());
-         return userDetails;
-    }
 }

File encuestame-core/src/main/java/org/encuestame/core/security/SecurityUtils.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.core.security;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.encuestame.core.util.ConvertDomainsToSecurityContext;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.springframework.security.core.GrantedAuthority;
+
+/**
+ * Description Class.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 31, 2010 1:56:03 AM
+ * @version Id:
+ */
+public class SecurityUtils {
+
+    /**
+     * Convert User Account to {@link EnMeUserDetails}.
+     * @param user
+     * @param roleUserAuth
+     * @return
+     */
+    public static EnMeUserDetails convertUserAccount(final UserAccount user, final Boolean roleUserAuth){
+          //log.debug("convertToUserDetails username "+user.getUsername());
+        final Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
+        // search if authorities if the group are activated
+       /* if (this.roleGroupAuth) {
+            // search groups of the user
+            final Set<SecGroup> groups = user.getSecGroups();
+            for (final SecGroup secGroups : groups) {
+                authorities.addAll(ConvertDomainsToSecurityContext.convertEnMePermission(secGroups.getSecPermissions()));
+            }
+        }*/
+        // sec permissions
+        if (roleUserAuth) {
+            authorities.addAll(ConvertDomainsToSecurityContext.convertEnMePermission(user.getSecUserPermissions()));
+        }
+
+         //creating user details
+         final EnMeUserDetails userDetails = new EnMeUserDetails(
+         user.getUsername(),
+         user.getPassword(),
+         authorities,
+         user.isUserStatus() == null ? false : user.isUserStatus(),
+         true, // account not expired
+         true, // credentials not expired
+         true, // account not locked
+         user.getUserTwitterAccount() == null ? "" : user.getUserTwitterAccount(), //twitter account
+         user.getCompleteName() == null ? "" : user.getCompleteName(), // complete name
+         user.getUserEmail() // user email
+         );
+         userDetails.setAccountNonExpired(true);
+         userDetails.setAccountNonLocked(true);
+         //log.debug("user details "+userDetails.getPassword());
+         //log.debug("user details "+userDetails.getPassword());
+         //log.debug("user details "+userDetails.getAuthorities());
+         //log.debug("user details "+userDetails.getUserEmail());
+         return userDetails;
+    }
+}

File encuestame-core/src/main/java/org/encuestame/core/util/OAuthUtils.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.core.util;
+
+/**
+ * Store of OAuth Helpers.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Dec 30, 2010 3:23:40 PM
+ * @version $Id:$
+ */
+public class OAuthUtils {
+
+    public static final String OAUTH_TOKEN_ATTRIBUTE = "oauthToken";
+
+}

File encuestame-core/src/main/resources/encuestame-quartz-context.xml

             <list>
                  <bean id="cronReindex" class="org.springframework.scheduling.quartz.CronTriggerBean">
                     <property name="jobDetail" ref="reindexingInvokingJobDetail" />
-                    <property name="cronExpression" value="0 0/5 * * * ?" />
+                    <property name="cronExpression" value="0 0/15 * * * ?" />
                     <!-- Every 5 minutes 0 0/5 * * * ? -->
                     <!-- 0 0 12 1/5 * ? Fire at 12pm (noon) every 5 days every month, starting on the first day of the month. -->
                 </bean>

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/AdmonController.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.mvc.controller;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * Admon View Controller.
+ * @author Picado, Juan juan@encuestame.org
+ * @since Mar 6, 2010 10:58:02 AM
+ * @version $Id: $
+ */
+
+@Controller
+public class AdmonController extends BaseController {
+
+    private Log log = LogFactory.getLog(this.getClass());
+
+    /**
+     * Tweet Poll Controller.
+     * @param model model
+     * @param id id tweet
+     * @return template
+     */
+    @RequestMapping(value = "/admon/location.jspx", method = RequestMethod.GET)
+    public String admonLocation(ModelMap model) {
+        log.debug("LOCATION");
+        return "admon/location";
+    }
+
+    @RequestMapping(value = "/admon/members.jspx", method = RequestMethod.GET)
+    public String membersLocation(ModelMap model) {
+        log.debug("LOCATION");
+        return "admon/members";
+    }
+
+    @RequestMapping(value = "admon/project.jspx", method = RequestMethod.GET)
+    public String admonProject(ModelMap model) {
+        log.debug("LOCATION");
+        return "admon/project";
+    }
+
+}

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/BaseController.java

 package org.encuestame.mvc.controller;
 
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
+import java.util.List;
 import java.util.Locale;
 
 import javax.servlet.http.HttpServletRequest;
 import org.encuestame.business.service.imp.IServiceManager;
 import org.encuestame.business.service.imp.ISurveyService;
 import org.encuestame.business.service.imp.ITweetPollService;
+import org.encuestame.core.security.EnMeUserDetails;
+import org.encuestame.core.security.SecurityUtils;
 import org.encuestame.core.security.util.HTMLInputFilter;
 import org.encuestame.core.util.DateUtil;
+import org.encuestame.persistence.domain.EnMePermission;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.GrantedAuthorityImpl;
 import org.springframework.security.core.context.SecurityContext;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
      * @param request {@link HttpServletRequest}.
      * @return
      */
-    public String buildDomainWithRequest(final HttpServletRequest request){
+    public String getDomain(final HttpServletRequest request){
             final StringBuffer stringBuffer = new StringBuffer(this.isSecure(request) ? "https://" : "http://");
             stringBuffer.append(request.getServerName());
+            if(request.getRemotePort() != 80){
+                stringBuffer.append(":");
+                stringBuffer.append(request.getLocalPort());
+            }
             stringBuffer.append(request.getContextPath());
             return stringBuffer.toString();
     }
     }
 
     /**
+     * Get User Account.
+     * @return
+     */
+    public UserAccount getUserAccount(){
+        return this.getByUsername(this.getUserPrincipalUsername());
+    }
+
+    /**
      * Get Ip Client.
      * @return ip
      */
      * @param username username
      * @param password password
      */
-    protected void authenticate(HttpServletRequest request, final String username, final String password) {
+    public void authenticate(HttpServletRequest request, final String username, final String password) {
         try{
             final UsernamePasswordAuthenticationToken usernameAndPassword = new UsernamePasswordAuthenticationToken(username, password);
             final HttpSession session = request.getSession();
     }
 
     /**
+     * Authenticate User.
+     * @param user
+     */
+    public void authenticate(final UserAccount user){
+        final EnMeUserDetails details = SecurityUtils.convertUserAccount(user, true);
+        final Collection<GrantedAuthority> authorities = details.getAuthorities();
+        SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(details, null,
+                authorities));
+        log.debug("SecurityContextHolder.getContext()"+SecurityContextHolder.getContext().getAuthentication());
+        log.debug("SecurityContextHolder.getContext()"+SecurityContextHolder.getContext().getAuthentication().isAuthenticated());
+        log.debug("SecurityContextHolder.getContext()"+SecurityContextHolder.getContext().getAuthentication().getName());
+        log.debug("SecurityContextHolder.getContext()"+SecurityContextHolder.getContext().getAuthentication().getAuthorities());
+    }
+
+
+    /**
      * Get Message with Locale.
      * @param message
      * @param request

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/HomeController.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.mvc.controller;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * Home or FrontEnd Controller.
+ * @author Picado, Juan juan@encuestame.org
+ * @since Mar 6, 2010 10:58:02 AM
+ * @version $Id: $
+ */
+
+@Controller
+public class HomeController extends BaseController {
+
+    private Log log = LogFactory.getLog(this.getClass());
+
+    /**
+     * Home Controller.
+     * @param model model
+     * @return template
+     */