cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Adding few convinience methods to OAuthAuthorizationData
Date Thu, 28 Jan 2016 17:15:09 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 15ebdfafc -> f8b8025bc


Adding few convinience methods to OAuthAuthorizationData


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

Branch: refs/heads/3.1.x-fixes
Commit: f8b8025bcf1b4b74712782db73dc2715aeae70fe
Parents: 15ebdfa
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Jan 28 17:13:20 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Jan 28 17:14:56 2016 +0000

----------------------------------------------------------------------
 .../oauth2/common/OAuthAuthorizationData.java   | 30 +++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f8b8025b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/OAuthAuthorizationData.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/OAuthAuthorizationData.java
b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/OAuthAuthorizationData.java
index 04618d6..218ad19 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/OAuthAuthorizationData.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/OAuthAuthorizationData.java
@@ -19,6 +19,7 @@
 package org.apache.cxf.rs.security.oauth2.common;
 
 import java.io.Serializable;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -26,6 +27,8 @@ import java.util.Map;
 
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.apache.cxf.rs.security.oauth2.utils.OAuthUtils;
+
 /**
  * This bean represents a resource owner authorization challenge.
  * Typically, an HTML view will be returned to a resource owner who
@@ -227,5 +230,30 @@ public class OAuthAuthorizationData extends OAuthRedirectionState implements
Ser
     public void setHidePreauthorizedScopesInForm(boolean hidePreauthorizedScopesInForm) {
         this.hidePreauthorizedScopesInForm = hidePreauthorizedScopesInForm;
     }
-
+    public List<String> getPermissionsAsStrings() {
+        return permissions != null ? OAuthUtils.convertPermissionsToScopeList(permissions)

+            : Collections.emptyList();
+    }
+    public List<String> getAlreadyAuthorizedPermissionsAsStrings() {
+        return alreadyAuthorizedPermissions != null 
+            ? OAuthUtils.convertPermissionsToScopeList(alreadyAuthorizedPermissions) 
+            : Collections.emptyList();
+    }
+    public List<OAuthPermission> getAllPermissions() {
+        List<OAuthPermission> allPerms = new LinkedList<OAuthPermission>();
+        if (alreadyAuthorizedPermissions != null) {
+            allPerms.addAll(alreadyAuthorizedPermissions);
+            if (permissions != null) {
+                List<String> list = getAlreadyAuthorizedPermissionsAsStrings();
+                for (OAuthPermission perm : permissions) {
+                    if (!list.contains(perm.getPermission())) {
+                        allPerms.add(perm);
+                    }
+                }
+            }
+        } else if (permissions != null) {
+            allPerms.addAll(permissions);
+        }
+        return allPerms;
+    }
 }


Mime
View raw message