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/USERGRID-909
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 );

Reply via email to