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.screens.security;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.apache.fulcrum.security.PermissionManager;
21  import org.apache.fulcrum.security.RoleManager;
22  import org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup;
23  import org.apache.fulcrum.security.model.dynamic.entity.DynamicRole;
24  import org.apache.fulcrum.security.util.PermissionSet;
25  import org.apache.fulcrum.security.util.RoleSet;
26  import org.apache.turbine.util.RunData;
27  import org.apache.velocity.context.Context;
28  
29  import com.anite.antelope.modules.screens.SecureScreen;
30  import com.anite.antelope.modules.tools.SecurityTool;
31  import com.anite.antelope.utils.PermissionHelper;
32  import com.anite.penguin.form.Field;
33  import com.anite.penguin.modules.tools.FormTool;
34  
35  /***
36   * @author <a href="mailTo:michael.jones@anite.com">Michael.Jones </a>
37   *  
38   */
39  public class Roles extends SecureScreen {
40  
41      /*
42       * (non-Javadoc)
43       * 
44       * @see org.apache.turbine.modules.screens.VelocitySecureScreen#doBuildTemplate(org.apache.turbine.util.RunData,
45       *      org.apache.velocity.context.Context)
46       */
47      protected void doBuildTemplate(RunData data, Context context)
48              throws Exception {
49          //      Retrieve the form tool that has validated the input
50          FormTool form = (FormTool) context.get(FormTool.DEFAULT_TOOL_NAME);
51          
52          // User the security tool to get all the managers needed
53          SecurityTool security = (SecurityTool) context.get(SecurityTool.DEFAULT_TOOL_NAME);
54          RoleManager roleManager = security.getRoleManager();
55          PermissionManager permissionManager = security.getPermissionManager();   
56  
57          DynamicGroup dynGroup;
58          RoleSet rs;
59          Field role;
60  
61          context.put("allocatedroles", roleManager.getAllRoles());
62  
63          role = (Field) form.getFields().get("allocatedroles");
64  
65          // if a role has been selected populate the permissions
66          if (!StringUtils.isEmpty(role.getValue())) {
67              DynamicRole dynRole;
68              PermissionSet ps;
69  
70              dynRole = (DynamicRole) roleManager.getRoleById(Long.valueOf(role
71                      .getValue()));
72  
73              ps = dynRole.getPermissions();
74  
75              context.put("selectedrole", dynRole);
76              context.put("allocatedperms", ps);
77              context.put("availableperms", PermissionHelper.permissionSetXOR(ps,
78                      permissionManager.getAllPermissions()));
79  
80              role = (Field) form.getFields().get("allocatedroles");
81          }
82      }
83  }