1 package org.tigris.scarab.actions.admin; 2 3 48 49 50 52 import org.apache.turbine.TemplateContext; 54 import org.apache.turbine.RunData; 55 import org.apache.turbine.tool.IntakeTool; 56 import org.apache.fulcrum.intake.model.Group; 57 import org.apache.fulcrum.security.TurbineSecurity; 58 import org.apache.fulcrum.security.entity.Permission; 59 import org.apache.fulcrum.security.util.EntityExistsException; 60 61 62 import org.tigris.scarab.om.ScarabUser; 64 import org.tigris.scarab.tools.ScarabLocalizationTool; 65 import org.tigris.scarab.util.ScarabConstants; 66 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 67 68 75 public class ManagePermissions extends RequireLoginFirstAction 76 { 77 78 81 public void doGotoaddpermission(RunData data, TemplateContext context) 82 throws Exception 83 { 84 setTarget(data, "admin,AddPermission.vm"); 85 } 86 87 90 public void doGotodeletepermission(RunData data, TemplateContext context) 91 throws Exception 92 { 93 setTarget(data, "admin,DeletePermission.vm"); 94 } 95 96 99 public void doAddpermission(RunData data, TemplateContext context) 100 throws Exception 101 { 102 IntakeTool intake = getIntakeTool(context); 103 ScarabLocalizationTool l10n = getLocalizationTool(context); 104 105 if (intake.isAllValid()) 106 { 107 Object user = data.getUser().getTemp(ScarabConstants.SESSION_REGISTER); 108 109 Group editPermission = null; 110 if (user != null && user instanceof ScarabUser) 111 { 112 editPermission = intake.get("EditPermission", ((ScarabUser)user).getQueryKey(), false); 113 } 114 else 115 { 116 editPermission = intake.get("EditPermission", IntakeTool.DEFAULT_KEY, false); 117 } 118 String name = editPermission.get("PermissionName").toString(); 119 120 try 121 { 122 Permission permission = TurbineSecurity.getNewPermission(null); 123 permission.setName(name); 124 125 TurbineSecurity.addPermission(permission); 126 data.getParameters().setString("lastAction", "addedpermission"); 127 String msg = l10n.format("PermissionCreated", name); 128 getScarabRequestTool(context).setConfirmMessage(msg); 129 } 130 catch (EntityExistsException eee) 131 { 132 String msg = l10n.format("PermissionExists", name); 133 getScarabRequestTool(context).setConfirmMessage(msg); 134 data.getParameters().setString("lastAction",""); 135 } 136 } 137 } 138 139 143 public void doDeletepermission(RunData data, TemplateContext context) 144 throws Exception 145 { 146 String name = data.getParameters().getString("name"); 147 Permission permission = TurbineSecurity.getPermission(name); 148 TurbineSecurity.removePermission(permission); 149 150 ScarabLocalizationTool l10n = getLocalizationTool(context); 151 String msg = l10n.format("PermissionDeleted", name); 152 getScarabRequestTool(context).setConfirmMessage(msg); 153 setTarget(data, data.getParameters().getString(ScarabConstants.NEXT_TEMPLATE, "admin,ManagePermissions.vm")); 154 155 } 156 157 158 161 public void doCancel(RunData data, TemplateContext context) throws Exception 162 { 163 setTarget(data, data.getParameters() 164 .getString(ScarabConstants.CANCEL_TEMPLATE, "admin,AdminIndex.vm")); 165 } 166 167 170 public void doPerform(RunData data, TemplateContext context) 171 throws Exception 172 { 173 doCancel(data,context); 174 } 175 } 176 | Popular Tags |