Monday, May 10, 2010

Bit #17 - Using the securityContext bean in a JSF page

To acess the user's authentication information from within a JSF page, use the securityContext bean and any of its available methods. For instance, using Expression Language (EL), the following will return true/false indicating whether the user is authenticated or not: #{securityContext.authenticated}. Similarly, to determine whether the user has been assigned a specific role, use the following EL snippet #{securityContext.userInRole['SomeRole']}. It will return true if the user has been assigned the specific role.


    // in the context of a JSF page

    <af:commandLink id="login_logout" action = "#{securityContext.authenticated ? 'logout' : 'login'}" text="#{securityContext.authenticated ? 'Logout' : 'Login'}/>

    <af:commandToolbarButton id="delete"  actionListener="#{backingBean.delete}" disabled="#{securityContext.userInRole['CanDelete']==false}" text="Delete"/>


JSF Page

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...