001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/authz/tags/sakai_2-4-1/authz-tool/tool/src/java/org/sakaiproject/authz/tool/PermissionsHelperAction.java $
003: * $Id: PermissionsHelperAction.java 13672 2006-08-15 03:22:07Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.authz.tool;
021:
022: import java.io.IOException;
023:
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026:
027: import org.sakaiproject.authz.api.PermissionsHelper;
028: import org.sakaiproject.cheftool.Context;
029: import org.sakaiproject.cheftool.RunData;
030: import org.sakaiproject.cheftool.VelocityPortlet;
031: import org.sakaiproject.cheftool.VelocityPortletPaneledAction;
032: import org.sakaiproject.event.api.SessionState;
033: import org.sakaiproject.util.ResourceLoader;
034: import org.sakaiproject.tool.api.Tool;
035: import org.sakaiproject.tool.api.ToolException;
036: import org.sakaiproject.tool.api.ToolSession;
037: import org.sakaiproject.tool.cover.SessionManager;
038: import org.sakaiproject.tool.cover.ToolManager;
039:
040: /**
041: * This is a helper interface to the Permissions tool.
042: */
043: public class PermissionsHelperAction extends
044: VelocityPortletPaneledAction {
045: private static ResourceLoader rb = new ResourceLoader("authz-tool");
046:
047: private static final String STARTED = "sakaiproject.permissions.started";
048:
049: protected void toolModeDispatch(String methodBase,
050: String methodExt, HttpServletRequest req,
051: HttpServletResponse res) throws ToolException {
052: SessionState sstate = getState(req);
053: ToolSession toolSession = SessionManager
054: .getCurrentToolSession();
055:
056: String mode = (String) sstate
057: .getAttribute(PermissionsAction.STATE_MODE);
058: Object started = toolSession.getAttribute(STARTED);
059:
060: if (mode == null && started != null) {
061: toolSession.removeAttribute(STARTED);
062: Tool tool = ToolManager.getCurrentTool();
063:
064: String url = (String) SessionManager
065: .getCurrentToolSession().getAttribute(
066: tool.getId() + Tool.HELPER_DONE_URL);
067:
068: SessionManager.getCurrentToolSession().removeAttribute(
069: tool.getId() + Tool.HELPER_DONE_URL);
070:
071: try {
072: res.sendRedirect(url);
073: } catch (IOException e) {
074: Log.warn("chef", this + " : ", e);
075: }
076: return;
077: }
078:
079: super .toolModeDispatch(methodBase, methodExt, req, res);
080: }
081:
082: /**
083: * Allow extension classes to control which build method gets called for this pannel
084: * @param panel
085: * @return
086: */
087: protected String panelMethodName(String panel) {
088: // we are always calling buildMainPanelContext
089: return "buildMainPanelContext";
090: }
091:
092: /**
093: * Default is to use when Portal starts up
094: */
095: public String buildMainPanelContext(VelocityPortlet portlet,
096: Context context, RunData rundata, SessionState sstate) {
097: String mode = (String) sstate
098: .getAttribute(PermissionsAction.STATE_MODE);
099:
100: if (mode == null) {
101: initHelper(portlet, context, rundata, sstate);
102: }
103:
104: String template = PermissionsAction.buildHelperContext(portlet,
105: context, rundata, sstate);
106: if (template == null) {
107: addAlert(sstate, rb.getString("java.alert.prbset"));
108: } else {
109: return template;
110: }
111:
112: return null;
113: }
114:
115: protected void initHelper(VelocityPortlet portlet, Context context,
116: RunData rundata, SessionState state) {
117: ToolSession toolSession = SessionManager
118: .getCurrentToolSession();
119:
120: String prefix = (String) toolSession
121: .getAttribute(PermissionsHelper.PREFIX);
122: String targetRef = (String) toolSession
123: .getAttribute(PermissionsHelper.TARGET_REF);
124: String description = (String) toolSession
125: .getAttribute(PermissionsHelper.DESCRIPTION);
126: String rolesRef = (String) toolSession
127: .getAttribute(PermissionsHelper.ROLES_REF);
128: if (rolesRef == null)
129: rolesRef = targetRef;
130:
131: toolSession.setAttribute(STARTED, new Boolean(true));
132:
133: // setup for editing the permissions of the site for this tool, using the roles of this site, too
134: state.setAttribute(PermissionsAction.STATE_REALM_ID, targetRef);
135:
136: // use the roles from this ref's AuthzGroup
137: state.setAttribute(PermissionsAction.STATE_REALM_ROLES_ID,
138: rolesRef);
139:
140: // ... with this description
141: state.setAttribute(PermissionsAction.STATE_DESCRIPTION,
142: description);
143:
144: // ... showing only locks that are prpefixed with this
145: state.setAttribute(PermissionsAction.STATE_PREFIX, prefix);
146:
147: // start the helper
148: state.setAttribute(PermissionsAction.STATE_MODE,
149: PermissionsAction.MODE_MAIN);
150: }
151: }
|