Commits

Juan Carlos Picado Herrera  committed 00de53e Merge

Merge branch 'juanpicado' into development

  • Participants
  • Parent commits 5aa5c92, bdfee09

Comments (0)

Files changed (9)

File encuestame-business/src/test/resources/messages_en.properties

 # Sign In
 ################
 
-secure.email.notvalid = Email Not Valid
-secure.user.notvalid = Username is not available
+secure.email.notvalid = This email is already registered
+secure.user.notvalid = This username is already taken!
+secure.username.empty = A username is required!
 secure.captcha.invalid = Catpcha is not valid
+secure.email.emtpy = Whats your email address?
+secure.email.valid = An email is perfect!
+secure.username.valid = Username is perfect!
+secure.realName.valid = Name looks great
+secure.realName.empty =  A real name is required!
+secure.type.not.valid = What are you doing?
 
 
 

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

             throws AuthenticationException {
          log.debug("EnMeUserAccountProvider "+authentication);
          if (authentication instanceof EnMeSecurityToken) {
-//             EnMeSecurityToken response = (EnMeSecurityToken) authentication;
-//                 // handle the various possibilities
-//                 // Lookup user details
-//                 final UserDetails userDetails =  SecurityUtils.convertUserAccountToUserDetails(response.getUserAccount(), true);
-//                     log.debug("user details "+userDetails);
-//             final Authentication auth = new EnMeSecurityToken(response.getUserAccount());
-             log.debug("EnMeUserAccountProvider -------- Return -------------");
              return authentication;
          } else {
              return null;

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

 
     private PasswordEncoder passwordEncoder = new PasswordEncoder();
 
+    /**
+     * {@link UserDetailsService}.
+     */
     @Autowired
     private UserDetailsService userDetailsService;
 
+    /**
+     */
     private boolean includeDetailsObject = true;
 
+    /*
+     * (non-Javadoc)
+     * @see org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider#additionalAuthenticationChecks(org.springframework.security.core.userdetails.UserDetails, org.springframework.security.authentication.UsernamePasswordAuthenticationToken)
+     */
     @Override
     protected void additionalAuthenticationChecks(UserDetails userDetails,
             final UsernamePasswordAuthenticationToken authentication)
             throws AuthenticationException {
-        log.debug("additionalAuthenticationChecks *********************************************");
-        log.debug("additionalAuthenticationChecks *********************************************");
-        log.debug("additionalAuthenticationChecks *********************************************");
-        log.debug("additionalAuthenticationChecks *********************************************");
 
         Object salt = null;
 
         final EnMeUserAccount detailsDataAccount = (EnMeUserAccount) userDetails;
 
         if (log.isDebugEnabled()) {
-            log.debug("detailsDataAccount "+detailsDataAccount.toString());
+            log.debug("detailsDataAccount " + detailsDataAccount.toString());
         }
 
         if (!detailsDataAccount.isSocialCredentials()) {
             if (authentication.getCredentials() == null) {
                 logger.debug("Authentication failed: no credentials provided");
 
-                throw new BadCredentialsException(messages.getMessage(
-                        "AbstractUserDetailsAuthenticationProvider.badCredentials",
-                        "Bad credentials"), includeDetailsObject ? userDetails
-                        : null);
+                throw new BadCredentialsException(
+                        messages.getMessage(
+                                "AbstractUserDetailsAuthenticationProvider.badCredentials",
+                                "Bad credentials"),
+                        includeDetailsObject ? userDetails : null);
             }
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
 
-            String presentedPassword = authentication.getCredentials().toString();
-            log.debug("EnMe: presentedPassword "+presentedPassword);
-            log.debug("EnMe: presentedPassword details "+userDetails.getPassword());
-            log.debug("EnMe: presentedPassword details "+passwordEncoder.getClass());
+            String presentedPassword = authentication.getCredentials()
+                    .toString();
 
             if (!passwordEncoder.isPasswordValid(userDetails.getPassword(),
                     presentedPassword, salt)) {
                 logger.debug("Authentication failed: password does not match stored value");
 
-                throw new BadCredentialsException(messages.getMessage(
-                        "AbstractUserDetailsAuthenticationProvider.badCredentials",
-                        "Bad credentials"), includeDetailsObject ? userDetails
-                        : null);
+                throw new BadCredentialsException(
+                        messages.getMessage(
+                                "AbstractUserDetailsAuthenticationProvider.badCredentials",
+                                "Bad credentials"),
+                        includeDetailsObject ? userDetails : null);
             }
-
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
-            log.debug("PASOWRDDDDDDDD CHECKKKKKKKS *********************************************");
         } else {
             if (log.isInfoEnabled()) {
                 log.info("SOCIAL CREDENTIALS ON");
             final String username,
             UsernamePasswordAuthenticationToken authentication)
             throws AuthenticationException {
-        log.info("retrieve user customized *********************************************************");
-        log.info("retrieve user customized *********************************************************");
-        log.info("retrieve user customized *********************************************************");
-        log.info("retrieve user customized *********************************************************");
-        log.info("retrieve user customized *********************************************************");
-        log.info("retrieve user customized *********************************************************");
 
         EnMeUserAccount loadedUser;
         try {

File encuestame-mvc/src/main/resources/properties-test/messages.properties

-#
-# License Agreement.
-#
-# encuestame system online surveys
-# Copyright (C) 2005-2008 encuestame Development Team
-#
-# This product is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License version 2.1 as published by the Free Software Foundation.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
-#
-
-################
-# Sign In
-################
-
-secure.email.notvalid = Email Not Valid
-secure.user.notvalid = Username is not available
-secure.captcha.invalid = Catpcha is not valid
-
-
-
-#######################
-# Notification Messages
-#######################
-
-notification.tweetpoll.publish = TweetPoll published successfull
-notification.tweetpoll.created = TweetPoll Created
-notification.tweetpoll.removed = TweetPoll {0} was removed
-notification.tweetpoll.like = {0} persons like your tweet
-notification.tweetpoll.unlike = {0} persons unlike your tweet
-notification.tweetpoll.finished = Your TweetPoll was finished. Check your results here.
-
-
-#########################
-# Relative Time Messages
-#########################
-
-relative.time.one.second.ago = Hace {0} segundo
-relative.time.one.seconds.ago = Hace {0} segundos
-relative.time.one.minute.ago =  Hace {0} minuto
-relative.time.one.minutes.ago = Hace {0} minutos
-relative.time.one.hour.ago = Hace {0} hora
-relative.time.one.hours.ago = Hace {0} horas
-relative.time.one.month.ago = Hace {0} mes
-relative.time.one.months.ago = Hace {0} meses
-relative.time.one.year.ago = Hace {0} a�o
-relative.time.one.years.ago = Hace {0} a�os
-
-########################
-## Social Message
-errorOauth = Uh Oh, something went wrong!
-tweet.processed = Your tweet has been published successfully.
-
-##############################
-# Email
-emailPasswordConfirmation = Remember your new password

File encuestame-mvc/src/main/resources/properties-test/messages_en.properties

-#
-# License Agreement.
-#
-# encuestame system online surveys
-# Copyright (C) 2005-2008 encuestame Development Team
-#
-# This product is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License version 2.1 as published by the Free Software Foundation.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
-#
-
-################
-# Sign In
-################
-
-secure.email.notvalid = Email Not Valid
-secure.user.notvalid = Username is not available
-secure.captcha.invalid = Catpcha is not valid
-
-
-
-#######################
-# Notification Messages
-#######################
-
-notification.tweetpoll.publish = TweetPoll published successfull
-notification.tweetpoll.created = TweetPoll Created
-notification.tweetpoll.removed = TweetPoll {0} was removed
-notification.tweetpoll.like = {0} persons like your tweet
-notification.tweetpoll.unlike = {0} persons unlike your tweet
-notification.tweetpoll.finished = Your TweetPoll was finished. Check your results here.
-
-
-#########################
-# Relative Time Messages
-#########################
-
-relative.time.one.second.ago = Hace {0} segundo
-relative.time.one.seconds.ago = Hace {0} segundos
-relative.time.one.minute.ago =  Hace {0} minuto
-relative.time.one.minutes.ago = Hace {0} minutos
-relative.time.one.hour.ago = Hace {0} hora
-relative.time.one.hours.ago = Hace {0} horas
-relative.time.one.month.ago = Hace {0} mes
-relative.time.one.months.ago = Hace {0} meses
-relative.time.one.year.ago = Hace {0} a�o
-relative.time.one.years.ago = Hace {0} a�os
-
-
-########################
-## Social Message
-
-errorOauth = Uh Oh, something went wrong!
-tweet.processed = Your tweet has been published successfully.
-
-##############################
-# Email
-emailPasswordConfirmation = Remember your new password

File encuestame-mvc/src/test/java/org/encuestame/mvc/test/config/AbstractJsonMvcUnitBeans.java

      */
     public JSONObject getSucess(final JSONObject response){
         Assert.assertNotNull("You need call first callJsonService", this.response);
-        System.out.println(this.response);
-        return (JSONObject) response.get("success");
+        if(response.get("success") == null) {
+            return new JSONObject();
+        } else {
+            return (JSONObject) response.get("success");
+        }
     }
 
     /**

File encuestame-mvc/src/test/java/org/encuestame/mvc/test/json/ValidatorServiceJsonTestCase.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2011
+ * 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.test.json;
+
+import junit.framework.Assert;
+
+import org.encuestame.mvc.controller.json.MethodJson;
+import org.encuestame.mvc.test.config.AbstractJsonMvcUnitBeans;
+import org.encuestame.persistence.domain.security.Account;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.json.simple.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Description.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Jul 18, 2011
+ */
+public class ValidatorServiceJsonTestCase extends AbstractJsonMvcUnitBeans{
+
+    /**
+     * Before.
+     */
+    @Before
+    public void initTest() {
+         Account account = createAccount();
+        createUserAccount("jota", "jota@jota.com", account);
+        createUserAccount("jota1", "jota1@jota.com", account);
+        createUserAccount("jota2", "jota2@jota.com", account);
+    }
+
+    /**
+     * Test not valid email.
+     * @throws Exception
+     */
+    @Test
+    public void validateEmailTestNotValid() throws Exception {
+        initService("/api/public/validator/email.json", MethodJson.GET);
+        setParameter("context", "test");
+        setParameter("email", "jota@jota.com");
+        final JSONObject response = callJsonService();
+        final JSONObject sucess = getSucess(response);
+        Assert.assertEquals(sucess.get("valid").toString(), "false");
+        Assert.assertEquals(sucess.get("msg").toString(), "This email is already registered");
+    }
+
+    /**
+     * Test valid email.
+     * @throws Exception
+     */
+    @Test
+    public void validateEmailTestValid() throws Exception {
+        initService("/api/public/validator/email.json", MethodJson.GET);
+        setParameter("context", "test");
+        setParameter("email", "jota555@jota.com");
+        final JSONObject response = callJsonService();
+        final JSONObject sucess = getSucess(response);
+        Assert.assertEquals(sucess.get("valid").toString(), "true");
+    }
+
+
+    @Test
+    public void validateEmailTestEmpty() throws Exception {
+        initService("/api/public/validator/email.json", MethodJson.GET);
+        setParameter("context", "test");
+        final JSONObject response = callJsonService();
+        final JSONObject sucess = getSucess(response);
+        Assert.assertEquals(sucess.get("valid").toString(), "false");
+    }
+
+    @Test
+    public void validateUsernameTestValid() throws Exception {
+        initService("/api/public/validator/username.json", MethodJson.GET);
+        setParameter("context", "test");
+        setParameter("username", "jota3333");
+        final JSONObject response = callJsonService();
+        final JSONObject sucess = getSucess(response);
+        Assert.assertEquals(sucess.get("valid").toString(), "true");
+        Assert.assertEquals(sucess.get("msg").toString(), "Username is perfect!");
+    }
+
+    @Test
+    public void validateUsernameTestNoValid() throws Exception {
+        initService("/api/public/validator/username.json", MethodJson.GET);
+        setParameter("context", "test");
+        setParameter("username", "jota");
+        final JSONObject response = callJsonService();
+        final JSONObject sucess = getSucess(response);
+        Assert.assertEquals(sucess.get("valid").toString(), "false");
+        Assert.assertEquals(sucess.get("msg").toString(), "This username is already taken!");
+
+    }
+
+    @Test
+    public void validateUsernameEmtpy() throws Exception {
+        initService("/api/public/validator/username.json", MethodJson.GET);
+        setParameter("context", "test");
+        final JSONObject response = callJsonService();
+        final JSONObject sucess = getSucess(response);
+        Assert.assertEquals(sucess.get("valid").toString(), "false");
+        Assert.assertEquals(sucess.get("msg").toString(), "A username is required!");
+        System.out.println(sucess);
+    }
+}

File encuestame-persistence/src/test/java/org/encuestame/test/config/AbstractBase.java

      */
     public UserAccount createUserAccount(
             final String name,
-            final Account secUser){
-        return createUserAccount(name, name.replace(" ", "")+"."+RandomStringUtils.randomNumeric(6)+"@users.com", secUser);
+            final Account account){
+        return createUserAccount(name, name.replace(" ", "")+"."+RandomStringUtils.randomNumeric(6)+"@users.com", account);
     }
 
-
     public UserAccount createSecondaryUserGroup(
             final String name,
             final Account secUser,

File encuestame-war/src/main/resources/messages_en.properties

 # Sign In
 ################
 
-secure.email.notvalid = This email is already registered"
+secure.email.notvalid = This email is already registered
 secure.user.notvalid = This username is already taken!
 secure.username.empty = A username is required!
 secure.captcha.invalid = Catpcha is not valid