001: package org.tigris.scarab.actions.admin;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: // JDK classes
050: // Turbine Stuff
051: import org.apache.turbine.TemplateContext;
052: import org.apache.turbine.RunData;
053: import org.apache.turbine.tool.IntakeTool;
054: import org.apache.fulcrum.intake.model.Group;
055: import org.apache.fulcrum.security.TurbineSecurity;
056: import org.apache.fulcrum.security.entity.Permission;
057: import org.apache.fulcrum.security.util.EntityExistsException;
058:
059: // Scarab Stuff
060: import org.tigris.scarab.om.ScarabUser;
061: import org.tigris.scarab.om.ScarabUserManager;
062: import org.tigris.scarab.tools.ScarabLocalizationTool;
063: import org.tigris.scarab.util.ScarabConstants;
064: import org.tigris.scarab.actions.base.RequireLoginFirstAction;
065:
066: /**
067: * This class is responsible for dealing with the permission management
068: * Action(s).
069: *
070: * @author <a href="mailto:dr@bitonic.com">Douglas B. Robertson</a>
071: * @version $Id: ManagePermissions.java 10239 2006-08-05 14:28:42Z pledbrook $
072: */
073: public class ManagePermissions extends RequireLoginFirstAction {
074:
075: /**
076: *
077: */
078: public void doGotoaddpermission(RunData data,
079: TemplateContext context) throws Exception {
080: setTarget(data, "admin,AddPermission.vm");
081: }
082:
083: /**
084: *
085: */
086: public void doGotodeletepermission(RunData data,
087: TemplateContext context) throws Exception {
088: setTarget(data, "admin,DeletePermission.vm");
089: }
090:
091: /**
092: * Manages the adding of a new role when the 'Add Role' button is pressed.
093: */
094: public void doAddpermission(RunData data, TemplateContext context)
095: throws Exception {
096: IntakeTool intake = getIntakeTool(context);
097: ScarabLocalizationTool l10n = getLocalizationTool(context);
098:
099: if (intake.isAllValid()) {
100: Object user = data.getUser().getTemp(
101: ScarabConstants.SESSION_REGISTER);
102:
103: Group editPermission = null;
104: if (user != null && user instanceof ScarabUser) {
105: editPermission = intake.get("EditPermission",
106: ((ScarabUser) user).getQueryKey(), false);
107: } else {
108: editPermission = intake.get("EditPermission",
109: IntakeTool.DEFAULT_KEY, false);
110: }
111: String name = editPermission.get("PermissionName")
112: .toString();
113:
114: try {
115: Permission permission = TurbineSecurity
116: .getNewPermission(null);
117: permission.setName(name);
118:
119: TurbineSecurity.addPermission(permission);
120: data.getParameters().setString("lastAction",
121: "addedpermission");
122: String msg = l10n.format("PermissionCreated", name);
123: getScarabRequestTool(context).setConfirmMessage(msg);
124: } catch (EntityExistsException eee) {
125: String msg = l10n.format("PermissionExists", name);
126: getScarabRequestTool(context).setConfirmMessage(msg);
127: data.getParameters().setString("lastAction", "");
128: }
129: }
130: }
131:
132: /**
133: * This manages the clicking of the 'Confirm Delete' button and actually
134: * deletes the Permission.
135: */
136: public void doDeletepermission(RunData data, TemplateContext context)
137: throws Exception {
138: String name = data.getParameters().getString("name");
139: Permission permission = TurbineSecurity.getPermission(name);
140: TurbineSecurity.removePermission(permission);
141:
142: ScarabUserManager.getMethodResult().clear();
143:
144: ScarabLocalizationTool l10n = getLocalizationTool(context);
145: String msg = l10n.format("PermissionDeleted", name);
146: getScarabRequestTool(context).setConfirmMessage(msg);
147: setTarget(data, data.getParameters().getString(
148: ScarabConstants.NEXT_TEMPLATE,
149: "admin,ManagePermissions.vm"));
150:
151: }
152:
153: /**
154: * This manages clicking the Cancel button
155: */
156: public void doCancel(RunData data, TemplateContext context)
157: throws Exception {
158: setTarget(data, data.getParameters().getString(
159: ScarabConstants.CANCEL_TEMPLATE, "admin,AdminIndex.vm"));
160: }
161:
162: /**
163: * calls doCancel()
164: */
165: public void doPerform(RunData data, TemplateContext context)
166: throws Exception {
167: doCancel(data, context);
168: }
169: }
|