/* (non-Javadoc) * @see org.sakaiproject.cheftool.VelocityPortletPaneledAction#toolModeDispatch(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ protected void toolModeDispatch( String methodBase, String methodExt, HttpServletRequest req, HttpServletResponse res) throws ToolException { ToolSession toolSession = SessionManager.getCurrentToolSession(); SessionState state = getState(req); if (MODE_DONE.equals(toolSession.getAttribute(LINK_MODE))) { Tool tool = ToolManager.getCurrentTool(); String url = (String) SessionManager.getCurrentToolSession() .getAttribute(tool.getId() + Tool.HELPER_DONE_URL); SessionManager.getCurrentToolSession().removeAttribute(tool.getId() + Tool.HELPER_DONE_URL); SessionManager.getCurrentToolSession().removeAttribute(LINK_MODE); try { res.sendRedirect(url); } catch (IOException e) { logger.warn("IOException: ", e); } return; } else if (sendToHelper(req, res, req.getPathInfo())) { return; } else { super.toolModeDispatch(methodBase, methodExt, req, res); } }
protected void toolModeDispatch( String methodBase, String methodExt, HttpServletRequest req, HttpServletResponse res) throws ToolException { SessionState sstate = getState(req); ToolSession toolSession = SessionManager.getCurrentToolSession(); String mode = (String) sstate.getAttribute(STATE_MODE); Object started = toolSession.getAttribute(STARTED); if (mode == null && started != null) { toolSession.removeAttribute(STARTED); Tool tool = ToolManager.getCurrentTool(); String url = (String) SessionManager.getCurrentToolSession() .getAttribute(tool.getId() + Tool.HELPER_DONE_URL); SessionManager.getCurrentToolSession().removeAttribute(tool.getId() + Tool.HELPER_DONE_URL); try { res.sendRedirect(url); } catch (IOException e) { Log.warn("chef", this + " : ", e); } return; } super.toolModeDispatch(methodBase, methodExt, req, res); }
/** override init so we can lookup our dependencies */ protected void initState(SessionState state, HttpServletRequest req, HttpServletResponse res) { super.initState(state, req, res); // SAK-28087 configurable value for max job time. A large term at a large institution may take // 24 hours maxJobTime = Long.valueOf( serverConfigurationService.getInt("archive.max.job.time", MAX_JOB_TIME_DEFAULT)); state.setAttribute(STATE_MODE, SINGLE_MODE); }
/** Remove the state variables used internally, on the way out. */ private static void cleanupState(SessionState state) { state.removeAttribute(STATE_REALM_ID); state.removeAttribute(STATE_REALM_ROLES_ID); state.removeAttribute(STATE_REALM_EDIT); state.removeAttribute(STATE_VIEW_REALM_EDIT); state.removeAttribute(STATE_PREFIX); state.removeAttribute(STATE_ABILITIES); state.removeAttribute(STATE_DESCRIPTION); state.removeAttribute(STATE_ROLES); state.removeAttribute(STATE_ROLE_ABILITIES); state.removeAttribute(STATE_PERMISSION_DESCRIPTIONS); state.removeAttribute(STATE_MODE); state.removeAttribute(VelocityPortletPaneledAction.STATE_HELPER); state.removeAttribute(STATE_GROUP_AWARE); // re-enable observers VelocityPortletPaneledAction.enableObservers(state); }
/** * build the context. * * @return The name of the template to use. */ public static String buildHelperContext( VelocityPortlet portlet, Context context, RunData rundata, SessionState state) { // in state is the realm id context.put("thelp", rb); String realmId = (String) state.getAttribute(STATE_REALM_ID); // in state is the realm to use for roles - if not, use realmId String realmRolesId = (String) state.getAttribute(STATE_REALM_ROLES_ID); context.put("viewRealmId", realmRolesId); // get the realm locked for editing AuthzGroup edit = (AuthzGroup) state.getAttribute(STATE_REALM_EDIT); if (edit == null) { if (AuthzGroupService.allowUpdate(realmId)) { try { edit = AuthzGroupService.getAuthzGroup(realmId); state.setAttribute(STATE_REALM_EDIT, edit); } catch (GroupNotDefinedException e) { try { // we can create the realm edit = AuthzGroupService.addAuthzGroup(realmId); state.setAttribute(STATE_REALM_EDIT, edit); } catch (GroupIdInvalidException ee) { M_log.warn("PermissionsAction.buildHelperContext: addRealm: " + ee); cleanupState(state); return null; } catch (GroupAlreadyDefinedException ee) { M_log.warn("PermissionsAction.buildHelperContext: addRealm: " + ee); cleanupState(state); return null; } catch (AuthzPermissionException ee) { M_log.warn("PermissionsAction.buildHelperContext: addRealm: " + ee); cleanupState(state); return null; } } } // no permission else { M_log.warn("PermissionsAction.buildHelperContext: no permission: " + realmId); cleanupState(state); return null; } } AuthzGroup viewEdit = null; // check wither the current realm id is of site group type if (realmId.indexOf(SiteService.REFERENCE_ROOT) != -1) { String siteId = realmId.replaceAll(SiteService.REFERENCE_ROOT + "/", ""); context.put("siteRef", realmId); if (state.getAttribute(STATE_GROUP_AWARE) != null && ((Boolean) state.getAttribute(STATE_GROUP_AWARE)).booleanValue()) { // only show groups for group-aware tools try { Site site = SiteService.getSite(siteId); Collection groups = site.getGroups(); if (groups != null && !groups.isEmpty()) { Iterator iGroups = groups.iterator(); for (; iGroups.hasNext(); ) { Group group = (Group) iGroups.next(); // need to either have realm update permission on the group level or better at the // site level if (!AuthzGroupService.allowUpdate(group.getReference())) { iGroups.remove(); } } context.put("groups", groups); } } catch (Exception siteException) { M_log.warn( "PermissionsAction.buildHelperContext: getsite of realm id = " + realmId + siteException); } } // get the realm locked for editing viewEdit = (AuthzGroup) state.getAttribute(STATE_VIEW_REALM_EDIT); if (viewEdit == null) { if (AuthzGroupService.allowUpdate(realmRolesId) || AuthzGroupService.allowUpdate(SiteService.siteReference(siteId))) { try { viewEdit = AuthzGroupService.getAuthzGroup(realmRolesId); state.setAttribute(STATE_VIEW_REALM_EDIT, viewEdit); } catch (GroupNotDefinedException e) { M_log.warn( "PermissionsAction.buildHelperContext: getRealm with id= " + realmRolesId + " : " + e); cleanupState(state); return null; } } // no permission else { M_log.warn("PermissionsAction.buildHelperContext: no permission: " + realmId); cleanupState(state); return null; } } } // in state is the prefix for abilities to present String prefix = (String) state.getAttribute(STATE_PREFIX); // in state is the list of abilities we will present List functions = (List) state.getAttribute(STATE_ABILITIES); if (functions == null) { // get all functions prefixed with our prefix functions = FunctionManager.getRegisteredFunctions(prefix); } if (functions != null && !functions.isEmpty()) { List<String> nFunctions = new Vector<String>(); if (!realmRolesId.equals(realmId)) { // editing groups within site, need to filter out those permissions only applicable to site // level for (Iterator iFunctions = functions.iterator(); iFunctions.hasNext(); ) { String function = (String) iFunctions.next(); if (function.indexOf("all.groups") == -1) { nFunctions.add(function); } } } else { nFunctions.addAll(functions); } state.setAttribute(STATE_ABILITIES, nFunctions); context.put("abilities", nFunctions); // get function description from passed in HashMap // output permission descriptions Map<String, String> functionDescriptions = (Map<String, String>) state.getAttribute(STATE_PERMISSION_DESCRIPTIONS); if (functionDescriptions != null) { Set keySet = functionDescriptions.keySet(); for (Object function : functions) { String desc = (String) function; String descKey = PermissionsHelper.PREFIX_PERMISSION_DESCRIPTION + function; if (keySet.contains(descKey)) { // use function description desc = (String) functionDescriptions.get(descKey); } functionDescriptions.put((String) function, desc); } context.put("functionDescriptions", functionDescriptions); } } // in state is the description of the edit String description = (String) state.getAttribute(STATE_DESCRIPTION); // the list of roles List roles = (List) state.getAttribute(STATE_ROLES); if (roles == null) { // get the roles from the edit, unless another is specified AuthzGroup roleRealm = viewEdit != null ? viewEdit : edit; if (realmRolesId != null) { try { roleRealm = AuthzGroupService.getAuthzGroup(realmRolesId); } catch (Exception e) { M_log.warn( "PermissionsHelperAction.buildHelperContext: getRolesRealm: " + realmRolesId + " : " + e); } } roles = new Vector(); roles.addAll(roleRealm.getRoles()); Collections.sort(roles); state.setAttribute(STATE_ROLES, roles); } // the abilities not including this realm for each role Map rolesAbilities = (Map) state.getAttribute(STATE_ROLE_ABILITIES); if (rolesAbilities == null) { rolesAbilities = new Hashtable(); state.setAttribute(STATE_ROLE_ABILITIES, rolesAbilities); // get this resource's role Realms,those that refine the role definitions, but not it's own Reference ref = EntityManager.newReference(viewEdit != null ? viewEdit.getId() : edit.getId()); Collection realms = ref.getAuthzGroups(); realms.remove(ref.getReference()); for (Iterator iRoles = roles.iterator(); iRoles.hasNext(); ) { Role role = (Role) iRoles.next(); Set locks = AuthzGroupService.getAllowedFunctions(role.getId(), realms); rolesAbilities.put(role.getId(), locks); } } context.put("realm", viewEdit != null ? viewEdit : edit); context.put("prefix", prefix); context.put("description", description); if (roles.size() > 0) { context.put("roles", roles); } context.put("rolesAbilities", rolesAbilities); // make sure observers are disabled VelocityPortletPaneledAction.disableObservers(state); return TEMPLATE_MAIN; }
/** Populate the state with configuration settings */ protected void initState(SessionState state, VelocityPortlet portlet, JetspeedRunData rundata) { // TODO: we might want to keep this from running for each request - but by letting it we get // fresh info each time... -ggolden super.initState(state, portlet, rundata); Placement placement = ToolManager.getCurrentPlacement(); Properties config = placement.getConfig(); // set the pass_pid parameter boolean passPid = false; String passPidStr = config.getProperty(PASS_PID, "false"); state.removeAttribute(PASS_PID); if ("true".equalsIgnoreCase(passPidStr)) { state.setAttribute(PASS_PID, Boolean.TRUE); passPid = true; } // Assume macro expansion (disable on request) boolean macroExpansion = true; String macroExpansionStr = config.getProperty(MACRO_EXPANSION, "true"); state.removeAttribute(MACRO_EXPANSION); if ("false".equalsIgnoreCase(macroExpansionStr)) { state.setAttribute(MACRO_EXPANSION, Boolean.FALSE); macroExpansion = false; } // set the special setting String special = config.getProperty(SPECIAL); final String sakaiPropertiesUrlKey = config.getProperty(SAKAI_PROPERTIES_URL_KEY); final String hideOptions = config.getProperty(HIDE_OPTIONS); // check for an older way the ChefWebPagePortlet took parameters, converting to our "special" // values if (special == null) { if ("true".equals(config.getProperty("site"))) { special = SPECIAL_SITE; } else if ("true".equals(config.getProperty("workspace"))) { special = SPECIAL_WORKSPACE; } else if ("true".equals(config.getProperty("worksite"))) { special = SPECIAL_WORKSITE; } else if ("true".equals(config.getProperty("annotatedurl"))) { special = SPECIAL_ANNOTATEDURL; } } state.removeAttribute(SPECIAL); if ((special != null) && (special.trim().length() > 0)) { state.setAttribute(SPECIAL, special); } state.removeAttribute(HIDE_OPTIONS); if ((hideOptions != null) && (hideOptions.trim().length() > 0)) { state.setAttribute(HIDE_OPTIONS, hideOptions); } // set the source url setting String source = StringUtils.trimToNull(config.getProperty(SOURCE)); // check for an older way the ChefWebPagePortlet took parameters, converting to our "source" // value if (source == null) { source = StringUtils.trimToNull(config.getProperty("url")); } // store the raw as-configured source url state.removeAttribute(SOURCE); if (source != null) { state.setAttribute(SOURCE, source); } // compute working URL, modified from the configuration URL if special String url = sourceUrl( special, source, placement.getContext(), macroExpansion, passPid, placement.getId(), sakaiPropertiesUrlKey); state.setAttribute(URL, url); // set the height state.setAttribute(HEIGHT, config.getProperty(HEIGHT, "600px")); state.setAttribute(ANNOTATED_TEXT, config.getProperty(ANNOTATED_TEXT, "")); if (config.getProperty(TARGETPAGE_URL) != null) { // set Target page url for Annotated URL Tool state.setAttribute(TARGETPAGE_URL, config.getProperty(TARGETPAGE_URL)); // set Target page name for Annotated URL Tool state.setAttribute(TARGETPAGE_NAME, config.getProperty(TARGETPAGE_NAME)); } // set the title state.setAttribute(TITLE, placement.getTitle()); if (state.getAttribute(STATE_PAGE_TITLE) == null) { SitePage p = SiteService.findPage(getCurrentSitePageId()); state.setAttribute(STATE_PAGE_TITLE, p.getTitle()); } // if events found in tool registration file put them in state if ((StringUtils.trimToNull(config.getProperty(EVENT_ACCESS_WEB_CONTENT)) != null)) { state.setAttribute(EVENT_ACCESS_WEB_CONTENT, config.getProperty(EVENT_ACCESS_WEB_CONTENT)); } if ((StringUtils.trimToNull(config.getProperty(EVENT_REVISE_WEB_CONTENT)) != null)) { state.setAttribute(EVENT_REVISE_WEB_CONTENT, config.getProperty(EVENT_REVISE_WEB_CONTENT)); } if (m_eventTrackingService == null) { m_eventTrackingService = (EventTrackingService) ComponentManager.get("org.sakaiproject.event.api.EventTrackingService"); } }