You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/06/22 17:40:34 UTC

[02/22] incubator-usergrid git commit: Added ability for application client resources to be accepted.

Added ability for application client resources to be accepted.


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

Branch: refs/heads/two-dot-o-dev
Commit: 5905b46fa5363ab1cc38daa2de9b7585718147fb
Parents: a784016
Author: GERey <gr...@apigee.com>
Authored: Fri Jun 5 15:36:52 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Fri Jun 5 15:36:52 2015 -0700

----------------------------------------------------------------------
 .../applications/ApplicationResourceIT.java     | 27 ++++++++++++++++++++
 .../rest/test/resource2point0/ClientSetup.java  |  6 +++++
 .../security/shiro/utils/SubjectUtils.java      | 10 +++++---
 3 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5905b46f/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
index 3b4a0b6..671954b 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
@@ -93,6 +93,33 @@ public class ApplicationResourceIT extends AbstractRestIT {
     }
 
     /**
+     * Retrieve an collection using the application client credentials
+     */
+    @Test
+    public void applicationCollectionWithAppCredentials() throws Exception {
+
+        //retrieve the credentials
+        Credentials appCredentials = getAppCredentials();
+
+        //retrieve the app using only the org credentials
+        ApiResponse apiResponse = this.app().collection( "roles" ).getResource( false )
+                                      .queryParam("grant_type", "client_credentials")
+                                      .queryParam("client_id", appCredentials.getClientId())
+                                      .queryParam("client_secret", appCredentials.getClientSecret())
+                                      .accept(MediaType.APPLICATION_JSON)
+                                      .type(MediaType.APPLICATION_JSON_TYPE)
+                                      .get(ApiResponse.class);
+        //assert that a valid response is returned without error
+        assertNotNull(apiResponse);
+        assertNull(apiResponse.getError());
+
+        Collection roles = new Collection(apiResponse);
+        //assert that we have the correct number of default roles
+        assertEquals(3, roles.getNumOfEntities());
+    }
+
+
+    /**
      * Verifies that we return JSON even when no accept header is specified.
      * (for backwards compatibility)
      */

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5905b46f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
index e033c2d..7966d3b 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
@@ -112,10 +112,16 @@ public class ClientSetup implements TestRule {
 
         organization = restClient.management().orgs().post(new Organization( orgName,username,username+"@usergrid.com",username,username, null  ));
 
+        refreshIndex();
+
         restClient.management().token().post(new Token(username,username));
 
+        refreshIndex();
+
         restClient.management().orgs().organization(organization.getName()).app().post(new Application(appName));
 
+        refreshIndex();
+
     }
 
     public String getUsername(){return username;}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5905b46f/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java
index 5c222b4..28f5d6d 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java
@@ -243,14 +243,18 @@ public class SubjectUtils {
         String applicationName = null;
         UUID applicationId = null;
         BiMap<UUID, String> applications = getApplications();
+        Set<String> values= applications.values();
+
         if ( applications == null ) {
             return null;
         }
         if ( identifier.isName() ) {
             applicationName = identifier.getName().toLowerCase();
-            applicationId = applications.inverse().get( applicationName );
-            if ( applicationId == null ) {
-                applicationId = applications.inverse().get( identifier.getName() );
+            for (String value: values ){
+                if(value.toLowerCase().equals( applicationName )){
+                    applicationId = applications.inverse().get( value );
+                    break;
+                }
             }
         }
         else if ( identifier.isUUID() ) {