usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [1/3] usergrid git commit: Add endpoint that allows fixing of admin user accounts.
Date Tue, 08 Dec 2015 22:35:08 GMT
Repository: usergrid
Updated Branches:
  refs/heads/unique_index_logging aba5705b1 -> 51cf21c08


Add endpoint that allows fixing of admin user accounts.


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

Branch: refs/heads/unique_index_logging
Commit: aa1ae7455fd13acdc0503cbce744d4df7f55f377
Parents: 98658fd
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Tue Dec 8 14:13:00 2015 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Tue Dec 8 14:13:00 2015 -0800

----------------------------------------------------------------------
 .../rest/management/users/UsersResource.java    | 73 +++++++++++++++++---
 1 file changed, 64 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/aa1ae745/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 816905c..50f0a4e 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
@@ -17,19 +17,12 @@
 package org.apache.usergrid.rest.management.users;
 
 
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.UUID;
 
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
+import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
@@ -37,8 +30,14 @@ 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.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.Identifier;
+import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.rest.RootResource;
 import org.apache.usergrid.rest.management.ManagementResource;
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
 import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,6 +57,7 @@ import net.tanesha.recaptcha.ReCaptchaResponse;
 
 import static org.apache.commons.lang.StringUtils.isBlank;
 import static org.apache.usergrid.rest.exceptions.SecurityException.mappableSecurityException;
+import static org.apache.usergrid.utils.ConversionUtils.string;
 
 
 @Component( "org.apache.usergrid.rest.management.users.UsersResource" )
@@ -114,6 +114,61 @@ public class UsersResource extends AbstractContextResource {
         return getUserResource(management.getAdminUserByEmail( email ), "email", email);
     }
 
+    @PUT
+    @RequireSystemAccess
+    @Path(RootResource.EMAIL_PATH+"/override")
+    public JSONWithPadding setUserInfo( @Context UriInfo ui, Map<String, Object> json,
+                                        @PathParam ("email") String emailFromPath,
+                                        @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+            throws Exception {
+
+        if ( json == null ) {
+            return null;
+        }
+
+        String emailFromBody = string( json.remove( "email" ) );
+
+        if(emailFromBody == null){
+            throw new IllegalArgumentException( "Email json body parameter required." );
+        }
+
+        if(!emailFromBody.equalsIgnoreCase(emailFromPath)){
+            throw new IllegalArgumentException( "Email provided in path must match email
provided in body" );
+        }
+
+        String username = string( json.remove( "username" ) );
+        String name = string( json.remove( "name" ) );
+
+        EntityManager em = emf.getEntityManager(CassandraService.MANAGEMENT_APPLICATION_ID);
+        EntityRef entity = em.getUserByIdentifier(Identifier.fromEmail(emailFromPath));
+        if(entity == null){
+            entity = em.getUserByIdentifier(Identifier.fromName(emailFromPath));
+        }
+        if(entity == null){
+            logger.error("Entity id parameter {} with {} value does not exist", "email",
emailFromPath);
+            throw new IllegalArgumentException("Entity not found.");
+        }
+
+        Map<String, Object> properties = new HashMap<String, Object>();
+        properties.put("email", emailFromPath);
+        properties.put("username", username);
+        properties.put("name", name);
+        properties.put("uuid", entity.getUuid());
+        properties.put("confirmed", true);
+        properties.put("activated", true);
+
+
+
+        // Re-create the user entity with the existing UUID found in the index
+        em.create(entity.getUuid(), User.ENTITY_TYPE, properties);
+
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "update user info" );
+
+        return new JSONWithPadding( response, callback );
+    }
+
 
     @POST
     @Consumes( MediaType.APPLICATION_FORM_URLENCODED )


Mime
View raw message