cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf-fediz git commit: Sorting client tokens and pending grants by the issue time for a start
Date Fri, 12 Feb 2016 16:33:51 GMT
Repository: cxf-fediz
Updated Branches:
  refs/heads/master 6461e3ba8 -> 01ffae1c4


Sorting client tokens and pending grants by the issue time for a start


Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/01ffae1c
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/01ffae1c
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/01ffae1c

Branch: refs/heads/master
Commit: 01ffae1c40ab7eaf4c33bf711b64fb279af5b870
Parents: 6461e3b
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Feb 12 16:33:28 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Feb 12 16:33:28 2016 +0000

----------------------------------------------------------------------
 .../oidc/clients/ClientRegistrationService.java | 37 +++++++++++++++++---
 1 file changed, 32 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/01ffae1c/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/clients/ClientRegistrationService.java
----------------------------------------------------------------------
diff --git a/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/clients/ClientRegistrationService.java
b/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/clients/ClientRegistrationService.java
index c0f7f8c..4ecc2c0 100644
--- a/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/clients/ClientRegistrationService.java
+++ b/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/clients/ClientRegistrationService.java
@@ -23,6 +23,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -51,10 +52,13 @@ import org.apache.commons.validator.routines.UrlValidator;
 import org.apache.cxf.common.util.Base64UrlUtility;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.rs.security.oauth2.common.Client;
+import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken;
 import org.apache.cxf.rs.security.oauth2.common.UserSubject;
 import org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeDataProvider;
+import org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant;
 import org.apache.cxf.rs.security.oauth2.provider.ClientRegistrationProvider;
 import org.apache.cxf.rs.security.oauth2.provider.OAuthDataProvider;
+import org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken;
 import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants;
 import org.apache.cxf.rt.security.crypto.CryptoUtils;
 
@@ -140,9 +144,14 @@ public class ClientRegistrationService {
         // Right now the user who is registering the clients 
         // is the one who is working with them, i.e, client registrations 
         // are user specific, so passing null is OK
-        return new ClientTokens(c, 
-                                dataProvider.getAccessTokens(c, null),
-                                dataProvider.getRefreshTokens(c, null));
+        Comparator<ServerAccessToken> tokenComp = new TokenComparator();
+        List<ServerAccessToken> accessTokens = 
+            new ArrayList<ServerAccessToken>(dataProvider.getAccessTokens(c, null));
+        Collections.sort(accessTokens, tokenComp);
+        List<RefreshToken> refreshTokens = 
+                new ArrayList<RefreshToken>(dataProvider.getRefreshTokens(c, null));
+        Collections.sort(refreshTokens, tokenComp);
+        return new ClientTokens(c, accessTokens, refreshTokens);
     }
     @POST
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@@ -176,8 +185,10 @@ public class ClientRegistrationService {
     public ClientCodeGrants getClientCodeGrants(@PathParam("id") String id) {
         if (dataProvider instanceof AuthorizationCodeDataProvider) {
             Client c = getRegisteredClient(id);
-            return new ClientCodeGrants(c, 
-                    ((AuthorizationCodeDataProvider)dataProvider).getCodeGrants(c, null));
+            List<ServerAuthorizationCodeGrant> codeGrants = new ArrayList<ServerAuthorizationCodeGrant>(
+               ((AuthorizationCodeDataProvider)dataProvider).getCodeGrants(c, null));
+            Collections.sort(codeGrants, new CodeGrantComparator());
+            return new ClientCodeGrants(c, codeGrants);
         }
         return null;
     }
@@ -424,4 +435,20 @@ public class ClientRegistrationService {
         }
         
     }
+    private static class TokenComparator implements Comparator<ServerAccessToken> {
+
+        @Override
+        public int compare(ServerAccessToken t1, ServerAccessToken t2) {
+            return Long.valueOf(t1.getIssuedAt()).compareTo(t2.getIssuedAt());
+        }
+        
+    }
+    private static class CodeGrantComparator implements Comparator<ServerAuthorizationCodeGrant>
{
+
+        @Override
+        public int compare(ServerAuthorizationCodeGrant g1, ServerAuthorizationCodeGrant
g2) {
+            return Long.valueOf(g1.getIssuedAt()).compareTo(g2.getIssuedAt());
+        }
+        
+    }
 }


Mime
View raw message