You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2015/10/30 17:55:44 UTC

[1/6] usergrid git commit: Adds the ability to PUT credentials as a superuser

Repository: usergrid
Updated Branches:
  refs/heads/2.1-release c652171f4 -> 3d1205784


Adds the ability to PUT credentials as a superuser


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

Branch: refs/heads/2.1-release
Commit: 5ed8c7ce14d253ba04dfad48d239a0e11bf1a33c
Parents: c652171
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Oct 29 12:36:21 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Oct 29 13:47:15 2015 -0600

----------------------------------------------------------------------
 .../rest/applications/users/UserResource.java   | 38 ++++++++++++++++++++
 .../usergrid/management/ManagementService.java  | 12 ++++++-
 .../cassandra/ManagementServiceImpl.java        | 21 ++++++++++-
 3 files changed, 69 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/5ed8c7ce/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
index a8b0f81..df88cf0 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
@@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 import org.apache.usergrid.management.ActivationState;
+import org.apache.usergrid.persistence.CredentialsInfo;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.entities.User;
@@ -165,6 +166,43 @@ public class UserResource extends ServiceResource {
     }
 
 
+    @PUT
+    @Path("credentials")
+    public JSONWithPadding setUserCredentials( @Context UriInfo ui, Map<String, Object> json,
+                                               @QueryParam("callback") @DefaultValue("callback") String callback )
+            throws Exception {
+
+        logger.info( "UserResource.setUserPassword" );
+
+        if ( json == null ) {
+            return null;
+        }
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "set user credentials" );
+        Object credentials = json.get( "credentials" );
+
+
+        if ( credentials == null ) {
+            throw new IllegalArgumentException( "credentials sub object is required" );
+        }
+
+        UUID applicationId = getApplicationId();
+        UUID targetUserId = getUserUuid();
+
+        if ( targetUserId == null ) {
+            response.setError( "User not found" );
+            return new JSONWithPadding( response, callback );
+        }
+
+
+        management.setAppUserCredentialsInfo( applicationId, targetUserId, ( CredentialsInfo ) credentials );
+
+
+        return new JSONWithPadding( response, callback );
+    }
+
+
     @POST
     @Path("password")
     public JSONWithPadding setUserPasswordPost( @Context UriInfo ui, Map<String, Object> json,

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5ed8c7ce/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 3c5bbdb..d69de2e 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -288,6 +288,16 @@ public interface ManagementService {
     public void setAppUserPassword( UUID applicationId, UUID userId, String oldPassword, String newPassword )
             throws Exception;
 
+    /**
+     * Set the credentials info into the
+     * @param applicationId
+     * @param userId
+     * @param credentialsInfo
+     * @throws Exception
+     */
+    void  setAppUserCredentialsInfo( final UUID applicationId, final UUID userId, final CredentialsInfo credentialsInfo ) throws Exception;
+
+
     public User verifyAppUserPasswordCredentials( UUID applicationId, String name, String password ) throws Exception;
 
     public UserInfo getAppUserFromAccessToken( String token ) throws Exception;
@@ -350,7 +360,7 @@ public interface ManagementService {
     public OrganizationConfig getOrganizationConfigForApplication( UUID applicationId ) throws Exception;
 
     public void updateOrganizationConfig( OrganizationConfig organizationConfig ) throws Exception;
-    
+
     /**
      * will delete all entities
      * @param applicationId

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5ed8c7ce/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 70d74fc..2e33539 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -18,6 +18,7 @@ package org.apache.usergrid.management.cassandra;
 
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
 import com.google.inject.Injector;
@@ -2806,9 +2807,27 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     @Override
+    public void setAppUserCredentialsInfo( final UUID applicationId, final UUID userId,
+                                           final CredentialsInfo credentialsInfo ) throws Exception {
+
+        Preconditions.checkNotNull( applicationId, "applicationId is required" );
+        Preconditions.checkNotNull( userId, "userId is required" );
+        Preconditions.checkNotNull( credentialsInfo, "credentialsInfo is required" );
+
+        final User user = emf.getEntityManager( applicationId ).get(userId, User.class);
+
+        if(user == null){
+            throw new EntityNotFoundException( "User with id " + userId + " cannot be found" );
+        }
+
+        writeUserPassword(applicationId, user, credentialsInfo);
+    }
+
+
+    @Override
     public User verifyAppUserPasswordCredentials( UUID applicationId, String name, String password ) throws Exception {
 
-        User user = findUserEntity(applicationId, name);
+        User user = findUserEntity( applicationId, name );
         if ( user == null ) {
             return null;
         }


[6/6] usergrid git commit: Addresses comments in review

Posted by mr...@apache.org.
Addresses comments in review


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

Branch: refs/heads/2.1-release
Commit: 3d1205784528b5026695910943243a7a38fcbdde
Parents: ba629da
Author: Todd Nine <tn...@apigee.com>
Authored: Fri Oct 30 10:51:58 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Fri Oct 30 10:51:58 2015 -0600

----------------------------------------------------------------------
 .../apache/usergrid/rest/applications/users/UserResource.java  | 6 +++---
 .../rest/applications/collection/users/UserResourceIT.java     | 2 --
 2 files changed, 3 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/3d120578/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
index 1116469..fb2962e 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
@@ -173,11 +173,11 @@ public class UserResource extends ServiceResource {
     public JSONWithPadding getUserCredentials(@QueryParam("callback") @DefaultValue("callback") String callback )
             throws Exception {
 
-        logger.info( "UserResource.setUserPassword" );
+        logger.info( "UserResource.getUserCredentials" );
 
 
         final ApiResponse response = createApiResponse();
-        response.setAction( "get user password" );
+        response.setAction( "get user credentials" );
 
         final UUID applicationId = getApplicationId();
         final UUID targetUserId = getUserUuid();
@@ -210,7 +210,7 @@ public class UserResource extends ServiceResource {
                                                @QueryParam("callback") @DefaultValue("callback") String callback )
             throws Exception {
 
-        logger.info( "UserResource.setUserPassword" );
+        logger.info( "UserResource.setUserCredentials" );
 
         if ( json == null ) {
             return null;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/3d120578/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
index deda5eb..f258f94 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
@@ -1154,7 +1154,6 @@ public class UserResourceIT extends AbstractRestIT {
         //here we modify the hash a little, this way we can break password validation, then re-set it to ensure we're actually updating the credentials info correctly.
         final String borkedSecret = originalSecret.substring( 0, originalSecret.length() -1 );
 
-        credentials.put( "credentials", borkedSecret );
         credentials.put( "secret", borkedSecret );
 
         //now PUT it
@@ -1192,7 +1191,6 @@ public class UserResourceIT extends AbstractRestIT {
         //now put the correct one
 
 
-        credentials.put( "credentials", originalSecret );
         credentials.put( "secret", originalSecret );
 
 


[5/6] usergrid git commit: Adds test to prove functionality of GET + PUT

Posted by mr...@apache.org.
Adds test to prove functionality of GET + PUT


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

Branch: refs/heads/2.1-release
Commit: ba629da577235c0c9bedf4addcb44bfb5fdbdccb
Parents: 4784b34
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Oct 29 15:25:42 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Oct 29 15:25:42 2015 -0600

----------------------------------------------------------------------
 .../collection/users/UserResourceIT.java        | 109 +++++++++++++++++++
 1 file changed, 109 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/ba629da5/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
index 79b8c85..deda5eb 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
@@ -37,9 +37,15 @@ import org.apache.usergrid.rest.applications.utils.UserRepo;
 import org.apache.usergrid.utils.UUIDUtils;
 
 import com.sun.jersey.api.client.ClientResponse.Status;
+import com.sun.jersey.api.client.GenericType;
 import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+
 import java.io.IOException;
 
+import javax.ws.rs.core.MediaType;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -1103,4 +1109,107 @@ public class UserResourceIT extends AbstractRestIT {
 
         assertEquals(response.getResponse().getEntities().get(0).get("uuid").toString(), userId.toString());
     }
+
+
+
+    @Test
+    public void testCredentialsTransfer() throws Exception {
+
+        usersResource.post(new User("test_1", "Test1 User", "test_1@test.com", "test123")); // client.setApiUrl(apiUrl);
+        refreshIndex();
+
+        //Entity appInfo = this.app().get().getResponse().getEntities().get(0);
+
+        Token token = this.app().token().post(new Token("test_1", "test123"));
+
+        assertNotNull(token.getAccessToken());
+
+        final String superUserName = this.clientSetup.getSuperuserName();
+        final String superUserPassword = this.clientSetup.getSuperuserPassword();
+
+
+        //get the credentials info
+        final CollectionEndpoint collection  = userResource.entity("test_1").collection( "credentials" );
+
+        final WebResource resource  = collection.getResource();
+
+        resource.addFilter( new HTTPBasicAuthFilter(superUserName, superUserPassword) );
+
+
+
+        final ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE)
+                                             .accept( MediaType.APPLICATION_JSON ).get( org.apache.usergrid.rest.test.resource.model.ApiResponse.class );
+
+
+        //now get the credentials sub object
+
+        final Map<String, Object> credentials = ( Map<String, Object> ) response.getProperties().get( "credentials" );
+
+
+
+        //get out the hash and change it so we can validate
+        final String originalSecret = ( String ) credentials.get( "secret" );
+
+
+        //here we modify the hash a little, this way we can break password validation, then re-set it to ensure we're actually updating the credentials info correctly.
+        final String borkedSecret = originalSecret.substring( 0, originalSecret.length() -1 );
+
+        credentials.put( "credentials", borkedSecret );
+        credentials.put( "secret", borkedSecret );
+
+        //now PUT it
+
+
+        final Map<String, Map<String, Object>> wrapper = new HashMap<>(  );
+        wrapper.put( "credentials", credentials );
+
+        final WebResource putResource  = collection.getResource();
+
+        putResource.addFilter( new HTTPBasicAuthFilter(superUserName, superUserPassword) );
+
+
+        putResource.type( MediaType.APPLICATION_JSON_TYPE)
+                   .accept( MediaType.APPLICATION_JSON ).put(
+            org.apache.usergrid.rest.test.resource.model.ApiResponse.class, wrapper );
+
+
+        //now try to get a password, it should fail because the hash is no longer correct
+
+        int status = 0;
+
+        // bad access token
+        try {
+            this.app().token().post(new Token("test_1", "test123"));
+            fail("Should have thrown an exception");
+        } catch (UniformInterfaceException uie) {
+            status = uie.getResponse().getStatus();
+            log.info("Error Response Body: " + uie.getResponse().getEntity(String.class));
+        }
+
+        assertEquals(Status.BAD_REQUEST.getStatusCode(), status);
+
+
+        //now put the correct one
+
+
+        credentials.put( "credentials", originalSecret );
+        credentials.put( "secret", originalSecret );
+
+
+        final WebResource putResource2  = collection.getResource();
+
+        putResource2.addFilter( new HTTPBasicAuthFilter( superUserName, superUserPassword ) );
+
+
+        putResource2.type( MediaType.APPLICATION_JSON_TYPE)
+                    .accept( MediaType.APPLICATION_JSON ).put(
+            org.apache.usergrid.rest.test.resource.model.ApiResponse.class, wrapper );
+
+
+        //now auth, should be good
+        final Token nextToken = this.app().token().post(new Token("test_1", "test123"));
+
+        assertNotNull( nextToken.getAccessToken() );
+
+    }
 }


[2/6] usergrid git commit: Adds the ability to get credentials info as superuser for user migration

Posted by mr...@apache.org.
Adds the ability to get credentials info as superuser for user migration


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

Branch: refs/heads/2.1-release
Commit: 08e978132375751caf90ebcffde7a20d5e84b206
Parents: 5ed8c7c
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Oct 28 15:27:36 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Oct 29 13:55:38 2015 -0600

----------------------------------------------------------------------
 .../rest/applications/users/UserResource.java   | 45 ++++++++++++++++++--
 .../usergrid/management/ManagementService.java  |  2 +
 .../cassandra/ManagementServiceImpl.java        | 19 +++++++++
 3 files changed, 62 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/08e97813/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
index df88cf0..fb10245 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
@@ -42,6 +42,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
+
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.message.OAuthResponse;
+import org.apache.commons.lang.StringUtils;
+
 import org.apache.usergrid.management.ActivationState;
 import org.apache.usergrid.persistence.CredentialsInfo;
 import org.apache.usergrid.persistence.EntityManager;
@@ -52,13 +57,10 @@ import org.apache.usergrid.rest.ApiResponse;
 import org.apache.usergrid.rest.applications.ServiceResource;
 import org.apache.usergrid.rest.exceptions.RedirectionException;
 import org.apache.usergrid.rest.security.annotations.RequireApplicationAccess;
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
 import org.apache.usergrid.security.oauth.AccessInfo;
 import org.apache.usergrid.security.tokens.exceptions.TokenException;
 
-import org.apache.amber.oauth2.common.exception.OAuthProblemException;
-import org.apache.amber.oauth2.common.message.OAuthResponse;
-import org.apache.commons.lang.StringUtils;
-
 import com.sun.jersey.api.json.JSONWithPadding;
 import com.sun.jersey.api.view.Viewable;
 
@@ -165,6 +167,41 @@ public class UserResource extends ServiceResource {
         return new JSONWithPadding( response, callback );
     }
 
+    @GET
+    @RequireSystemAccess
+    @Path("password")
+    public JSONWithPadding getUserPassword(@QueryParam("callback") @DefaultValue("callback") String callback )
+            throws Exception {
+
+        logger.info( "UserResource.setUserPassword" );
+
+
+        final ApiResponse response = createApiResponse();
+        response.setAction( "get user password" );
+
+        final UUID applicationId = getApplicationId();
+        final UUID targetUserId = getUserUuid();
+
+        if ( applicationId == null ) {
+            response.setError( "Application not found" );
+            return new JSONWithPadding( response, callback );
+        }
+
+        if ( targetUserId == null ) {
+            response.setError( "User not found" );
+            return new JSONWithPadding( response, callback );
+        }
+
+        final CredentialsInfo credentialsInfo = management.getAppUserPasswordRaw( applicationId, targetUserId );
+
+
+        response.setProperty( "credentials", credentialsInfo );
+
+
+        return new JSONWithPadding( response, callback );
+    }
+
+
 
     @PUT
     @Path("credentials")

http://git-wip-us.apache.org/repos/asf/usergrid/blob/08e97813/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index d69de2e..3f02e5a 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -288,6 +288,8 @@ public interface ManagementService {
     public void setAppUserPassword( UUID applicationId, UUID userId, String oldPassword, String newPassword )
             throws Exception;
 
+    CredentialsInfo getAppUserPasswordRaw( final UUID applicationId, final UUID userId ) throws Exception;
+
     /**
      * Set the credentials info into the
      * @param applicationId

http://git-wip-us.apache.org/repos/asf/usergrid/blob/08e97813/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 2e33539..b633727 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -2825,6 +2825,25 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     @Override
+    public CredentialsInfo getAppUserPasswordRaw( final UUID applicationId, final UUID userId ) throws Exception {
+
+        final User user = emf.getEntityManager( applicationId ).get( userId, User.class );
+
+        if(user == null){
+            throw new EntityNotFoundException("Could not find user with id " + userId + " in application" + applicationId  );
+        }
+
+        final CredentialsInfo ci = readUserPasswordCredentials( applicationId, userId );
+
+        if ( ci == null ) {
+            throw new EntityNotFoundException("Could not find credentials for user with id " + userId + " in application" + applicationId );
+        }
+
+        return ci;
+    }
+
+
+    @Override
     public User verifyAppUserPasswordCredentials( UUID applicationId, String name, String password ) throws Exception {
 
         User user = findUserEntity( applicationId, name );


[3/6] usergrid git commit: Updated call for new read api in 2.0

Posted by mr...@apache.org.
Updated call for new read api in 2.0


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

Branch: refs/heads/2.1-release
Commit: 7fc7c55b7839ff9ba5a71b1c3d74a095c27f49ff
Parents: 08e9781
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Oct 29 13:56:14 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Oct 29 13:56:14 2015 -0600

----------------------------------------------------------------------
 .../apache/usergrid/rest/applications/users/UserResource.java    | 4 ++--
 .../java/org/apache/usergrid/management/ManagementService.java   | 2 +-
 .../usergrid/management/cassandra/ManagementServiceImpl.java     | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/7fc7c55b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
index fb10245..716f367 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
@@ -169,7 +169,7 @@ public class UserResource extends ServiceResource {
 
     @GET
     @RequireSystemAccess
-    @Path("password")
+    @Path("credentials")
     public JSONWithPadding getUserPassword(@QueryParam("callback") @DefaultValue("callback") String callback )
             throws Exception {
 
@@ -192,7 +192,7 @@ public class UserResource extends ServiceResource {
             return new JSONWithPadding( response, callback );
         }
 
-        final CredentialsInfo credentialsInfo = management.getAppUserPasswordRaw( applicationId, targetUserId );
+        final CredentialsInfo credentialsInfo = management.getAppUserCredentialsInfo( applicationId, targetUserId );
 
 
         response.setProperty( "credentials", credentialsInfo );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7fc7c55b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 3f02e5a..cf2924b 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -288,7 +288,7 @@ public interface ManagementService {
     public void setAppUserPassword( UUID applicationId, UUID userId, String oldPassword, String newPassword )
             throws Exception;
 
-    CredentialsInfo getAppUserPasswordRaw( final UUID applicationId, final UUID userId ) throws Exception;
+    CredentialsInfo getAppUserCredentialsInfo( final UUID applicationId, final UUID userId ) throws Exception;
 
     /**
      * Set the credentials info into the

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7fc7c55b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index b633727..dfd0cb1 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -2825,7 +2825,7 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     @Override
-    public CredentialsInfo getAppUserPasswordRaw( final UUID applicationId, final UUID userId ) throws Exception {
+    public CredentialsInfo getAppUserCredentialsInfo( final UUID applicationId, final UUID userId ) throws Exception {
 
         final User user = emf.getEntityManager( applicationId ).get( userId, User.class );
 
@@ -2833,7 +2833,7 @@ public class ManagementServiceImpl implements ManagementService {
             throw new EntityNotFoundException("Could not find user with id " + userId + " in application" + applicationId  );
         }
 
-        final CredentialsInfo ci = readUserPasswordCredentials( applicationId, userId );
+        final CredentialsInfo ci = readUserPasswordCredentials( applicationId, userId, User.ENTITY_TYPE );
 
         if ( ci == null ) {
             throw new EntityNotFoundException("Could not find credentials for user with id " + userId + " in application" + applicationId );


[4/6] usergrid git commit: Fixes GET + PUT for credentials info

Posted by mr...@apache.org.
Fixes GET + PUT for credentials info


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

Branch: refs/heads/2.1-release
Commit: 4784b34f3342b32639ee23beb9ccafa9a5443ed0
Parents: 7fc7c55
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Oct 29 12:37:31 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Oct 29 14:42:41 2015 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/CredentialsInfo.java   | 46 ++++++++++++++++++++
 .../rest/applications/users/UserResource.java   | 11 +++--
 2 files changed, 53 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/4784b34f/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java b/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
index 957f8a8..c7c4cba 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/CredentialsInfo.java
@@ -20,7 +20,10 @@ package org.apache.usergrid.persistence;
 import com.fasterxml.jackson.annotation.JsonAnyGetter;
 import com.fasterxml.jackson.annotation.JsonAnySetter;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.google.common.base.Preconditions;
+
 import java.io.Serializable;
+import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 import javax.xml.bind.annotation.XmlRootElement;
@@ -118,6 +121,11 @@ public class CredentialsInfo implements Comparable<CredentialsInfo>,Serializable
     }
 
 
+    public void setCreated( final Long created ) {
+        this.created = created;
+    }
+
+
     @JsonAnySetter
     public void setProperty( String key, Object value ) {
         properties.put( key, value );
@@ -172,4 +180,42 @@ public class CredentialsInfo implements Comparable<CredentialsInfo>,Serializable
         }
         return o.created.compareTo( created );
     }
+
+
+    /**
+     * Parse the json representation into an object
+     * @param json
+     * @return
+     */
+    public static CredentialsInfo fromJson(final Map<String, Object> json){
+        final boolean recoverable = ( boolean ) json.get( "recoverable");
+
+        final boolean encrypted = ( boolean ) json.get("encrypted");
+        final String hashType = ( String ) json.get( "hashType");
+        final long created = ( long ) json.get( "created");
+        final String secret = ( String ) json.get(  "secret" );
+
+        final List<String>  cryptoChain = ( List<String> ) json.get( "cryptoChain");
+
+        Preconditions.checkNotNull(created, "created is required");
+        Preconditions.checkNotNull(secret, "secret is required");
+        Preconditions.checkNotNull(cryptoChain, "cryptoChain is required");
+
+        Preconditions.checkArgument(cryptoChain.size() >= 1, "cryptoChain must have 1 or more entries");
+
+
+        final String[] cryptoString = new String[cryptoChain.size()];
+
+        cryptoChain.toArray( cryptoString );
+
+
+        final CredentialsInfo credentialsInfo = new CredentialsInfo();
+        credentialsInfo.setEncrypted( encrypted );
+        credentialsInfo.setHashType( hashType );
+        credentialsInfo.setCreated( created );
+        credentialsInfo.setSecret( secret );
+        credentialsInfo.setCryptoChain( cryptoString );
+
+        return credentialsInfo;
+    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/4784b34f/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
index 716f367..1116469 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/users/UserResource.java
@@ -170,7 +170,7 @@ public class UserResource extends ServiceResource {
     @GET
     @RequireSystemAccess
     @Path("credentials")
-    public JSONWithPadding getUserPassword(@QueryParam("callback") @DefaultValue("callback") String callback )
+    public JSONWithPadding getUserCredentials(@QueryParam("callback") @DefaultValue("callback") String callback )
             throws Exception {
 
         logger.info( "UserResource.setUserPassword" );
@@ -204,6 +204,7 @@ public class UserResource extends ServiceResource {
 
 
     @PUT
+    @RequireSystemAccess
     @Path("credentials")
     public JSONWithPadding setUserCredentials( @Context UriInfo ui, Map<String, Object> json,
                                                @QueryParam("callback") @DefaultValue("callback") String callback )
@@ -217,13 +218,15 @@ public class UserResource extends ServiceResource {
 
         ApiResponse response = createApiResponse();
         response.setAction( "set user credentials" );
-        Object credentials = json.get( "credentials" );
+        Map<String, Object> credentialsJson = ( Map<String, Object> ) json.get( "credentials" );
 
 
-        if ( credentials == null ) {
+        if ( credentialsJson == null ) {
             throw new IllegalArgumentException( "credentials sub object is required" );
         }
 
+        final CredentialsInfo credentials = CredentialsInfo.fromJson( credentialsJson );
+
         UUID applicationId = getApplicationId();
         UUID targetUserId = getUserUuid();
 
@@ -233,7 +236,7 @@ public class UserResource extends ServiceResource {
         }
 
 
-        management.setAppUserCredentialsInfo( applicationId, targetUserId, ( CredentialsInfo ) credentials );
+        management.setAppUserCredentialsInfo( applicationId, targetUserId, credentials );
 
 
         return new JSONWithPadding( response, callback );