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/USERGRID-909 Commit: 4784b34f3342b32639ee23beb9ccafa9a5443ed0 Parents: 7fc7c55 Author: Todd Nine <[email protected]> Authored: Thu Oct 29 12:37:31 2015 -0600 Committer: Todd Nine <[email protected]> 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 );
