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/11/02 23:56:17 UTC
[26/50] [abbrv] usergrid git commit: Adds the ability to PUT
credentials as a superuser
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/USERGRID-909
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;
}