    001package org.apache.turbine.modules.screens;
    002
    003/*
    004 * Licensed to the Apache Software Foundation (ASF) under one
    005 * or more contributor license agreements.  See the NOTICE file
    006 * distributed with this work for additional information
    007 * regarding copyright ownership.  The ASF licenses this file
    008 * to you under the Apache License, Version 2.0 (the
    009 * "License"); you may not use this file except in compliance
    010 * with the License.  You may obtain a copy of the License at
    011 *
    012 *   http://www.apache.org/licenses/LICENSE-2.0
    013 *
    014 * Unless required by applicable law or agreed to in writing,
    015 * software distributed under the License is distributed on an
    016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    017 * KIND, either express or implied.  See the License for the
    018 * specific language governing permissions and limitations
    019 * under the License.
    020 */
    021
    022
    023import org.apache.turbine.pipeline.PipelineData;
    024import org.apache.velocity.context.Context;
    025
    026/**
    027 * VelocitySecureScreen
    028 *
    029 * Always performs a Security Check that you've defined before
    030 * executing the doBuildTemplate().  You should extend this class and
    031 * add the specific security check needed.  If you have a number of
    032 * screens that need to perform the same check, you could make a base
    033 * screen by extending this class and implementing the isAuthorized().
    034 * Then each screen that needs to perform the same check could extend
    035 * your base screen.
    036 *
    037 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
    038 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    039 * @version $Id: VelocitySecureScreen.java 1773378 2016-12-09 13:19:59Z tv $
    040 */
    041public abstract class VelocitySecureScreen
    042        extends VelocityScreen
    043{
    044    /**
    045     * Implement this to add information to the context.
    046     *
    047     * @param pipelineData Turbine information.
    048     * @param context Context for web pages.
    049     * @throws Exception a generic exception.
    050     */
    051    @Override
    052    protected abstract void doBuildTemplate(PipelineData pipelineData,
    053                                            Context context)
    054            throws Exception;
    055
    056    /**
    057     * This method overrides the method in VelocityScreen to
    058     * perform a security check first.
    059     *
    060     * @param pipelineData Turbine information.
    061     * @throws Exception a generic exception.
    062     */
    063    @Override
    064    protected void doBuildTemplate(PipelineData pipelineData)
    065        throws Exception
    066    {
    067        if (isAuthorized(pipelineData))
    068        {
    069            doBuildTemplate(pipelineData, velocity.getContext(pipelineData));
    070        }
    071    }
    072
    073    /**
    074     * Implement this method to perform the security check needed.
    075     * You should set the template in this method that you want the
    076     * user to be sent to if they're unauthorized.  See the
    077     * VelocitySecurityCheck utility.
    078     *
    079     * @param pipelineData Turbine information.
    080     * @return True if the user is authorized to access the screen.
    081     * @throws Exception a generic exception.
    082     */
    083    protected abstract boolean isAuthorized(PipelineData pipelineData)
    084            throws Exception;
    085}