You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/08/12 22:11:19 UTC

[1/3] incubator-usergrid git commit: Fix logic issue when recaptcha is disabled

Repository: incubator-usergrid
Updated Branches:
  refs/heads/master 8e32c136a -> f011b3ddd


Fix logic issue when recaptcha is disabled


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/322886b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/322886b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/322886b4

Branch: refs/heads/master
Commit: 322886b4d87ad34c849ba76e04ddf14fb996e310
Parents: 49ae4ac
Author: ryan bridges <rb...@apigee.com>
Authored: Tue Jun 2 14:38:36 2015 -0400
Committer: ryan bridges <rb...@apigee.com>
Committed: Tue Jun 2 14:38:36 2015 -0400

----------------------------------------------------------------------
 .../rest/applications/users/UsersResource.java  | 45 +++++++--------
 .../rest/management/users/UsersResource.java    | 61 ++++++++------------
 2 files changed, 43 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/322886b4/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
index 1a1b576..044f54e 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
@@ -85,7 +85,7 @@ public class UsersResource extends ServiceResource {
 
         logger.info( "ServiceResource.addIdParameter" );
 
-        UUID itemId = UUID.fromString( entityId.getPath() );
+        UUID itemId = UUID.fromString(entityId.getPath());
 
         addParameter( getServiceParameters(), itemId );
 
@@ -116,12 +116,12 @@ public class UsersResource extends ServiceResource {
 
         addParameter( getServiceParameters(), itemName.getPath() );
 
-        addMatrixParams( getServiceParameters(), ui, itemName );
+        addMatrixParams(getServiceParameters(), ui, itemName);
         Identifier id = Identifier.from( itemName.getPath() );
         if ( id == null ) {
             throw new IllegalArgumentException( "Not a valid user identifier: " + itemName.getPath() );
         }
-        return getSubResource( UserResource.class ).init( id );
+        return getSubResource( UserResource.class ).init(id);
     }
 
 
@@ -129,7 +129,7 @@ public class UsersResource extends ServiceResource {
     @Path("resetpw")
     @Produces(MediaType.TEXT_HTML)
     public Viewable showPasswordResetForm( @Context UriInfo ui ) {
-        return handleViewable( "resetpw_email_form", this );
+        return handleViewable("resetpw_email_form", this);
     }
 
 
@@ -142,32 +142,28 @@ public class UsersResource extends ServiceResource {
                                              @FormParam("recaptcha_response_field") String uresponse ) {
 
         try {
-            ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
-            reCaptcha.setPrivateKey( properties.getRecaptchaPrivate() );
+            if ( isBlank(email) ) {
+                errorMsg = "No email provided, try again...";
+                throw new Exception("No email provided");
+            }else if (useReCaptcha()){
+                ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
+                reCaptcha.setPrivateKey( properties.getRecaptchaPrivate() );
 
-            ReCaptchaResponse reCaptchaResponse =
+                ReCaptchaResponse reCaptchaResponse =
                     reCaptcha.checkAnswer( httpServletRequest.getRemoteAddr(), challenge, uresponse );
 
-            if ( isBlank( email ) ) {
-                errorMsg = "No email provided, try again...";
-                return handleViewable( "resetpw_email_form", this );
-            }
-
-            if ( !useReCaptcha() || reCaptchaResponse.isValid() ) {
-                user = management.getAppUserByIdentifier( getApplicationId(), Identifier.fromEmail( email ) );
-                if ( user != null ) {
-                    management.startAppUserPasswordResetFlow( getApplicationId(), user );
-                    return handleViewable( "resetpw_email_success", this );
-                }
-                else {
-                    errorMsg = "We don't recognize that email, try again...";
-                    return handleViewable( "resetpw_email_form", this );
+                if(!reCaptchaResponse.isValid()){
+                    errorMsg = "Incorrect Captcha, try again...";
+                    throw new Exception("Incorrect Captcha");
                 }
             }
-            else {
-                errorMsg = "Incorrect Captcha, try again...";
-                return handleViewable( "resetpw_email_form", this );
+            user = management.getAppUserByIdentifier(getApplicationId(), Identifier.fromEmail(email));
+            if (user == null) {
+                errorMsg = "We don't recognize that email, try again...";
+                throw new Exception("Unrecognized email address");
             }
+            management.startAppUserPasswordResetFlow( getApplicationId(), user );
+            return handleViewable("resetpw_email_success", this);
         }
         catch ( RedirectionException e ) {
             throw e;
@@ -177,7 +173,6 @@ public class UsersResource extends ServiceResource {
         }
     }
 
-
     public String getErrorMsg() {
         return errorMsg;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/322886b4/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
index d907632..ffa4bf1 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
@@ -80,7 +80,7 @@ public class UsersResource extends AbstractContextResource {
     @Path(RootResource.USER_ID_PATH)
     public UserResource getUserById( @Context UriInfo ui, @PathParam( "userId" ) String userIdStr ) throws Exception {
 
-        return getUserResource(management.getAdminUserByUuid( UUID.fromString( userIdStr ) ), "user id", userIdStr);
+        return getUserResource(management.getAdminUserByUuid(UUID.fromString(userIdStr)), "user id", userIdStr);
     }
 
 
@@ -103,7 +103,7 @@ public class UsersResource extends AbstractContextResource {
         if (user == null) {
             throw new ManagementException("Could not find organization for " + type + " : " + value);
         }
-        return getSubResource(UserResource.class).init( user );
+        return getSubResource(UserResource.class).init(user);
     }
 
 
@@ -176,60 +176,45 @@ public class UsersResource extends AbstractContextResource {
 
 
     @POST
-    @Path( "resetpw" )
-    @Consumes( "application/x-www-form-urlencoded" )
-    @Produces( MediaType.TEXT_HTML )
-    public Viewable handlePasswordResetForm( @Context UriInfo ui, @FormParam( "email" ) String email,
-                                             @FormParam( "recaptcha_challenge_field" ) String challenge,
-                                             @FormParam( "recaptcha_response_field" ) String uresponse ) {
+    @Path("resetpw")
+    @Consumes("application/x-www-form-urlencoded")
+    @Produces(MediaType.TEXT_HTML)
+    public Viewable handlePasswordResetForm( @Context UriInfo ui, @FormParam("email") String email,
+                                             @FormParam("recaptcha_challenge_field") String challenge,
+                                             @FormParam("recaptcha_response_field") String uresponse ) {
 
         try {
-            if ( isBlank( email ) ) {
+            if ( isBlank(email) ) {
                 errorMsg = "No email provided, try again...";
-                return handleViewable( "resetpw_email_form", this );
-            }
-
-            //we don't require recaptcha - only use it if it is present in the props file
-            boolean reCaptchaPassed = false;
-            if ( useReCaptcha() ) {
-
+                throw new Exception("No email provided");
+            }else if (useReCaptcha()){
                 ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
-                reCaptcha.setPrivateKey(properties.getRecaptchaPrivate());
+                reCaptcha.setPrivateKey( properties.getRecaptchaPrivate() );
 
                 ReCaptchaResponse reCaptchaResponse =
-                        reCaptcha.checkAnswer(httpServletRequest.getRemoteAddr(), challenge, uresponse);
+                    reCaptcha.checkAnswer( httpServletRequest.getRemoteAddr(), challenge, uresponse );
 
-                if (reCaptchaResponse.isValid()) {
-                    reCaptchaPassed = true;
+                if(!reCaptchaResponse.isValid()){
+                    errorMsg = "Incorrect Captcha, try again...";
+                    throw new Exception("Incorrect Captcha");
                 }
-            } else {
-                reCaptchaPassed = true;
             }
-
-            if (reCaptchaPassed) {
-                user = management.findAdminUser(email);
-                if (user != null) {
-                    management.startAdminUserPasswordResetFlow(user);
-                    return handleViewable("resetpw_email_success", this);
-                } else {
-                    errorMsg = "We don't recognize that email, try again...";
-                    return handleViewable("resetpw_email_form", this);
-                }
-            } else {
-                errorMsg = "Incorrect Captcha, try again...";
-                return handleViewable("resetpw_email_form", this);
+            user = management.findAdminUser(email);
+            if (user == null) {
+                errorMsg = "We don't recognize that email, try again...";
+                throw new Exception("Unrecognized email address");
             }
-            
+            management.startAdminUserPasswordResetFlow(user);
+            return handleViewable("resetpw_email_success", this);
         }
         catch ( RedirectionException e ) {
             throw e;
         }
         catch ( Exception e ) {
-            return handleViewable( "error", e );
+            return handleViewable( "resetpw_email_form", e );
         }
     }
 
-
     public String getErrorMsg() {
         return errorMsg;
     }


[2/3] incubator-usergrid git commit: Adding additional logging and exception handling to recaptcha

Posted by gr...@apache.org.
Adding additional logging and exception handling to recaptcha


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2b336ef1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2b336ef1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2b336ef1

Branch: refs/heads/master
Commit: 2b336ef12600fb9a8f54211cc209a6a13227bc5e
Parents: 322886b
Author: ryan bridges <rb...@apigee.com>
Authored: Wed Jun 3 12:57:43 2015 -0400
Committer: ryan bridges <rb...@apigee.com>
Committed: Wed Jun 3 12:57:43 2015 -0400

----------------------------------------------------------------------
 .../usergrid/rest/applications/users/UsersResource.java     | 9 ++++++---
 .../usergrid/rest/management/users/UsersResource.java       | 8 ++++++--
 2 files changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2b336ef1/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
index 044f54e..6325d5a 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UsersResource.java
@@ -36,6 +36,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.UriInfo;
 
+import net.tanesha.recaptcha.ReCaptchaException;
 import org.apache.usergrid.rest.RootResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -154,14 +155,15 @@ public class UsersResource extends ServiceResource {
 
                 if(!reCaptchaResponse.isValid()){
                     errorMsg = "Incorrect Captcha, try again...";
-                    throw new Exception("Incorrect Captcha");
+                    throw new Exception("reCAPTCHA error message: "+reCaptchaResponse.getErrorMessage());
                 }
             }
             user = management.getAppUserByIdentifier(getApplicationId(), Identifier.fromEmail(email));
             if (user == null) {
                 errorMsg = "We don't recognize that email, try again...";
-                throw new Exception("Unrecognized email address");
+                throw new Exception("Unrecognized email address "+email);
             }
+            logger.info(String.format("Starting AppUser Password Reset Flow for %s on %s", user.getUuid(), getApplicationId()));
             management.startAppUserPasswordResetFlow( getApplicationId(), user );
             return handleViewable("resetpw_email_success", this);
         }
@@ -169,7 +171,8 @@ public class UsersResource extends ServiceResource {
             throw e;
         }
         catch ( Exception e ) {
-            return handleViewable( "resetpw_email_form", e );
+            logger.error(String.format("Exception in password reset form. (%s) %s ", e.getClass().getCanonicalName(), e.getMessage()));
+            return handleViewable( "resetpw_email_form", this );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2b336ef1/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
index ffa4bf1..816905c 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/users/UsersResource.java
@@ -34,6 +34,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
 
+import net.tanesha.recaptcha.ReCaptchaException;
 import org.apache.commons.lang.StringUtils;
 import org.apache.usergrid.management.exceptions.ManagementException;
 import org.apache.usergrid.rest.RootResource;
@@ -196,14 +197,16 @@ public class UsersResource extends AbstractContextResource {
 
                 if(!reCaptchaResponse.isValid()){
                     errorMsg = "Incorrect Captcha, try again...";
-                    throw new Exception("Incorrect Captcha");
+                    throw new Exception("reCAPTCHA error message: "+reCaptchaResponse.getErrorMessage());
                 }
             }
             user = management.findAdminUser(email);
+
             if (user == null) {
                 errorMsg = "We don't recognize that email, try again...";
                 throw new Exception("Unrecognized email address");
             }
+            logger.info("Starting Admin User Password Reset Flow for "+user.getUuid());
             management.startAdminUserPasswordResetFlow(user);
             return handleViewable("resetpw_email_success", this);
         }
@@ -211,7 +214,8 @@ public class UsersResource extends AbstractContextResource {
             throw e;
         }
         catch ( Exception e ) {
-            return handleViewable( "resetpw_email_form", e );
+            logger.error(String.format("Exception in password reset form. (%s) %s ", e.getClass().getCanonicalName(), e.getMessage()));
+            return handleViewable( "resetpw_email_form", this );
         }
     }
 


[3/3] incubator-usergrid git commit: Merge branch 'recaptcha-fix'

Posted by gr...@apache.org.
Merge branch 'recaptcha-fix'

* recaptcha-fix:
  Adding additional logging and exception handling to recaptcha
  Fix logic issue when recaptcha is disabled


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f011b3dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f011b3dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f011b3dd

Branch: refs/heads/master
Commit: f011b3dddf93998a799dfe48e632f0d8856d8792
Parents: 8e32c13 2b336ef
Author: GERey <gr...@apigee.com>
Authored: Wed Aug 12 12:50:26 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Wed Aug 12 12:50:26 2015 -0700

----------------------------------------------------------------------
 .../rest/applications/users/UsersResource.java  | 50 ++++++++--------
 .../rest/management/users/UsersResource.java    | 63 ++++++++------------
 2 files changed, 50 insertions(+), 63 deletions(-)
----------------------------------------------------------------------