Author: nbelaevski
Date: 2009-03-18 15:56:01 -0400 (Wed, 18 Mar 2009)
New Revision: 13011
Modified:
trunk/ui/functions/src/main/config/component/functions.xml
trunk/ui/functions/src/main/java/org/richfaces/function/RichFunction.java
Log:
https://jira.jboss.org/jira/browse/RF-6551
Modified: trunk/ui/functions/src/main/config/component/functions.xml
===================================================================
--- trunk/ui/functions/src/main/config/component/functions.xml 2009-03-18 17:49:15 UTC
(rev 13010)
+++ trunk/ui/functions/src/main/config/component/functions.xml 2009-03-18 19:56:01 UTC
(rev 13011)
@@ -23,4 +23,9 @@
<name>findComponent</name>
<method>org.richfaces.function.RichFunction.findComponent(String)</method>
</function>
+
+ <function>
+ <name>isUserInRole</name>
+
<method>org.richfaces.function.RichFunction.isUserInRole(Object)</method>
+ </function>
</components>
Modified: trunk/ui/functions/src/main/java/org/richfaces/function/RichFunction.java
===================================================================
--- trunk/ui/functions/src/main/java/org/richfaces/function/RichFunction.java 2009-03-18
17:49:15 UTC (rev 13010)
+++ trunk/ui/functions/src/main/java/org/richfaces/function/RichFunction.java 2009-03-18
19:56:01 UTC (rev 13011)
@@ -21,10 +21,14 @@
package org.richfaces.function;
+import java.util.Set;
+
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils;
/**
@@ -80,4 +84,25 @@
public static UIComponent findComponent(String id) {
return findComponent(FacesContext.getCurrentInstance(), id);
}
+
+ /**
+ * @since 3.3.1
+ * @param rolesObject
+ * @return
+ */
+ public static boolean isUserInRole(Object rolesObject) {
+ Set<String> rolesSet = AjaxRendererUtils.asSet(rolesObject);
+ if (rolesSet != null) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ExternalContext externalContext = facesContext.getExternalContext();
+
+ for (String role : rolesSet) {
+ if (externalContext.isUserInRole(role)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
}