isuserinroletag.java
来自「jakarta-taglibs」· Java 代码 · 共 99 行
JAVA
99 行
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.taglibs.request;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
* JSP Tag <b>isuserinrole</b>, used to determine if HttpServletRequest
* is for an authenticated user in a role.
* <p>
* Includes the body of the tag if an authenticated user in a role.
* <p>
* Requires that the attribute <b>role</b> be set.
* <p>
* You can set the optional tag attribute <b>value</b> to <i>true</i> or
* <i>false</i>. The body of the tag is included if isuserinrole matches
* the value.
* <p>
* JSP Tag Lib Descriptor
* <p><pre>
* <name>isuserinrole</name>
* <tagclass>org.apache.taglibs.request.IsUserInRoleTag</tagclass>
* <bodycontent>JSP</bodycontent>
* <info>Test whether the remote user is in a role.</info>
* <attribute>
* <name>role</name>
* <required>yes</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* <attribute>
* <name>value</name>
* <required>false</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* </pre>
*
* @author Glenn Nielsen
*/
public class IsUserInRoleTag extends TagSupport
{
private boolean value = true;
private String role = null;
/**
* Determines whether remote user is in a role.
*
* @return SKIP_BODY if isuserinrole doesn't match value, EVAL_BODY_include if isuserinrole matches value
*/
public final int doStartTag() throws JspException
{
boolean result = ((HttpServletRequest)pageContext.getRequest()).isUserInRole(role);
if( value == result )
return EVAL_BODY_INCLUDE;
return SKIP_BODY;
}
/**
* Set the optional tag attribute <b>value</b> to true or false.
*
* @param boolean true or false
*/
public final void setValue(boolean value)
{
this.value = value;
}
/**
* Set the required tag attribute <b>role</b> to the name
* of the role you wish to test remote user for.
*
* @param String role name
*/
public final void setRole(String str)
{
role = str;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?