<anyxmlelement xmlns:sec="omnifaces.security"/>
| Info | Value |
|---|---|
| ID (tag prefix) | sec |
| URI | omnifaces.security |
| Tag | Description |
|---|---|
| authorize |
The Usage
To use the security taglib, declare the <html xmlns:sec="omnifaces.security">
The Single role check
Use the
<sec:authorize role="ADMIN">
<h:link value="Admin Panel" outcome="/admin" />
</sec:authorize>
Any-of-roles check
Use the
<sec:authorize anyRole="ADMIN, MODERATOR, EDITOR">
<h:link value="Content Management" outcome="/cms" />
</sec:authorize>
All-of-roles check
Use the
<sec:authorize allRoles="ADMIN, AUDITOR">
<h:link value="Audit Logs" outcome="/audit" />
</sec:authorize>
Exposing authorization result
The optional
<sec:authorize role="ADMIN" var="isAdmin" />
<h:panelGroup rendered="#{isAdmin}">
<h:link value="Admin Panel" outcome="/admin" />
</h:panelGroup>
<h:outputText value="Welcome, Administrator!" rendered="#{isAdmin}" />
The variable is always set regardless of whether the content inside the tag is rendered or not. Configuration
This tag requires |
| isAnonymous |
The Usage
To use the security taglib, declare the <html xmlns:sec="omnifaces.security">
The Example: Login form for anonymous usersDisplay a login link only when the user is not authenticated:
<sec:isAnonymous>
<h:link value="Login" outcome="/login" />
</sec:isAnonymous>
Example: Welcome message for guestsShow a different welcome message for anonymous users:
<sec:isAnonymous>
<h:outputText value="Welcome, Guest! Please login to access all features." />
</sec:isAnonymous>
Example: Combined with isAuthenticated
Use together with
<sec:isAnonymous>
<h:form>
<h:outputLabel for="username" value="Username:" />
<h:inputText id="username" value="#{loginBean.username}" />
<h:commandButton value="Login" action="#{loginBean.login}" />
</h:form>
</sec:isAnonymous>
<sec:isAuthenticated>
<h:outputText value="Welcome back, #{request.remoteUser}!" />
</sec:isAuthenticated>
Implementation details
This tag checks if Configuration
This tag requires |
| isAuthenticated |
The Usage
To use the security taglib, declare the <html xmlns:sec="omnifaces.security">
The Example: Welcome message for authenticated usersDisplay a personalized welcome message only when the user is authenticated:
<sec:isAuthenticated>
<h:outputText value="Welcome back, #{request.remoteUser}!" />
</sec:isAuthenticated>
Example: Logout button for authenticated usersShow a logout button only when the user is authenticated:
<sec:isAuthenticated>
<h:form>
<h:commandButton value="Logout" action="#{loginBean.logout}" />
</h:form>
</sec:isAuthenticated>
Example: User-specific navigationDisplay navigation links that are only available to authenticated users:
<sec:isAuthenticated>
<ul>
<li><h:link value="My Profile" outcome="/profile" /></li>
<li><h:link value="Settings" outcome="/settings" /></li>
<li><h:link value="My Orders" outcome="/orders" /></li>
</ul>
</sec:isAuthenticated>
Example: Combined with isAnonymous
Use together with
<sec:isAnonymous>
<h:link value="Login" outcome="/login" />
<h:link value="Register" outcome="/register" />
</sec:isAnonymous>
<sec:isAuthenticated>
<h:link value="Profile" outcome="/profile" />
<h:form>
<h:commandLink value="Logout" action="#{loginBean.logout}" />
</h:form>
</sec:isAuthenticated>
Example: Combined with authorize
Use together with
<sec:isAuthenticated>
<h:link value="Dashboard" outcome="/dashboard" />
<sec:authorize role="ADMIN">
<h:link value="Admin Panel" outcome="/admin" />
</sec:authorize>
</sec:isAuthenticated>
Implementation details
This tag checks if Configuration
This tag requires |
Output generated by Vdldoc View Declaration Language Documentation Generator.