You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matt Raible <ma...@yahoo.com> on 2001/06/19 19:06:47 UTC
Tag Libraries for Checking Role?
I want to show/hide links in a page based on the role that an authenticated
user is in. Is it possible to write the following with a TagLib?
<%@page contentType="text/html"%>
<%@page import="java.security.Principal" %>
<html>
<head><title>JSP Page</title></head>
<body>
<%
Principal principal = request.getUserPrincipal();
if( principal == null ) {
%>
There is no user principal (null)<p>
<%
} else {
%>
User Principal is: <%= principal.getName() %>
<%
}
%>
<P>Auth type is: <%= request.getAuthType() %>
<P>Request is secure: <%= request.isSecure() %>
<P>User is in role1: <%= request.isUserInRole("role1") %>
<P>User is in role2: <%= request.isUserInRole("role2") %>
<P>User is in Employee: <%= request.isUserInRole("Employee") %>
</body>
</html>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Re: Tag Libraries for Checking Role?
Posted by Mike Thompson <mr...@instanton.com>.
<logic:present role="ADMIN">
html for administrator
</logic:present>
<logic:notPresent role="ADMIN">
non admin links
</logic:notPresent>
----- Original Message -----
From: "Matt Raible" <ma...@yahoo.com>
To: <st...@jakarta.apache.org>
Sent: Tuesday, June 19, 2001 12:06 PM
Subject: Tag Libraries for Checking Role?
> I want to show/hide links in a page based on the role that an
authenticated
> user is in. Is it possible to write the following with a TagLib?
>
> <%@page contentType="text/html"%>
> <%@page import="java.security.Principal" %>
> <html>
> <head><title>JSP Page</title></head>
> <body>
>
> <%
> Principal principal = request.getUserPrincipal();
> if( principal == null ) {
> %>
> There is no user principal (null)<p>
> <%
> } else {
> %>
> User Principal is: <%= principal.getName() %>
> <%
> }
> %>
> <P>Auth type is: <%= request.getAuthType() %>
> <P>Request is secure: <%= request.isSecure() %>
> <P>User is in role1: <%= request.isUserInRole("role1") %>
> <P>User is in role2: <%= request.isUserInRole("role2") %>
> <P>User is in Employee: <%= request.isUserInRole("Employee") %>
> </body>
> </html>
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com