Author: ppitonak(a)redhat.com
Date: 2010-07-23 06:42:23 -0400 (Fri, 23 Jul 2010)
New Revision: 18211
Added:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/TestIdentityFilter.java
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/UserBean.java
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/all.xhtml
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/list.xhtml
root/tests/metamer/trunk/application/src/main/webapp/resources/css/richFunctions.css
Modified:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
root/tests/metamer/trunk/application/src/main/webapp/WEB-INF/web.xml
Log:
* added a page for RichFaces client functions (clientId, element, component,
findComponent, isUserInRole)
Added:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/TestIdentityFilter.java
===================================================================
---
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/TestIdentityFilter.java
(rev 0)
+++
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/TestIdentityFilter.java 2010-07-23
10:42:23 UTC (rev 18211)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+
+package org.richfaces.tests.metamer;
+
+import java.io.IOException;
+import java.security.Principal;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpSession;
+import org.richfaces.tests.metamer.bean.UserBean;
+
+/**
+ * Filter for working with user roles. It is used by RichFaces client function
rich:isUserInRole().
+ *
+ * @author Nick Belaevski, <a href="mailto:ppitonak@redhat.com">Pavol
Pitonak</a>
+ * @version $Revision$
+ */
+public class TestIdentityFilter implements Filter {
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void destroy() {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException {
+
+ HttpServletRequestWrapper wrapper = new
HttpServletRequestWrapper((HttpServletRequest) request) {
+
+ private UserBean getUserBean() {
+ HttpSession session = getSession(false);
+ if (session != null) {
+ return (UserBean) session.getAttribute("userBean");
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isUserInRole(String role) {
+ UserBean userBean = getUserBean();
+ if (userBean != null) {
+ return userBean.isUserInRole(role);
+ }
+ return false;
+ }
+
+ @Override
+ public Principal getUserPrincipal() {
+ UserBean userBean = getUserBean();
+ if (userBean != null) {
+ return userBean.getPrincipal();
+ }
+ return null;
+ }
+
+ @Override
+ public String getRemoteUser() {
+ UserBean userBean = getUserBean();
+ if (userBean != null) {
+ return userBean.getRolename();
+ }
+ return null;
+ }
+ };
+
+ chain.doFilter(wrapper, response);
+ }
+}
Property changes on:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/TestIdentityFilter.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Modified:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
===================================================================
---
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-07-23
07:21:06 UTC (rev 18210)
+++
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-07-23
10:42:23 UTC (rev 18211)
@@ -107,6 +107,7 @@
components.put("richDataScroller", "Rich Data Scroller");
components.put("richDataTable", "Rich Data Table");
components.put("richExtendedDataTable", "Rich Extended Data
Table");
+ components.put("richFunctions", "Rich Functions");
components.put("richList", "Rich List");
components.put("richPanel", "Rich Panel");
}
Added:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/UserBean.java
===================================================================
---
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/UserBean.java
(rev 0)
+++
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/UserBean.java 2010-07-23
10:42:23 UTC (rev 18211)
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+
+package org.richfaces.tests.metamer.bean;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+
+/**
+ * Session-scoped managed bean storing user's roles.
+ *
+ * @author Nick Belaevski, <a href="mailto:ppitonak@redhat.com">Pavol
Pitonak</a>
+ * @version $Revision$
+ */
+@ManagedBean(name = "userBean")
+@SessionScoped
+public class UserBean implements Serializable {
+
+ private String rolename;
+
+ public String getRolename() {
+ return rolename;
+ }
+
+ public void setRolename(String username) {
+ this.rolename = username;
+ }
+
+ public Principal getPrincipal() {
+ if (rolename != null) {
+ return new PrincipalImpl(rolename);
+ }
+
+ return null;
+ }
+
+ public boolean isUserInRole(String role) {
+ Principal principal = getPrincipal();
+ if (principal != null) {
+ //username & principal's name & role name are considered the
same
+ return principal.getName().equals(role);
+ }
+
+ return false;
+ }
+}
+
+class PrincipalImpl implements Principal {
+
+ private String name;
+
+ public PrincipalImpl(String name) {
+ super();
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
Property changes on:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/UserBean.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Modified: root/tests/metamer/trunk/application/src/main/webapp/WEB-INF/web.xml
===================================================================
--- root/tests/metamer/trunk/application/src/main/webapp/WEB-INF/web.xml 2010-07-23
07:21:06 UTC (rev 18210)
+++ root/tests/metamer/trunk/application/src/main/webapp/WEB-INF/web.xml 2010-07-23
10:42:23 UTC (rev 18211)
@@ -16,6 +16,14 @@
<param-name>org.richfaces.skin</param-name>
<param-value>#{richBean.skin}</param-value>
</context-param>
+ <filter>
+ <filter-name>Test Identity Filter</filter-name>
+
<filter-class>org.richfaces.tests.metamer.TestIdentityFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>Test Identity Filter</filter-name>
+ <servlet-name>Faces Servlet</servlet-name>
+ </filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
Added:
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/all.xhtml
===================================================================
---
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/all.xhtml
(rev 0)
+++
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/all.xhtml 2010-07-23
10:42:23 UTC (rev 18211)
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
xmlns:ta="http://java.sun.com/jsf/composite/testapp"
+
xmlns:rich="http://richfaces.org/rich">
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+
+ <h:outputStylesheet library="css"
name="richFunctions.css"/>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+ <f:subview id="subview">
+ <h:outputLabel value="input: " for="input" />
+ <h:inputText id="input" value="abc" />
+ </f:subview>
+
+ <br/><br/>
+
+ <h:panelGrid columns="2">
+ rich:clientId('input')
+ <h:outputText value="#{rich:clientId('input')}"
style="font-weight: bold;" />
+
+ rich:element('input')
+ <h:outputText value="#{rich:element('input')}"
style="font-weight: bold;" />
+
+ rich:component('input')
+ <h:outputText value="#{rich:component('input')}"
style="font-weight: bold;" />
+
+ rich:findComponent('input').value
+ <h:outputText
value="#{rich:findComponent('input').value}" style="font-weight:
bold;" />
+ </h:panelGrid>
+
+ <hr/>
+
+ <h:outputLabel value="Role name: " for="roleName"
/>
+ <h:inputText value="#{userBean.rolename}"
id="roleName" />
+ <br />
+ <h:commandLink value="Apply role name" />
+
+ <hr/>
+ <h:panelGrid columns="2">
+ rich:isUserInRole('admin, user')
+ <h:outputText id="outputUserInRoleAU"
value="#{rich:isUserInRole('admin, user')}" style="font-weight:
bold;" />
+
+ rich:isUserInRole('admin')
+ <h:outputText id="outputUserInRoleA"
value="#{rich:isUserInRole('admin')}" style="font-weight:
bold;" />
+
+ rich:isUserInRole('user')
+ <h:outputText id="outputUserInRoleU"
value="#{rich:isUserInRole('user')}" style="font-weight:
bold;" />
+ </h:panelGrid>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Added:
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/list.xhtml
===================================================================
---
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/list.xhtml
(rev 0)
+++
root/tests/metamer/trunk/application/src/main/webapp/components/richFunctions/list.xhtml 2010-07-23
10:42:23 UTC (rev 18211)
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:c="http://java.sun.com/jsp/jstl/core">
+
+ <h:head>
+ <title>Rich Functions</title>
+ <meta http-equiv="Content-Type" content="text/xhtml;
charset=UTF-8" />
+ <h:outputStylesheet library="css" name="list.css" />
+ </h:head>
+
+ <h:body>
+ <h:link outcome="all" value="All"
styleClass="link"/>
+ <div class="description">Page containing all RichFaces client
functions.</div>
+
+ </h:body>
+</html>
\ No newline at end of file
Added:
root/tests/metamer/trunk/application/src/main/webapp/resources/css/richFunctions.css
===================================================================