usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [2/3] usergrid git commit: Minor cleanups, plus use standard TTL.
Date Wed, 02 Mar 2016 21:34:25 GMT
Minor cleanups, plus use standard TTL.

Conflicts:
	stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
	stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
	stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java


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

Branch: refs/heads/release-2.1.1
Commit: 8f588b97736532de1747bd763d404ea9d8a0e72e
Parents: 7f93739
Author: Dave Johnson <snoopdave@apache.org>
Authored: Tue Feb 16 17:19:07 2016 -0500
Committer: Michael Russo <mrusso@apigee.com>
Committed: Wed Mar 2 13:30:49 2016 -0800

----------------------------------------------------------------------
 .../rest/management/ManagementResourceIT.java   | 49 ++++++++++++++++++++
 .../tokens/cassandra/TokenServiceImpl.java      |  8 +---
 2 files changed, 51 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/8f588b97/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
index f29edcf..f05d4b6 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
@@ -609,6 +609,55 @@ public class ManagementResourceIT extends AbstractRestIT {
 
 
     @Test
+    public void testValidateExternalToken() throws Exception {
+
+        // create a new admin user, get access token
+
+        String rand = RandomStringUtils.randomAlphanumeric(10);
+        final String username = "user_" + rand;
+        management().orgs().post(
+            new Organization( username, username, username+"@example.com", username, "password",
null ) );
+
+        Map<String, Object> loginInfo = new HashMap<String, Object>() {{
+            put("username", username );
+            put("password", "password" );
+            put("grant_type", "password");
+        }};
+
+        JsonNode accessInfoNode = management.token()
+            .post( JsonNode.class, loginInfo );
+        String accessToken = accessInfoNode.get( "access_token" ).asText();
+
+        // set the Usergrid Central SSO URL because Tomcat port is dynamically assigned
+
+        String suToken = clientSetup.getSuperuserToken().getAccessToken();
+        Map<String, String> props = new HashMap<String, String>();
+        props.put( USERGRID_CENTRAL_URL, getBaseURI().toURL().toExternalForm() );
+        pathResource( "testproperties" ).post( props );
+
+
+        // TODO: how do we unit test SSO now that we have no external token end-point?
+
+
+        JsonNode node = pathResource("/management/me").get( JsonNode.class,  new QueryParameters()
+            .addParam( "access_token", accessToken) );
+
+
+        logger.info( "node: {}", node );
+        String token = node.get( "access_token" ).asText();
+
+        assertNotNull( token );
+
+        // TODO: how do we test the create new user and organization case?
+
+        // unset the Usergrid Central SSO URL so it does not interfere with other tests
+
+        props.put( USERGRID_CENTRAL_URL, "" );
+        pathResource( "testproperties" ).post( props );
+    }
+
+
+    @Test
     public void testSuperuserOnlyWhenValidateExternalTokensEnabled() throws Exception {
 
         // create an org and an admin user

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8f588b97/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
index 8bbb60f..8792fa8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
@@ -38,12 +38,10 @@ import org.apache.usergrid.security.AuthPrincipalInfo;
 import org.apache.usergrid.security.AuthPrincipalType;
 import org.apache.usergrid.security.tokens.TokenCategory;
 import org.apache.usergrid.security.tokens.TokenInfo;
-import org.apache.usergrid.security.tokens.TokenInfo;
 import org.apache.usergrid.security.tokens.TokenService;
 import org.apache.usergrid.security.tokens.exceptions.BadTokenException;
 import org.apache.usergrid.security.tokens.exceptions.ExpiredTokenException;
 import org.apache.usergrid.security.tokens.exceptions.InvalidTokenException;
-import org.apache.usergrid.services.ServiceManager;
 import org.apache.usergrid.utils.ConversionUtils;
 import org.apache.usergrid.utils.JsonUtils;
 import org.apache.usergrid.utils.UUIDUtils;
@@ -324,16 +322,14 @@ public class TokenServiceImpl implements TokenService {
 
         UUID uuid = getUUIDForToken( token );
 
-        long ssoTtl = 1000000L; // TODO: property for this
-
         if ( uuid == null ) {
-            return isSSOEnabled() ? validateExternalToken( token, ssoTtl ) : null;
+            return null;
         }
 
         TokenInfo tokenInfo = getTokenInfo( uuid );
 
         if ( tokenInfo == null ) {
-            return isSSOEnabled() ? validateExternalToken( token, ssoTtl ) : null;
+            return isSSOEnabled() ? validateExternalToken( token, maxPersistenceTokenAge
) : null;
         }
 
         //update the token


Mime
View raw message