Return-Path: X-Original-To: apmail-usergrid-commits-archive@minotaur.apache.org Delivered-To: apmail-usergrid-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EA55B184EC for ; Thu, 29 Oct 2015 19:47:19 +0000 (UTC) Received: (qmail 30853 invoked by uid 500); 29 Oct 2015 19:47:19 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 30830 invoked by uid 500); 29 Oct 2015 19:47:19 -0000 Mailing-List: contact commits-help@usergrid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@usergrid.apache.org Delivered-To: mailing list commits@usergrid.apache.org Received: (qmail 30821 invoked by uid 99); 29 Oct 2015 19:47:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Oct 2015 19:47:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A86AEE3932; Thu, 29 Oct 2015 19:47:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: toddnine@apache.org To: commits@usergrid.apache.org Message-Id: <60b059c32d9b476f8c5cf77a8b2d41fe@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: usergrid git commit: Adds the ability to PUT credentials as a superuser Date: Thu, 29 Oct 2015 19:47:19 +0000 (UTC) Repository: usergrid Updated Branches: refs/heads/USERGRID-1079-2x [created] 5ed8c7ce1 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-1079-2x Commit: 5ed8c7ce14d253ba04dfad48d239a0e11bf1a33c Parents: c652171 Author: Todd Nine Authored: Thu Oct 29 12:36:21 2015 -0600 Committer: Todd Nine 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 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 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; }