Version 2


    Render controls depending on the user role.


    Use #{rich:isUserInRole(object) to identify the user role and rendered attribute to manage  controls rendering.


    The #{rich:isUserInRole(object) function lets you identify the whether the logged in user belongs to a certain user role. The function returns “true” if the logged in user has the role passed to the function.  This can be useful when you work with user-role dependent layout.  By setting the rendered attribute of any JSF/RichFaces component to true/false you can include/omit the controls from the layout.


    Let’s create a protected area (let it be admin folder) in an application and place a file that will have user-role dependent layout:  a text area will be displayed only to the users with   “amin” role and a plain text with no editing option will be shown to the users that belongs to the “user” user role.
    First we need to create basic authentification.
    Add this code to your web.xml:


                   <web-resource-name>Protected Site</web-resource-name>
                   <!-- Roles that have access -->
         <!-- BASIC authentication -->
              <realm-name>Basic Authentication</realm-name>
         <!-- Define security roles -->


    Then you need to set up your server. In this example we will show how to configure Tomcat server.
    Define user roles, logings and passwords in Tomcat_Installation_folder\conf\tomcat-users.xml:

    <role rolename="user"/>
    <role rolename="admin"/>
    <user name="user" password="123" roles="user" />
    <user name="admin" password="456" roles="admin" />

    And add this line of code to the Tomcat_Installation_folder\conf\ server.xml in the <Engine> element:


    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

    As you could see the admin folder is restricted in the project.
    Create a view page in the amin folder and add this code to the page:

    <h:form rendered="#{rich:isUserInRole('admin')}" >
    <rich:editor value="#{editor.pageText}" rendered="#{rich:isUserInRole('admin')}"/>
    <h:commandButton value="Save" />
    <h:outputText value="#{editor.pageText}" rendered="#{rich:isUserInRole('user')}" />

    Now you can login with as amin to see the editor, while if you login as a user you will see just a text without editing option.