usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject incubator-usergrid git commit: Added test that proves the issue that we couldn't use application credentials. Fixed not being able to get mixed case applications using application credentials in the realm. Fixed the creation of mixed case applications, n
Date Fri, 12 Jun 2015 19:29:53 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-670-one-o [created] db83ff47c


Added test that proves the issue that we couldn't use application credentials.
Fixed not being able to get mixed case applications using application credentials in the realm.
Fixed the creation of mixed case applications, now its all handled as lower case in the backend...for
applications at least.


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

Branch: refs/heads/USERGRID-670-one-o
Commit: db83ff47c118c7c959ee425f8d2b5ce2e09c8c2c
Parents: a415af4
Author: GERey <greyes@apigee.com>
Authored: Fri Jun 12 12:29:50 2015 -0700
Committer: GERey <greyes@apigee.com>
Committed: Fri Jun 12 12:29:50 2015 -0700

----------------------------------------------------------------------
 .../applications/ApplicationResourceIT.java     | 37 ++++++++++++++++++--
 .../cassandra/ManagementServiceImpl.java        |  3 +-
 .../apache/usergrid/security/shiro/Realm.java   |  2 +-
 3 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db83ff47/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 e7af2f5..469bf60 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
@@ -17,6 +17,7 @@
 package org.apache.usergrid.rest.applications;
 
 
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
@@ -28,6 +29,7 @@ import org.apache.usergrid.cassandra.Concurrent;
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.OrganizationInfo;
 import org.apache.usergrid.rest.AbstractRestIT;
+import org.apache.usergrid.rest.management.organizations.OrganizationsResource;
 
 import org.apache.shiro.codec.Base64;
 
@@ -65,16 +67,45 @@ public class ApplicationResourceIT extends AbstractRestIT {
         assertNotNull( node.get( "entities" ) );
     }
 
+    //TODO: write a test so that its mixed case.
     @Test
     public void applicationWithAppCredentials() throws Exception {
 
-        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo( "test-organization/test-app"
);
+        String orgName = "MiXedApplicationResourceTest";
+        String appName = "mgmt-org-app-test";
+
+        //create new org
+        Map payload = hashMap( "email", "test-user-1@mockserver.com" ).map( "username", "ApplicationAppCredsTest"
)
+                                                                      .map( "name", "App
Creds User" )
+                                                                      .map( "password", "password"
)
+                                                                      .map( "organization",
+                                                                              orgName );
+
+        resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON
)
+                                  .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class,
payload );
+
+        //create new app
+        Map<String, String> data = new HashMap<String, String>();
+        data.put( "name", appName );
+
+        JsonNode appdata = resource().path( "/management/orgs/" + orgName + "/applications"
)
+                                     .queryParam( "access_token", superAdminToken() ).accept(
MediaType.APPLICATION_JSON )
+                                     .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class,
data );
+
 
+        ApplicationInfo appInfo = setup.getMgmtSvc().getApplicationInfo(orgName+"/"+appName
);//"test-organization/test-app" );
+
+        //don't know what kind of creds these are but they sure aren't app creds...
         String clientId = setup.getMgmtSvc().getClientIdForApplication( appInfo.getId() );
         String clientSecret = setup.getMgmtSvc().getClientSecretForApplication( appInfo.getId()
);
 
-        JsonNode node = resource().path( "/test-organization/test-app/users" ).queryParam(
"client_id", clientId )
-                .queryParam( "client_secret", clientSecret ).accept( MediaType.APPLICATION_JSON
)
+        JsonNode applicationCredentials = resource().path( "/"+orgName.toLowerCase()+"/"+appName+"/credentials"
).queryParam( "client_id", clientId )
+
+                                                    .queryParam( "client_secret", clientSecret
).accept( MediaType.APPLICATION_JSON )
+                                                    .type( MediaType.APPLICATION_JSON_TYPE
).get( JsonNode.class );
+
+        JsonNode node = resource().path( "/"+orgName.toLowerCase()+"/"+appName+"/users" ).queryParam(
"client_id", applicationCredentials.get( "credentials" ).get( "client_id" ).asText())
+                .queryParam( "client_secret", applicationCredentials.get( "credentials" ).get(
"client_secret" ).asText() ).accept( MediaType.APPLICATION_JSON )
                 .type( MediaType.APPLICATION_JSON_TYPE ).get( JsonNode.class );
 
         assertNotNull( node.get( "entities" ) );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db83ff47/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 b3204a7..b117be5 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
@@ -680,7 +680,8 @@ public class ManagementServiceImpl implements ManagementService {
      * (and that organization is needed) if so.
      */
     private String buildAppName( String applicationName, OrganizationInfo organization )
{
-        return applicationName.contains( "/" ) ? applicationName : organization.getName()
+ "/" + applicationName;
+        return org.apache.commons.lang.StringUtils.lowerCase(
+                applicationName.contains( "/" ) ? applicationName : organization.getName()
+ "/" + applicationName);
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/db83ff47/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
index 0f1f9e8..0188922 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
@@ -278,7 +278,7 @@ public class Realm extends AuthorizingRealm {
 
                 application = ( ( ApplicationPrincipal ) principal ).getApplication();
                 grant( info, principal, "applications:admin,access,get,put,post,delete:"
+ application.getId() );
-                applicationSet.put( application.getId(), application.getName() );
+                applicationSet.put( application.getId(), application.getName().toLowerCase());
             }
             else if ( principal instanceof AdminUserPrincipal ) {
                 // AdminUserPrincipals are through basic auth and sessions


Mime
View raw message