| /* |
| * Copyright 2005-2008 Les Hazlewood, Jeremy Haile |
| * |
| * 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.jsecurity.web.tags; |
| |
| import javax.servlet.jsp.JspException; |
| import javax.servlet.jsp.tagext.TagSupport; |
| |
| /** |
| * @since 0.1 |
| * @author Les Hazlewood |
| * @author Jeremy Haile |
| */ |
| public abstract class PermissionTag extends SecureTag { |
| |
| private String permission = null; |
| |
| public PermissionTag() { |
| } |
| |
| public String getPermission() { |
| return permission; |
| } |
| |
| public void setPermission(String permission) { |
| this.permission = permission; |
| } |
| |
| protected void verifyAttributes() throws JspException { |
| String permission = getPermission(); |
| |
| if ( permission == null || permission.length() == 0 ) { |
| String msg = "The 'permission' tag attribute must be set."; |
| throw new JspException( msg ); |
| } |
| } |
| |
| public int onDoStartTag() throws JspException { |
| |
| String p = getPermission(); |
| |
| boolean show = showTagBody( p ); |
| if ( show ) { |
| return TagSupport.EVAL_BODY_INCLUDE; |
| } else { |
| return TagSupport.SKIP_BODY; |
| } |
| } |
| |
| protected boolean isPermitted( String p ) { |
| return getSubject() != null && getSubject().isPermitted( p ); |
| } |
| |
| protected abstract boolean showTagBody( String p ); |
| |
| } |