Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9B635179C6 for ; Thu, 28 Jan 2016 17:21:50 +0000 (UTC) Received: (qmail 55641 invoked by uid 500); 28 Jan 2016 17:15:10 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 55575 invoked by uid 500); 28 Jan 2016 17:15:09 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 55566 invoked by uid 99); 28 Jan 2016 17:15:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Jan 2016 17:15:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 855D6DFFF4; Thu, 28 Jan 2016 17:15:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: Adding few convinience methods to OAuthAuthorizationData Date: Thu, 28 Jan 2016 17:15:09 +0000 (UTC) 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 Authored: Thu Jan 28 17:13:20 2016 +0000 Committer: Sergey Beryozkin 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 getPermissionsAsStrings() { + return permissions != null ? OAuthUtils.convertPermissionsToScopeList(permissions) + : Collections.emptyList(); + } + public List getAlreadyAuthorizedPermissionsAsStrings() { + return alreadyAuthorizedPermissions != null + ? OAuthUtils.convertPermissionsToScopeList(alreadyAuthorizedPermissions) + : Collections.emptyList(); + } + public List getAllPermissions() { + List allPerms = new LinkedList(); + if (alreadyAuthorizedPermissions != null) { + allPerms.addAll(alreadyAuthorizedPermissions); + if (permissions != null) { + List list = getAlreadyAuthorizedPermissionsAsStrings(); + for (OAuthPermission perm : permissions) { + if (!list.contains(perm.getPermission())) { + allPerms.add(perm); + } + } + } + } else if (permissions != null) { + allPerms.addAll(permissions); + } + return allPerms; + } }