You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/10/28 22:27:39 UTC
usergrid git commit: Adds the ability to get credentials info as
superuser for user migration
Repository: usergrid
Updated Branches:
refs/heads/USERGRID-1079-1x [created] 07e4cc211
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/07e4cc21
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/07e4cc21
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/07e4cc21
Branch: refs/heads/USERGRID-1079-1x
Commit: 07e4cc211ac715fca19b24355ca690bab2876218
Parents: afe0c51
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Oct 28 15:27:36 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Oct 28 15:27:36 2015 -0600
----------------------------------------------------------------------
.../rest/applications/users/UserResource.java | 46 ++++++++++++++++++--
.../usergrid/management/ManagementService.java | 2 +
.../cassandra/ManagementServiceImpl.java | 19 ++++++++
3 files changed, 63 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/07e4cc21/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 ea17282..5fa67af 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
@@ -41,7 +41,13 @@ 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;
import org.apache.usergrid.persistence.Identifier;
import org.apache.usergrid.persistence.entities.User;
@@ -50,13 +56,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;
@@ -159,6 +162,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 );
+ }
+
+
@POST
@Path("password")
http://git-wip-us.apache.org/repos/asf/usergrid/blob/07e4cc21/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 708e823..b5537ec 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
@@ -283,6 +283,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;
+
public User verifyAppUserPasswordCredentials( UUID applicationId, String name, String password ) throws Exception;
public UserInfo getAppUserFromAccessToken( String token ) throws Exception;
http://git-wip-us.apache.org/repos/asf/usergrid/blob/07e4cc21/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 b117be5..cb19733 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
@@ -2677,6 +2677,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 );