usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject usergrid git commit: Enhance secured endpoint that can force update a user's entity.
Date Sun, 13 Dec 2015 01:34:24 GMT
Repository: usergrid
Updated Branches:
  refs/heads/1.x aa1ae7455 -> ccf4e4231


Enhance secured endpoint that can force update a user's entity.


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

Branch: refs/heads/1.x
Commit: ccf4e4231e7f071b80e19bf2d3c8a32c9cec3266
Parents: aa1ae74
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Sat Dec 12 17:32:48 2015 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Sat Dec 12 17:32:48 2015 -0800

----------------------------------------------------------------------
 .../usergrid/persistence/EntityManager.java     |  4 ++
 .../cassandra/EntityManagerImpl.java            | 60 ++++++++++++++++++++
 .../rest/management/users/UsersResource.java    |  3 +-
 3 files changed, 66 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/ccf4e423/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 5684dc5..5dad23b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -97,6 +97,8 @@ public interface EntityManager {
      */
     public EntityRef getAlias( UUID ownerId, String collectionName, String aliasValue ) throws
Exception;
 
+    public EntityRef getAliasForAdminEmail( UUID ownerId, String collectionName, String aliasValue
) throws Exception;
+
     public Map<String, EntityRef> getAlias( String aliasType, List<String> aliases
) throws Exception;
 
     /**
@@ -573,6 +575,8 @@ public interface EntityManager {
 
     public EntityRef getUserByIdentifier( Identifier identifier ) throws Exception;
 
+    public EntityRef getUserByIdentifierOverride( Identifier identifier ) throws Exception;
+
     public EntityRef getGroupByIdentifier( Identifier identifier ) throws Exception;
 
     public Set<String> getCounterNames() throws Exception;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/ccf4e423/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index 0dd1b93..2be0252 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -747,6 +747,32 @@ public class EntityManagerImpl implements EntityManager {
         return results;
     }
 
+    @Override
+    public EntityRef getAliasForAdminEmail( UUID ownerId, String collectionName, String aliasValue
)
+            throws Exception {
+
+        Assert.notNull( ownerId, "ownerId is required" );
+        Assert.notNull( collectionName, "collectionName is required" );
+        Assert.notNull( aliasValue, "aliases are required" );
+
+
+        // force set this to email
+        String propertyName = "email";
+
+        Map<String, EntityRef> results = new HashMap<String, EntityRef>();
+
+
+            for ( UUID id : getUUIDsForUniqueProperty( ownerId, collectionName, propertyName,
aliasValue ) ) {
+                results.put( aliasValue, new SimpleEntityRef( collectionName, id ) );
+            }
+
+        if ( results.size() == 0 ) {
+            return null;
+        }
+
+        return results.get(aliasValue);
+    }
+
 
     @SuppressWarnings( "unchecked" )
     @Override
@@ -1645,6 +1671,40 @@ public class EntityManagerImpl implements EntityManager {
         return null;
     }
 
+    @Override
+    public EntityRef getUserByIdentifierOverride( Identifier identifier ) throws Exception
{
+        if ( identifier == null ) {
+            return null;
+        }
+        if ( identifier.isUUID() ) {
+            return new SimpleEntityRef( "user", identifier.getUUID() );
+        }
+        if ( identifier.isName() ) {
+            return this.getAlias( applicationId, "user", identifier.getName() );
+        }
+        if ( identifier.isEmail() ) {
+
+            // Check unique index first to see if email address exists, otherwise fall back
to regular entity index
+            EntityRef user = this.getAliasForAdminEmail( applicationId, "user", identifier.getValue().toString());
+            if (user != null){
+                return user;
+            }else {
+
+                Query query = new Query();
+                query.setEntityType("user");
+                query.addEqualityFilter("email", identifier.getEmail());
+                query.setLimit(1);
+                query.setResultsLevel(REFS);
+
+                Results r = getRelationManager(ref(applicationId)).searchCollection("users",
query);
+                if (r != null && r.getRef() != null) {
+                    return r.getRef();
+                }
+            }
+        }
+        return null;
+    }
+
 
     @Override
     public EntityRef getGroupByIdentifier( Identifier identifier ) throws Exception {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/ccf4e423/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 50f0a4e..758798c 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
@@ -140,7 +140,8 @@ public class UsersResource extends AbstractContextResource {
         String name = string( json.remove( "name" ) );
 
         EntityManager em = emf.getEntityManager(CassandraService.MANAGEMENT_APPLICATION_ID);
-        EntityRef entity = em.getUserByIdentifier(Identifier.fromEmail(emailFromPath));
+        // Use the override method as it also checks for email in Unique Index instead of
only Entity Index
+        EntityRef entity = em.getUserByIdentifierOverride(Identifier.fromEmail(emailFromPath));
         if(entity == null){
             entity = em.getUserByIdentifier(Identifier.fromName(emailFromPath));
         }


Mime
View raw message