usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [26/35] usergrid git commit: Allow GET /management/me with local UG tokens when External SSO is enabled.
Date Fri, 02 Sep 2016 00:51:45 GMT
Allow GET /management/me with local UG tokens when External SSO is enabled.


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

Branch: refs/heads/master
Commit: f73ce4a72696eac4db0b45ccb6e64a6f6f758494
Parents: 23cfde0
Author: Michael Russo <mrusso@apigee.com>
Authored: Wed Aug 31 11:46:21 2016 -0700
Committer: Michael Russo <mrusso@apigee.com>
Committed: Wed Aug 31 11:46:21 2016 -0700

----------------------------------------------------------------------
 .../rest/management/ManagementResource.java     | 21 ++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/f73ce4a7/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
index 4f8b456..12e1270 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
@@ -42,6 +42,7 @@ import org.apache.usergrid.security.sso.ApigeeSSO2Provider;
 import org.apache.usergrid.security.sso.ExternalSSOProvider;
 import org.apache.usergrid.security.sso.SSOProviderFactory;
 import org.apache.usergrid.security.tokens.cassandra.TokenServiceImpl;
+import org.apache.usergrid.security.tokens.exceptions.BadTokenException;
 import org.apache.usergrid.utils.JsonUtils;
 import org.glassfish.jersey.server.mvc.Viewable;
 import org.slf4j.Logger;
@@ -196,14 +197,22 @@ public class ManagementResource extends AbstractContextResource {
         String ssoUserId = null;
         if(ssoEnabled && !user.getUsername().equals(properties.getProperty(USERGRID_SYSADMIN_LOGIN_NAME))){
             ExternalSSOProvider provider = ssoProviderFactory.getProvider();
-            final Map<String, String> decodedTokenDetails = provider.getDecodedTokenDetails(access_token);
-            final String expiry = decodedTokenDetails.containsKey("expiry") ? decodedTokenDetails.get("expiry")
: "0";
 
-            tokenTtl =
-                Long.valueOf(expiry) - System.currentTimeMillis()/1000;
+            try {
+                final Map<String, String> decodedTokenDetails = provider.getDecodedTokenDetails(access_token);
+                final String expiry = decodedTokenDetails.containsKey("expiry") ? decodedTokenDetails.get("expiry")
: "0";
+
+                tokenTtl =
+                    Long.valueOf(expiry) - System.currentTimeMillis() / 1000;
+
+                if (provider instanceof ApigeeSSO2Provider) {
+                    ssoUserId = decodedTokenDetails.get("user_id");
+                }
+            }catch (BadTokenException e){
+
+                // even when SSO is enabled, this could be a local token
+                tokenTtl = tokens.getTokenInfo(access_token).getDuration();
 
-            if( provider instanceof ApigeeSSO2Provider ) {
-                ssoUserId = decodedTokenDetails.get("user_id");
             }
 
         }else{


Mime
View raw message