View Javadoc

1   /*
2    * Copyright 2004 Anite - Central Government Division
3    * http://www.anite.com/publicsector
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License. You may obtain a copy of
7    * the License at
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package com.anite.antelope.modules.actions;
18  
19  import org.apache.fulcrum.security.entity.Permission;
20  import org.apache.turbine.modules.actions.VelocitySecureAction;
21  import org.apache.turbine.services.velocity.TurbineVelocity;
22  import org.apache.turbine.util.RunData;
23  import org.apache.velocity.context.Context;
24  
25  import com.anite.antelope.modules.tools.SecurityTool;
26  
27  
28  /***
29   *
30   * @author <a href="mailTo:michael.jones@anite.com">Michael.Jones</a>
31   *
32   */
33  public abstract class PermissionAction extends VelocitySecureAction  {
34  
35      /* (non-Javadoc)
36       * @see org.apache.turbine.modules.screens.VelocitySecureScreen#isAuthorized(org.apache.turbine.util.RunData)
37       */
38      protected boolean isAuthorized(RunData data) throws Exception {
39          Context context = TurbineVelocity.getContext(data);
40          SecurityTool security = (SecurityTool) context.get(SecurityTool.DEFAULT_TOOL_NAME);
41          
42          if (security.hasPermission(data, pagePermission())) {
43              data.setScreenTemplate("Login.vm");
44              return false;
45          } else {
46              return true;
47          }
48      }
49      
50      /***
51       * You must implment this method to define a permission that
52       * a user complete the action
53       * @return
54       */
55      public abstract Permission pagePermission();
56  
57  }