usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [12/50] [abbrv] usergrid git commit: Updates to Java SDK to allow management user authentication.
Date Wed, 17 Aug 2016 21:17:31 GMT
Updates to Java SDK to allow management user authentication.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/5abd2a10
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/5abd2a10
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/5abd2a10

Branch: refs/heads/datastax-cass-driver
Commit: 5abd2a10e6603b03fcfcb4b08fa0efe59c383d64
Parents: 4558dc9
Author: Michael Russo <mrusso@apigee.com>
Authored: Wed Jul 27 16:51:42 2016 -0700
Committer: Michael Russo <mrusso@apigee.com>
Committed: Wed Jul 27 16:51:42 2016 -0700

----------------------------------------------------------------------
 .../apache/usergrid/java/client/UsergridClient.java |  2 ++
 .../java/client/UsergridRequestManager.java         | 13 ++++++++++++-
 .../usergrid/java/client/auth/UsergridAuth.java     |  1 +
 .../usergrid/java/client/auth/UsergridUserAuth.java | 16 ++++++++++++++--
 .../usergrid/java/client/query/UsergridQuery.java   |  5 -----
 5 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/5abd2a10/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java
index 87a84ae..a317d07 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClient.java
@@ -72,6 +72,8 @@ public class UsergridClient {
 
     @NotNull public String clientAppUrl() { return getBaseUrl() + "/" + getOrgId() + "/"
+ getAppId(); }
 
+    @NotNull public String managementUrl() { return getBaseUrl() + "/management"; }
+
     @NotNull public UsergridAuthMode getAuthMode() { return this.config.authMode; }
     public void setAuthMode(@NotNull final UsergridAuthMode authMode) { this.config.authMode
= authMode; }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5abd2a10/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java
index ef771e7..7099d42 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequestManager.java
@@ -60,7 +60,18 @@ public class UsergridRequestManager {
     @NotNull
     private UsergridResponse authenticate(@NotNull final UsergridAuth auth) {
         Map<String, String> credentials = auth.credentialsMap();
-        UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE,
this.usergridClient.clientAppUrl(), null, credentials, this.usergridClient.authForRequests(),
"token");
+        String url = this.usergridClient.clientAppUrl();
+        if ( auth instanceof UsergridUserAuth){
+
+            UsergridUserAuth userAuth = (UsergridUserAuth) auth;
+            if( userAuth.isAdminUser()){
+
+                url = this.usergridClient.managementUrl();
+            }
+
+        }
+
+        UsergridRequest request = new UsergridRequest(UsergridHttpMethod.POST, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE,
url, null, credentials, this.usergridClient.authForRequests(), "token");
         UsergridResponse response = performRequest(request);
         if (!isEmpty(response.getAccessToken()) && !isEmpty(response.getExpires()))
{
             auth.setAccessToken(response.getAccessToken());

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5abd2a10/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
index 94b4809..1ed61da 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
@@ -28,6 +28,7 @@ public class UsergridAuth {
     @Nullable private String accessToken = null;
     @Nullable private Long expiry = null;
     private boolean usingToken = false;
+    private boolean isAdminUser = false;
 
     public UsergridAuth() { }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5abd2a10/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
index e1831c2..7cb42ad 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
@@ -17,7 +17,6 @@
 package org.apache.usergrid.java.client.auth;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
-import org.apache.usergrid.java.client.model.UsergridUser;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.HashMap;
@@ -27,6 +26,7 @@ public class UsergridUserAuth extends UsergridAuth {
 
     @NotNull private String username;
     @NotNull private String password;
+    private boolean isAdminUser = false;
 
     @NotNull public String getUsername() { return username; }
     public void setUsername(@NotNull final String username) { this.username = username; }
@@ -34,6 +34,8 @@ public class UsergridUserAuth extends UsergridAuth {
     @NotNull private String getPassword() { return password; }
     public void setPassword(@NotNull final String password) { this.password = password; }
 
+    public boolean isAdminUser() { return isAdminUser; }
+
     @NotNull
     @Override
     public HashMap<String, String> credentialsMap() {
@@ -48,9 +50,19 @@ public class UsergridUserAuth extends UsergridAuth {
         this("","");
     }
 
-    public UsergridUserAuth(@JsonProperty("username") @NotNull final String username, @JsonProperty("password")
@NotNull final String password) {
+    public UsergridUserAuth(@JsonProperty("username") @NotNull final String username,
+                            @JsonProperty("password") @NotNull final String password) {
+        super();
+        this.username = username;
+        this.password = password;
+    }
+
+    public UsergridUserAuth(@JsonProperty("username") @NotNull final String username,
+                            @JsonProperty("password") @NotNull final String password,
+                            @JsonProperty("isAdminUser") final boolean isAdminUser) {
         super();
         this.username = username;
         this.password = password;
+        this.isAdminUser = isAdminUser;
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5abd2a10/sdks/java/src/main/java/org/apache/usergrid/java/client/query/UsergridQuery.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/query/UsergridQuery.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/query/UsergridQuery.java
index dc359c0..f7c8430 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/query/UsergridQuery.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/query/UsergridQuery.java
@@ -374,11 +374,6 @@ public final class UsergridQuery {
         }
 
         String requirementsString = this.constructRequirementString();
-        if (!requirementsString.isEmpty()) {
-            requirementsString = SELECT_ALL + SPACE + WHERE + SPACE + requirementsString;
-        } else {
-            requirementsString = SELECT_ALL + SPACE;
-        }
 
         String orderByString = this.constructOrderByString();
         if (!orderByString.isEmpty()) {


Mime
View raw message