/* JSPWiki - a JSP-based WikiWiki clone. Copyright (C) 2001-2004 Janne Jalkanen (Janne.Jalkanen@iki.fi) (C) 2004 Foster Schucker (Foster at Schucker.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.ecyrd.jspwiki.tags; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTagSupport; import javax.servlet.http.*; import com.ecyrd.jspwiki.plugin.Auth; import org.apache.log4j.Category; /** * This tag allows us to check some user authorization * Auth allow="user,role list" deny="user,role list" * This is the same as the AuthPlugin * * @author Foster Schucker * @since 2.0.54 */ public class AuthTag extends BodyTagSupport { static Category log = Category.getInstance( TranslateTag.class ); protected String m_allow; protected String m_deny; public void setAllow( String allow ) { m_allow = allow; } public String getAllow() { return m_allow; } public void setDeny( String deny ) { m_deny = deny; } public String getDeny() { return m_deny; } public final int doStartTag() throws JspException { try { // nothing to do } catch (Exception ex) { throw new JspException ("Auth doStartTag fail"); } finally { return EVAL_BODY_TAG; } } public final int doAfterBody() throws JspException { try { // nothing to do } catch (Exception ex) { throw new JspException ("Auth doAfterBody fail"); } finally { return SKIP_BODY; } } public final int doEndTag() throws JspException { JspWriter out = pageContext.getOut(); boolean allow = true; // let then see it HttpServletRequest req = (HttpServletRequest)pageContext.getRequest(); try { // out.print(getAllow()+"
"+getDeny()+"
"); allow = Auth.userInList(req,getAllow(),req.getRemoteUser()); if (Auth.userInList(req,getDeny(),req.getRemoteUser())) { allow = false; } if (allow){ BodyContent body = getBodyContent(); out.println(body.getString()); } } catch (Exception ex) { throw new JspException ("Auth doEndTag fail"); } finally { return EVAL_PAGE; } } }