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.security;
18  
19  import org.apache.fulcrum.security.RoleManager;
20  import org.apache.fulcrum.security.SecurityService;
21  import org.apache.fulcrum.security.model.dynamic.DynamicModelManager;
22  import org.apache.fulcrum.security.model.dynamic.entity.DynamicRole;
23  import org.apache.turbine.util.RunData;
24  import org.apache.velocity.context.Context;
25  
26  import com.anite.antelope.modules.actions.SecureAction;
27  import com.anite.antelope.modules.tools.SecurityTool;
28  import com.anite.penguin.form.Field;
29  import com.anite.penguin.modules.tools.FieldMap;
30  import com.anite.penguin.modules.tools.FormTool;
31  
32  /***
33   * 
34   * @author <a href="mailTo:michael.jones@anite.com">Michael.Jones </a>
35   *  
36   */
37  public class DeleteRole extends SecureAction {
38  
39  	/*
40  	 * (non-Javadoc)
41  	 * 
42  	 * @see org.apache.turbine.modules.actions.VelocitySecureAction#doPerform(org.apache.turbine.util.RunData,
43  	 *      org.apache.velocity.context.Context)
44  	 */
45  	public void doPerform(RunData data, Context context) throws Exception {
46  		FormTool form = (FormTool) context.get(FormTool.DEFAULT_TOOL_NAME);
47  		SecurityTool security = (SecurityTool) context
48  				.get(SecurityTool.DEFAULT_TOOL_NAME);
49  
50  		if (form.isAllValid()) {
51  			// Declare variables
52  			SecurityService securityService;
53  			RoleManager roleManager;			
54  			DynamicModelManager modelManager;
55  			FieldMap fieldMap;
56  			Field roleField;
57  			DynamicRole role;
58  
59  			roleManager = security.getRoleManager();
60  			modelManager = (DynamicModelManager) security.getModelManager();
61  			
62  
63  			fieldMap = form.getFields();
64  			roleField = (Field) fieldMap.get("allocatedroles");
65  			role = (DynamicRole) roleManager.getRoleById(Long
66  					.valueOf(roleField.getValue()));
67  
68  			modelManager.revokeAll(role);
69  			roleManager.removeRole(role);
70  			// need to remove the username from the username from
71  			// the data so it isnt tried to be selected in the screen class
72  			roleField.setValue("");
73  		}
74  	}
75  }
76