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.turbine.util.RunData;
025import org.apache.velocity.context.Context;
026
027/**
028 * Support Turbine 2 screens
029 *
030 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
031 * @deprecated Use VelocitySecureScreen directly
032 */
033@Deprecated
034public abstract class LegacyVelocitySecureScreen
035        extends LegacyVelocityScreen
036{
037    /**
038     * Implement this to add information to the context.
039     *
040     * @param data Turbine information.
041     * @param context Context for web pages.
042     * @throws Exception a generic exception.
043     */
044    @Override
045    protected abstract void doBuildTemplate(RunData data, Context context)
046            throws Exception;
047
048    /**
049     * This method overrides the method in VelocityScreen to
050     * perform a security check first.
051     *
052     * @param pipelineData Turbine information.
053     * @throws Exception a generic exception.
054     */
055    @Override
056    protected void doBuildTemplate(PipelineData pipelineData)
057        throws Exception
058    {
059        if (isAuthorized(pipelineData.getRunData()))
060        {
061            doBuildTemplate(pipelineData.getRunData(), velocity.getContext(pipelineData));
062        }
063    }
064
065    /**
066     * Implement this method to perform the security check needed.
067     * You should set the template in this method that you want the
068     * user to be sent to if they're unauthorized.  See the
069     * VelocitySecurityCheck utility.
070     *
071     * @param data Turbine information.
072     * @return True if the user is authorized to access the screen.
073     * @throws Exception a generic exception.
074     */
075    protected abstract boolean isAuthorized(RunData data)
076            throws Exception;
077}