9 Replies Latest reply on Sep 28, 2007 6:59 AM by Pete Muir

    rendering of UI component based on identity roles

    Vincent LAUGIER Newbie

      Hello again,

      I want to apply rendering rules to UI components based on the identity roles ?

      for example
      only render a UI component if the user has role A
      only render a UI component if the user has role A or role B
      only render a UI component if the user has role A and role B

      I have tried the following

      rendered="#{authenticator.identity.hasRole('admin')}"
      


      but I get this error when going to the page

      /clientList.xhtml @44,175 rendered="#{authenticator.identity.hasRole('admin')}" Error Parsing: #{authenticator.identity.hasRole('admin')}

      is there someting to do with the scope of the authenticator ?

      thank you

        • 1. Re: rendering of UI component based on identity roles
          Damian Harvey Master

          try:

          rendered="#{s:hasRole('admin')}"

          Read the section on security in the user interface in the reference.

          Cheers,

          Damian.

          • 2. Re: rendering of UI component based on identity roles
            stephen.friedrich Novice

            Damian, IIRC that failed for me with an error saying functions are not supported here.

            However "#{identity.hasRole('admin'}" worked fine.

            (Though my problem might have been special as I was using the EL in a Trinidad xml menu definition.)

            • 3. Re: rendering of UI component based on identity roles
              Shane Bryzak Master

              s:hasRole() does work, if you have a situation where it doesn't then it is a bug and should be raised in JIRA.

              • 4. Re: rendering of UI component based on identity roles
                stephen.friedrich Novice

                Shane, you are right, of course - the big question is: Whose Jira?
                From my experience it is quite hard to get bugs fixed when more than one framework might be affected.
                Do you think this is a problem of MyFaces or of Seam:

                SCHWERWIEGEND: EL Expression #{s:hasRole('ADMINISTRATOR')} is invalid or returned a bad value.
                
                javax.faces.el.EvaluationException: Cannot get value for expression '#{s:hasRole('ADMINISTRATOR')}'
                 at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:405)
                 at org.apache.myfaces.trinidadinternal.menu.MenuUtils.getBoundValue(MenuUtils.java:68)
                 at org.apache.myfaces.trinidadinternal.menu.MenuUtils.evalBoolean(MenuUtils.java:102)
                 at org.apache.myfaces.trinidadinternal.menu.MenuNode.getRendered(MenuNode.java:129)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:585)
                 at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:457)
                 at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:85)
                 at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:141)
                 at com.sun.el.parser.AstValue.getValue(AstValue.java:125)
                 at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:195)
                 at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                 at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
                 at org.apache.myfaces.trinidad.bean.FacesBeanImpl.getProperty(FacesBeanImpl.java:68)
                 at org.apache.myfaces.trinidad.component.UIXComponentBase.getBooleanProperty(UIXComponentBase.java:1127)
                 at org.apache.myfaces.trinidad.component.UIXComponentBase.isRendered(UIXComponentBase.java:352)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.NavigationPaneRenderer.renderContent(NavigationPaneRenderer.java:165)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.NavigationPaneRenderer.encodeAll(NavigationPaneRenderer.java:87)
                 at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:220)
                 at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:710)
                 at org.apache.myfaces.trinidad.component.UIXCollection.encodeEnd(UIXCollection.java:525)
                 at org.apache.myfaces.trinidad.render.RenderUtils.encodeRecursive(RenderUtils.java:69)
                 at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:294)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelGroupLayoutRenderer.encodeChild(PanelGroupLayoutRenderer.java:177)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelGroupLayoutRenderer._encodeChildren(PanelGroupLayoutRenderer.java:143)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelGroupLayoutRenderer.encodeAll(PanelGroupLayoutRenderer.java:95)
                 at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:220)
                 at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:710)
                 at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:299)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelBorderLayoutRenderer._encodeAllWithSideFacets(PanelBorderLayoutRenderer.java:112)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelBorderLayoutRenderer.encodeAll(PanelBorderLayoutRenderer.java:57)
                 at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:220)
                 at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:710)
                 at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:299)
                 at org.apache.myfaces.trinidad.render.CoreRenderer.encodeAllChildren(CoreRenderer.java:316)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelPartialRootRenderer.renderContent(PanelPartialRootRenderer.java:64)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.BodyRenderer.renderContent(BodyRenderer.java:139)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelPartialRootRenderer.encodeAll(PanelPartialRootRenderer.java:119)
                 at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.BodyRenderer.encodeAll(BodyRenderer.java:79)
                 at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:220)
                 at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:710)
                 at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:252)
                 at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
                 at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:594)
                 at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:182)
                 at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
                 at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
                 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                 at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._invokeDoFilter(TrinidadFilterImpl.java:253)
                 at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:210)
                 at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:164)
                 at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                 at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
                 at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
                 at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
                 at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                 at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
                 at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
                 at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
                 at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
                 at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
                 at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                 at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:164)
                 at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
                 at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
                 at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:395)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
                 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
                 at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
                 at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                 at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
                 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
                 at java.lang.Thread.run(Thread.java:595)
                Caused by: javax.faces.el.ReferenceSyntaxException: Functions not supported in expressions. Function: s:hasRole
                 at org.apache.myfaces.el.ValueBindingImpl$1.resolveFunction(ValueBindingImpl.java:74)
                 at org.apache.commons.el.FunctionInvocation.evaluate(FunctionInvocation.java:148)
                 at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:386)
                 ... 87 more
                


                • 5. Re: rendering of UI component based on identity roles
                  Pete Muir Master

                  Guys, please post versions of the involved libraries :)

                  • 6. Re: rendering of UI component based on identity roles
                    stephen.friedrich Novice

                    Sorry, Pete your're right of course:
                    Seam 1.2.1, MyFaces 1.1.5, Trinidad 1.0.2, Facelets from VCS about two weeks old (because of https://facelets.dev.java.net/issues/show_bug.cgi?id=239).
                    On Tomcat 5.5.17.

                    • 7. Re: rendering of UI component based on identity roles
                      Pete Muir Master

                      Looks to me like somehow you've got commons-el in the stack there when we've always used the RI with Seam.

                      The security functions are tied into Seam using a custom FunctionMapper, which, I would suspect, is not getting called because of commons-el being in the picture.

                      • 8. Re: rendering of UI component based on identity roles
                        stephen.friedrich Novice

                        Phew - and again I am deep into the foreign land of JSF internals.

                        Any idea what could have caused this?
                        I see that in MyFaces
                        ApplicationImpl.createValueBinding(String)
                        is hardcoded to return an instance of
                        org.apache.myfaces.el.ValueBindingImpl

                        Is this already incorrect? Or should the correct implementation be selected when valueBinding.getValue(FacesContext) is called?

                        • 9. Re: rendering of UI component based on identity roles
                          Pete Muir Master

                          Shane knows better than me, but I think function handling is quite broken in myfaces 1.1.x

                          So I suggest

                          1) Try to get commons-el out of the stack trace
                          2) Consider switching to RI 1.2 if you can.